开发者

Need to use an array in another class.. error is arrayXYZ undeclared!

i have a class abcParser in which i have an array arrayXYZ. Now i need to use this array in a vie开发者_JAVA技巧wController.. when i do so it gives an error.. arrayXYZ undeclared

i m weak in inheritance, please help! thanks!!


Declare a function in ABCParser that lets you retrieve the array, like so:

-(NSArray *)arrayXYZ:(NSString *)anArgument{
    NSArray *array = [NSArray arrayWithObject:anArgument];

    return array;
}

EDIT:

Alright, seems like we need a little lesson on instantiation etc...

Now, those Plus (+) and Minus (-) signs beside method names...

Plus is a class method. It can be used without instantiation, but understand that variables cannot be carried over when you use these.

Instance methods require you to instantiate a new object, then ask it to perform methods.

ABCParser *parser = [[ABCParser alloc] init];

That creates a new 'instance' of ABCParser and makes a pointer to it with the name 'parser'. That's all fine and dandy.

When we want this new parser object to do something, we tell it as normal:

NSArray *myNewArray = [parser arrayXYZ];

So - When you have an instance of your class, do this:

ABCParser *parser = [[ABCParser alloc] init];

[parser generateArrayXYZ];
NSArray *array = [parser getArrayXYZ];

This will give you an object that you can work with. It'll take a bit of getting used to, but you'll learn. If you need any further explanation, just post :)


Did you already add @property and @syntesize to your NSArray variable in abcParser?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜