what is the problem with these variables?

Discussion in 'Mac Programming' started by saleh.hi.62, Nov 3, 2011.

  1. saleh.hi.62 macrumors member

    Jul 25, 2011
    what is the problem with these variables?

    Attached Files:

  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    The first two errors are because you can't initialize variables in an @interface.

    The third error is because you wrote this:
    @property NSMutableArray WebsiteQueue, WebpageQueue;
    You're missing the * that means "pointer".

    If I had to guess, I'd say you need to review the fundamentals more carefully.

    As a rule, it's better to post code as text, so we can read it, copy and paste it, or even try compiling it (if it's complete enough). Pictures of code are inferior to the actual text of the code.
  3. saleh.hi.62 thread starter macrumors member

    Jul 25, 2011
    thank you so much for your help. i appreciate that.

    when where is the best place to initialize variables? do i have to define a new init function ?
  4. gnasher729 macrumors P6


    Nov 25, 2005
    Maybe you should take a basic programming course. Or take a good introductory book, which you will find by going through old threads, without having to ask unnecessary questions. Actually _learning_ the things is much more efficient than blindly stumbling through them without understanding anything.

    Your question can't be answered until you actually know what you are asking. Google for "lifetime of a variable" and read until you understand it. If you understand it, then you have a chance of asking a meaningful question and benefitting from the answer.
  5. Kenndac macrumors 6502


    Jun 28, 2003
    …except in *many* other languages you can instantiate your instance variables at the same time as declaring them. Your rant seems a little bit OTT.

    In answer to the original question, yes, the best place to instantiate variables that need to live as long as the container class is in a custom init method. Make sure to release them in your class' dealloc method if you're not running under ARC or garbage collection.
  6. gnasher729 macrumors P6


    Nov 25, 2005
    Hardly over the top, when you are yourself confusing instance variables (lifetime = lifetime of an object) with class variables (lifetime = lifetime of the class, which don't exist per se in Objective-C, but are easily simulated with static variables), and you wouldn't initialize class variables in an init method.
  7. saleh.hi.62, Nov 4, 2011
    Last edited: Nov 4, 2011

    saleh.hi.62 thread starter macrumors member

    Jul 25, 2011
  8. Catfish_Man macrumors 68030


    Sep 13, 2001
    Portland, OR
    Bah, somehow didn't notice this was a very stale tab. Sorry!
  9. cocell macrumors newbie

    Nov 4, 2011
    Los Angeles,CA
    You can't alloc or init in .h

    I would read more about Objective-C, A good book I like is "iPhone Application Development for iOS 4" by Duncan Campbell

    Your code should look somewhat like this.
    @interface sch: NSObject {
    NSMutableArray *_websiteQueue;
    NSMutableArray *_webpageQueue;
    [B]Your sch.m[/B]
    //Now you can alloc and init your instance
    _websiteQueue = [[NSMutableArray alloc] initWithCapacity:2];
    _webpageQueue = [[NSMutableArray alloc] initWithCapacity:2];
    //Now you can add,remove,replace objects etc from your array sense it's Mutable. 

Share This Page