前言
整理之前iOS開發中遇到的問題,集合一下。很大部分來自StackOverFlow。
問題1:Xcode release下調試報錯[Project Name] was compiled with optimization - stepping may behave oddly; variables may not be available
解決:Build Setting中的optimization level release改為與debug一樣的模式。
問題2:Xcode代碼中類和方法等字體變黑文件失去關聯symbol not found
解決:Xcode用得久了,代碼中類和方法等字體變黑文件失去關聯symbol not found,連智能提示有時候都沒有,這里是因為工程索引文件被破壞導致,可通過以下方法解決:
一、Organizer -> Projects ->把所有工程中的Derived Data 刪除Delete掉。
二、進入~/Library/Developer/Xcode/DerivedData 這個文件夾,把里面相關工程的文件夾刪掉。
問題3:提交SVN Target沒有顯示出來
解決:需要勾選Autocreate schemes
問題4:property follows cocoa naming convention for returning 'owned’ objects
注意:
- 代碼中不能使用retain, release, retain, autorelease
- 不重載dealloc(如果是釋放對象內存以外的處理,是可以重載該函數的,但是不能調用[super dealloc])
- 不能使用NSAllocateObject, NSDeallocateObject
- 不能在C結構體中使用對象指針
- id與void *間的如果cast時需要用特定的方法(__bridge關鍵字)
- 不能使用NSAutoReleasePool、而需要@autoreleasepool塊
- 不能使用“new”開始的屬性名稱 (如果使用會有下面的編譯錯誤”Property’s synthesized getter follows Cocoa naming convention for returning ‘owned’ objects”)
問題5:"No previous prototype for function" warning警告錯誤
解決:warning:No previous prototype for function "randomPoint"。如何取消這個警告錯誤呢?方法嘗試了這兩種都可以:
- 1.方法上加修飾符static
- 2.或者Project-Info -> TARGETS ->Build Settings -> LLVM GCC4.2 - Warnings組 -> Missing Function Prototypes Yes->No
問題6:Code signing is required for product type 'Application' in SDK 'iOS5.1'
解決:One possible solution which works for me:
Search "code sign" in Build settings
Change everything in code signing identity to "iOS developer", which are "Don't code sign" originally.
問題7:The common causes for "Undefined symbols for architecture armv7"
- You import a header and do not link against the correct library. This is common, especially for headers for libraries like QuartzCore since it is not included in projects by default. To resolve:
- Add the correct libraries in the Link Binary With Libraries section of the Build Phases.
- If you want to add a library outside of the default search path you can include the path in the Library Search Paths value in the Build Settings and add
-l{library_name_without_lib_and_suffix} (eg. for libz.a use -lz) to the Other Linker Flags section of Build Settings.
- You copy files into your project but forgot to check the target to add the files to. To resolve:
- Open the Build Phases for the correct target, expand Compile Sources and add the missing .m files. If this is your issue please upvote Cortex's answer below as well.
- You include a static library that is built for another architecture like i386, the simulator on your host machine. To resolve:
- If you have multiple library files from your libraries vendor to include in the project you need to include the one for the simulator (i386) and the one for the device (armv7 for example).
- Optionally, you could create a fat static library that contains both architectures.
問題8:'_compress2', referenced from:+[UMANUtil deflatedDataPrefixedWith:level:source:] in libMobClickLibrary.a(UMANUtil.o)ld: symbol(s) not found for architecture x86_64clang: error: linker command failed with exit code 1 (use -v to see invocation)
解決:在Other Linker Flags里加入-lz
問題9:objc_msgSend()報錯Too many arguments to function call ,expected 0,have3
解決:Build Setting--> Apple LLVM 6.0 - Preprocessing--> Enable Strict Checking of objc_msgSend Calls 改為 NO
問題10:dyld: Library not loaded: /System/Library/Frameworks/Social.framework/SocialReferenced from: /var/mobile/Applications/00D3E0A7-4FF6-451E-B11C-87D7A189F425/sample.app/sample Reason: image not found
解決:把Build Phases 里Social.framework后邊的選項修改成為Optional就可以了
問題11:Xcode release下調試報錯[Project Name] was compiled with optimization - stepping may behave oddly; variables may not be available
解決:Build Setting中的optimization level release改為與debug一樣的模式。
問題12:is invalid in c99
解決: build setting -> c language dialect -> GNU89
問題13: Xcode build .c文件失敗
原因:對應的.pch文件中,沒有針對Objecttive-C的特殊編譯,是統一指定的,建議加入,
ifdef OBJC
endif
環繞 #import ***