/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BASEVERNUM.$REV" "${INFOPLIST_FILE}"
1: 為工程運行時加入 NSZombieEnabled 環境變量,并設為啟用,則在 EXC_BAD_ACCESS 發生時,XCode 的 Console 會打印出問題描述。
首先雙擊 XCode 工程中,Executables 下的 可執行模組,
在彈出窗口中,Variables to be set in the environment,添加 NSZombieEnabled,并設定為 YES,點擊選中復選框啟用此變量。
這樣,運行 Objective-C 時會看到控制臺輸出錯誤信息
這條消息對于定位問題有很好的提示作用。但是很多時候,只有這條提示是不夠的,我們需要更多的提示來幫助定位問題,這時候再加入 MallocStackLogging 來啟用malloc記錄。
當錯誤發生后,在終端執行:
malloc_history ${App_PID} ${Object_instance_addr}
則會獲得相應的 malloc 歷史記錄,比如對于上一個控制臺輸出
Untitled[3646:a0f] *** -[CFString release]: message sent to deallocated instance 0x10010d340
則我們可以在終端執行,結果如下:
Buick-Wongs-MacBook-Pro:Downloads buick$ malloc_history 3646 0x10010d340
malloc_history Report Version: 2.0
Process: Untitled [3646]
Path: /Users/buick/Desktop/Untitled/build/Debug/Untitled
Load Address: 0×100000000
Identifier: Untitled
Version: ??? (???)
Code Type: X86-64 (Native)
Parent Process: gdb-i386-apple-darwin [3638]
Date/Time: 2011-02-01 15:07:04.181 +0800
OS Version: Mac OS X 10.6.6 (10J567)
Report Version: 6
ALLOC 0x10010d340-0x10010d357 [size=24]: thread_7fff70118ca0 |start | main | objc_msgSend | lookUpMethod | prepareForMethodLookup | _class_initialize | +[NSString initialize] | objc_msgSend | lookUpMethod | prepareForMethodLookup | _class_initialize | NXCreateMapTableFromZone | malloc_zone_malloc
—-
FREE 0x10010d340-0x10010d357 [size=24]: thread_7fff70118ca0 |start | main | objc_msgSend | lookUpMethod | prepareForMethodLookup | _class_initialize | _finishInitializing | free
ALLOC 0x10010d340-0x10010d357 [size=24]: thread_7fff70118ca0 |start | main | -[NSPlaceholderString initWithString:] | objc_msgSend | lookUpMethod | prepareForMethodLookup | _class_initialize | _class_initialize | +[NSMutableString initialize] | objc_msgSend | lookUpMethod | prepareForMethodLookup | _class_initialize | NXCreateMapTableFromZone | malloc_zone_malloc
—-
FREE 0x10010d340-0x10010d357 [size=24]: thread_7fff70118ca0 |start | main | -[NSPlaceholderString initWithString:] | objc_msgSend | lookUpMethod | prepareForMethodLookup | _class_initialize | _class_initialize | _finishInitializing | free
ALLOC 0x10010d340-0x10010d35f [size=32]: thread_7fff70118ca0 |start | main | -[NSCFString substringWithRange:] | CFStringCreateWithSubstring | __CFStringCreateImmutableFunnel3 | _CFRuntimeCreateInstance | malloc_zone_malloc
這樣就可以很快的定位出問題的代碼片段了,注意輸出的最后一行,,,這行雖然不是問題的最終原因,但是離問題點已經很近了,隨著它找下去,八成就會找到問題。
2 NSLog(@"tempString retainCount-----%D",[tempString retainCount]);
3 NSLog(@"tempString -----%p---%p",tempString,&tempString);
4
5 NSMutableString*string1=[tempString retain];
6 NSLog(@"string1 retainCount-----%D",[string1 retainCount]);
7 NSLog(@"string1 -----%p---%p",string1,&string1);
8
9 NSMutableString*string2=[tempString mutableCopy];
10 NSLog(@"string2 retainCount-----%D",[string2 retainCount]);
11 NSLog(@"string2 -----%p---%p",string2,&string2);
12
13
14 NSString*s=[[NSString alloc]initWithFormat:@"%@",@"hello"];
15 NSLog(@"s retainCount-----%D",[s retainCount]);
16 NSLog(@"s -----%p---%p",s,&s);
17 NSString*st=[s copy];
18 NSLog(@"st retainCount-----%D",[st retainCount]);
19 NSLog(@"st -----%p---%p",st,&st);
20 NSString*str=[s retain];
21 NSLog(@"str retainCount-----%D",[str retainCount]);
22 NSLog(@"str -----%p---%p",str,&str);
當retain 時是表示指向了同一個內存空間,只是內存空間的retainCount加了1,其他的都沒變,但是當copy時,如果那個內存單元里面的值是不可變的時候,我們跟retain是一樣的,只是內存空間的retainCount加了1!如果那個內存單元里面的值是可變的時候,其實在在內存中另外給分配了一塊內存空間,然后把值賦給內存空間里面。原來那個內存空間的retainCount不加1,現在新分配的內存空間retainCount加1.
#ifndef __OPTIMIZE__
# define NSLog(...) NSLog(__VA_ARGS__)
#else
# define NSLog(...) {}
#endif
一直找不到原因
所以就用以下方法了,希望能對大家有幫助



























最近在學習ASIHttpRequest
先認識一下ASIHttpRequest
如果要用到ASIHttpRequest先要向工程中加入CFNetwork.framework
SystemConfiguration.framework, MobileCoreServices.framework, CoreGraphics.framework and libz.1.2.3.dylib
然后再工程中加入所用到的包ASIHttpRequest
接下來就可寫代碼了
















這只是一個很簡單的ASIHttpRequest應用,我也在研究中,呵呵,希望對初學者有一點幫助
iphone中沒有現成的下拉菜單,所以我只能用代碼實現,寫了小例子:

有一些對象沒有進行release,童鞋們可自己稍加改動
/Files/linyu0324/Iphone/DropDown.zip 判斷當前設備:
Ipad:

Mac&Iphone&Ipod:







縮放圖片:







