Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

saleh.hi.62

macrumors member
Original poster
Jul 25, 2011
95
0
what is the problem with these variables?
 

Attachments

  • Screen shot 2011-11-03 at 10.32.16 PM.png
    Screen shot 2011-11-03 at 10.32.16 PM.png
    43.1 KB · Views: 201
The first two errors are because you can't initialize variables in an @interface.

The third error is because you wrote this:
Code:
@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.
 
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 ?
 
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 ?

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.
 
Ranting…

…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.
 
…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.

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.
 
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.
Code:
sch.h

@interface sch: NSObject {
NSMutableArray *_websiteQueue;
NSMutableArray *_webpageQueue;
}

@end

[B]Your sch.m[/B]

@implemetation

-(void)whateverMethod{
//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. 

}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.