前言
整理之前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 ***