我的代码中出现了未声明的标识符问题。已注释编译器消息。
的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;
}
答案 0 :(得分:2)
你的问题是等号..
[stock **=** setObject:@"GOOG" // use of undeclared identifier 'setObject'
forKey:@"symbol"];
[stock **=** setObject:[NSNumber numberWithInt:160] // use of undeclared identifier 'setObject'
forKey:@"shares"];
您的代码应该是..
[stock setObject:@"GOOG" // use of undeclared identifier 'setObject'
forKey:@"symbol"];
[stock setObject:[NSNumber numberWithInt:160] // use of undeclared identifier 'setObject'
forKey:@"shares"];
答案 1 :(得分:1)
你不做
[stock = setObject....
你直接做
[stock setObject....
这些方法不返回任何类型的值,它们是void方法(谈论-setObject方法)
答案 2 :(得分:0)
你有[stock = setObject而不仅仅是[stock setObject:失去了等于。