我对编程非常陌生,目前正试图通过 Ray Wenderlich 初学者教程取得进展,但我已经陷入了第一个障碍!看来,要么我的程序设置错误,要么教程已经过时,因为当我开始程序时我们有不同的代码,当我尝试运行他生成的代码时出现了错误。
他的代码
// // main.m // Are You A WIZARD? //
#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
//These are the different variables that will be evaluated to generate responses.
float strength, intelligence, speed, alchemy_skill, sum, avg;
//I included (1-10) so that users would know how to answer.
NSLog(@"What is your strength (1-10)?");
NSLog(@"What is your intelligence (1-10)?");
NSLog(@"What is your speed (1-10)?");
NSLog(@"What is your alchemy skill level (1-10)?");
[pool drain];
return 0; }
我的代码
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//These are the different variables that will be evaluated to generate responses:
float strength, intelligence, speed, alchemy_skill, sum, avg;
//I included (1-10) so that users would know how to answer.
NSLog(@"What is your strength (1-10)?");
NSLog(@"What is your intelligence (1-10)?");
NSLog(@"What is your speed (1-10)?");
NSLog(@"What is your alchemy skill level (1-10)?");
}
return 0; }
当我运行他的代码时,它会出现诸如“NSAutoreleasePool 在自动引用计数模式下不可用”之类的错误,而当我运行我的代码时,它会说我有“未使用的变量”。
谢谢你的帮助!我确信我马上犯了一个愚蠢的错误,但我将不胜感激!