release' is unavailable和semantic issue

1. 首次使用NSString *greeting = [[NSString alloc] initWithFormat:@"test..."];

如上代码所申请的空间,用完后,想调用[greeting release];释放,但编译时,会报错release' is unavailable...错误

解决:

You need to turn off Automatic Reference Counting. You do this by clicking on your project in the navigator (the top item in the finder-like thing on the left), then click on your target, select "Build Settings" and turn off the option "Objective-C Automatic Reference Counting" (you can use the search field on the upper right to search it).

2. 但 关掉ARC,原本@synthesize userName = _userName;又出现了semantic issue错误,原来ARC下需要用strong,而不能用weak。

修改定义@property (strong, nonatomic) IBOutlet UITextField *userName;

你可能感兴趣的:(iOS开发)