Reputation: 3917
Am getting an undeclared identifier problem in my code. Have commented the compiler messages.
Main.m
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
NSMutableArray *stocks = [[NSMutableArray alloc]init];
NSMutableDictionary *stock;
stock = [NSMutableDictionary dictionary];
[stock setObject:@"AAPL"
forKey:@"symbol"];
[stock setObject:[NSNumber numberWithInt:200]
forKey:@"shares"];
[stocks addObject:stock];
stock = [NSMutableDictionary dictionary];
[stock = setObject:@"GOOG" // use of undeclared identifier 'setObject'
forKey:@"symbol"];
[stock = setObject:[NSNumber numberWithInt:160] // use of undeclared identifier 'setObject'
forKey:@"shares"];
[stocks addObject:stock];
[stocks writeToFile:@"/tmp/stocks/plist"
atomically:YES];
}
return 0;
}
Upvotes: 0
Views: 1652
Reputation: 16937
You've got [stock = setObject instead of just [stock setObject: Lose the equals.
Upvotes: 0
Reputation: 2279
Your problem is the equals sign..
[stock **=** setObject:@"GOOG" // use of undeclared identifier 'setObject'
forKey:@"symbol"];
[stock **=** setObject:[NSNumber numberWithInt:160] // use of undeclared identifier 'setObject'
forKey:@"shares"];
Your code should be..
[stock setObject:@"GOOG" // use of undeclared identifier 'setObject'
forKey:@"symbol"];
[stock setObject:[NSNumber numberWithInt:160] // use of undeclared identifier 'setObject'
forKey:@"shares"];
Upvotes: 2
Reputation: 2578
You do not do
[stock = setObject....
you directly do
[stock setObject....
These methods do not return any sort of value, they are void methods (talking about the -setObject method)
Upvotes: 1