error during variable setting

Discussion in 'Mac Programming' started by arfius, Oct 31, 2012.

  1. macrumors newbie

    Joined:
    Oct 31, 2012
    #1
    Hi @ all,
    I have a problem in my class,
    In my class.m, I declared some NNString variable, all in same way.
    I "@"synthesized these, but someones thrown exceptions, others not.
    this is the myclass header code
    Code:
    @interface Paziente : NSObject
    {
        NSString * name;
        NSString * birth;
        NSString * ID;
        NSString * sex;
        NSString * mTeGr;
        NSString * vTeGr;
        NSString * mCrGr;
        NSString * vCrGr;
       NSString * mCdGr;
        NSString * vCdGr;
        NSString * mTeM;
        NSString * vTeM;
        NSString * mCrM;
        NSString * vCrM;
        NSString * mCdM;
        NSString * vCdM;
    }
    @property (nonatomic,retain)NSString * name;
    @property (nonatomic,retain)NSString * birth;
    @property (nonatomic,retain)NSString * ID;
    @property (nonatomic,retain)NSString * sex;
    @property (nonatomic,retain)NSString * mTeGr;
    @property (nonatomic,retain)NSString * vTeGr;
    @property (nonatomic,retain)NSString * mCrGr;
    @property (nonatomic,retain)NSString * vCrGr;
    @property (nonatomic,retain)NSString * mCdGr;
    @property (nonatomic,retain)NSString * vCdGr;
    @property (nonatomic,retain)NSString * mTeM;
    @property (nonatomic,retain)NSString * vTeM;
    @property (nonatomic,retain)NSString * mCrM;
    @property (nonatomic,retain)NSString * vCrM;
    @property (nonatomic,retain)NSString * mCdM;
    @property (nonatomic,retain)NSString * vCdM;
    @end
    whereas the .m code is
    Code:
    #import "Paziente.h"
    @implementation Paziente
    @synthesize  mCdGr;
    @synthesize  vCdGr;
    @synthesize  mTeM;
    @synthesize  vTeM;
    @synthesize  mCrM;
    @synthesize  vCrM;
    @synthesize  mCdM;
    @synthesize  vCdM;
    @synthesize  name;
    @synthesize  birth;
    @synthesize  ID;
    @synthesize  sex;
    @synthesize  mTeGr;
    @synthesize  vTeGr;
    @synthesize  mCrGr;
    @synthesize  vCrGr;
    @end
    
    
    for example, if I set the variable "birth" p.birth=@"", it works; otherwise if I set the variable p.mTeM it doesn't work, I tried to use the method [p setMTeM:mad:""], but it is the same. This is the generated error.
    can someone can help me :) ?
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    From your error it looks like you were sending the message to the class, Paziente, and not the instance, p. I tested your code exactly and the . notation and setter for the member you were having problems with worked fine for me.

    As an aside, post ALL the code. Post a small main.m that has the calls you make where you see a problem, so we can run it ourselves (or just see it). We'd probably be able to call out the problem immediately if you had done so.

    -Lee
     
  3. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #3
    Just some recommendations:

    Don't write "NSString * variable". It looks like a multiplication.
    Use "NSString* variable" instead.

    Start all instance variables with an underscore. That way when you read the code you know exactly where instance variables are used, and where properties are used.
     
  4. thread starter macrumors newbie

    Joined:
    Oct 31, 2012
    #4
    Very strange!
    The debugger shows some variables of Paziente class.
    Like the instance of class is partially allocated.
    mmm
     
  5. thread starter macrumors newbie

    Joined:
    Oct 31, 2012
    #5
    I created a new class,
    I pasted the same code of the Paziente class.
    Now, it works fine.
     
  6. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #6
    There are class members. What you declared are instance members. You have to access them on an instance of the class instead of on the class itself. I'm guessing it worked the second time because you changed the code accessing it and used an object instead of the new class name. If you post all of your code before and after we can tell you for sure and you can learn by identifying the error. Copying to a new file and declaring success when the real change was tangential is the sort of superstition that's best to avoid.

    -Lee
     

Share This Page