废话少说,直接正题。
今天使用VMware安装OS X 7.0、Xcode 4.2.1开始第一个Objective-C的程序,也就是HelloWorld。以下是从网上copy的代码
1 #import<Foundation/Foundation.h>
2 int main (int argc, constchar * argv[])
3 {
4 NSAutoreleasePool * pool = [[NSAutoreleasePoolalloc] init];
5 NSLog(@"Hello,iphone!");
6 [pool drain];
7 return 0;
8 }
但把代码敲进去的时候,编译是失败的,查阅资料得知:
Xcode4.2之后就不使用NSAutoreleasePool这种东西了,改用了@autoreleasepool{...}这种玩意.
查阅的源地址
原文copy如下:
Whenever a new Xcode release and iOs version comes out, there is a lot of new adjustments to make. Apple make a lot of change that are a real pain at the start, but generally make sense after a while.
With Xcode 5, apple have added ARC (automatic reference counting) when you compile the application. This breaks a lot of the old way of doing things, such as release, autorelease, and using NSAutoreleasePool.
So if we have code such as this:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
…..
[pool release];
We will get an error. But all we need to do is change the format of the code to this:
@autoreleasepool {
….
}
Or you can switch of ARC by setting CLANG_ENABLE_OBJC_ARC to NO in the
Build Settings of your app.
You can read more about ARC herehttps://developer.apple.com/library/ios/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html
至此搞定第一个程序,改天再接再厉。
一些可预见的计划:
1. 学习Objective-C基础语法
2. 学习iOS开发基础
原文:http://www.cnblogs.com/insIs0n/p/3541981.html