Reputation: 23
I've been trying for days to access an alphabet array from another class, yet I can't figure it out! I know there are several posts similar to this one, but none of them were any help. Here is the interface and implementation portions of the Alphabet class containing the array.
@interface Alphabet : NSObject {
NSArray *abet;
}
@property (nonatomic, retain) NSArray *abet;
@end
@implementation Alphabet
@synthesize abet;
- (id) init {
if ((self = [super init])) {
abet = [[NSArray alloc]
initWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q", @"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z", nil];
}
return self;
}
@end
Here is the code in the class that I want to access the array
@interface NewView () {
Alphabet* ab;
}
- (void)viewDidLoad
{
[super viewDidLoad];
ab = [[Alphabet alloc] init];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[[Alphabet.abet] objectAtIndex:p];
What am I missing?
Upvotes: 0
Views: 307
Reputation: 108169
[[Alphabet.abet] objectAtIndex:p];
makes no sense.
It should be
[ab.abet objectAtIndex:p];
or just
ab.abet[p];
(whatever p
is...)
Upvotes: 2