Results 1 to 3 of 3
  1. #1

    Member Since
    Mar 11, 2009
    Trouble with Objective-c class
    I'm an experienced programmer, but a newbie with Objective-C. I am using a sample I found on the internet as a model. All I tried to do, was add a new class to the project - that is, I'm not trying to use it yet, I'm just trying to get the program to compile. When I do, I get several error messages: in the .m file, after the initWithName I get "syntax error before NSString" and then after ever line except "name = nameValue" I get "type defaults to an int" and "addressValue undeclared here" and "data definition has no type or storage class." The strange thing is if I drop the last parameter (zip) it compiles ok. I've tried adding another parameter, but then it doesn't compile again. I also tried changing names around in case I was using reserved words or something (although the compiler should pick that up...)

    Like I say, I'm just starting out. HELP! All I'm trying to do is make a class that uses "initialize with arguments" just to try it out.

    By the way this editor insists on replacing a colon followed by a left parens with a smiley face. I can't figure out how to tell it not to.

    Here's the code: here's Door.h

    #import <Foundation/Foundation.h>

    @interface Door : NSObject {
    ****NSString *name;
    ****NSString *dooraddress;
    ****NSString *city;
    ****NSString *state;
    ****NSString *zip;

    @property (nonatomic, retain) NSString *name;
    @property (nonatomic, retain) NSString *dooraddress;
    @property (nonatomic, retain) NSString *city;
    @property (nonatomic, retain) NSString *state;
    @property (nonatomic, retain) NSString *zip;

    -(id)initWithNameNSString *)nameValue
    *******andAddressNSString *)addressValue
    **********andCityNSString *)cityValue
    ******** andStateNSString *)stateValue
    ***********andZipNSString *)zipValue;


    and here's door.m

    #import "Door.h"

    @implementation Door
    @synthesize name;
    @synthesize dooraddress;
    @synthesize city;
    @synthesize state;
    @synthesize zip;

    -(id)initWithNameNSString *)nameValue
    *******andAddressNSString *)addressValue
    **********andCityNSString *)cityValue
    ******** andStateNSString *)stateValue
    ***********andZipNSSTring *)zipValue {
    ****name = nameValue;
    ****dooraddress = addressValue;
    ****city = cityValue;
    ****state = stateValue;
    ****zip = zipValue;

    ****return self;


  2. #2

    Member Since
    Mar 15, 2007
    17" MacBook Pro, 2.33GHz C2D, 2GB RAM
    For your zipValue parameter you have typed in NSSTring rather than NSString. That typo might be your problem.

    As far as showing code in a forum post, look into surrounding your code blocks with the CODE tag (surrounded by square brackets, and also available via the '#' button in the advanced post editor's toolbar), which will give you results like this:

    - (id) initWithName:(NSString *)nameValue
             andAddress:(NSString *)addressValue
                andCity:(NSString *)cityValue
               andState:(NSString *)stateValue
                 andZip:(NSString *)zipValue;

  3. #3

    Member Since
    Mar 11, 2009
    That was it. I found out last night by re-typing part of the files, and the error went away. Thanks for the tip about posting code too....

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Objective-C help
    By bikka in forum OS X - Development and Darwin
    Replies: 22
    Last Post: 05-27-2014, 03:56 PM
  2. Need help in objective C
    By prateek.chaubey in forum iOS Development
    Replies: 3
    Last Post: 09-23-2011, 10:12 PM
  3. Objective-C
    By eddielee in forum OS X - Development and Darwin
    Replies: 2
    Last Post: 02-02-2011, 01:27 PM
  4. Is Objective For me?
    By Estanislao in forum OS X - Apps and Games
    Replies: 1
    Last Post: 05-26-2009, 05:13 AM
  5. Objective-C
    By AstralZenith in forum OS X - Development and Darwin
    Replies: 13
    Last Post: 03-09-2003, 11:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts