当前位置: 移动技术网 > 移动技术>移动开发>IOS > Xcode 常见错误/警告,处理方法

Xcode 常见错误/警告,处理方法

2018年09月14日  | 移动技术网移动技术  | 我要评论

整理了常见错误,这里记录下,方便后续查询。

xcode 升级后,常常遇到的遇到的警告、错误,解决方法

从sdk3.2.5升级到sdk 7.1中间废弃了很多的方法,还有一些逻辑关系更加严谨了。

1. 警告:“xoxoxoxo” is deprecated

解决办法:查看xoxoxoxo的这个方法的文档,替换掉这个方法即可。

2. 警告:declaration of "struct sockaddr" will not be visible outside of this function

解决办法:在你的开源.m文件中添加 #import

3. 警告:implicit conversion from enumeration type 'uiinterfaceorientation' to different enumeration type 'uideviceorientation'

解决办法:类型不匹配。跳到出错的那一行,uiinterfaceorientation强制转换为uideviceorientation就行了。

4. 警告:incompatible pointer types assigning to 'myarraylist*'from 'nsmutablearray'

解决办法:加入强制转换(myarraylist*)

5. 警告:'&&' within '||'

问题出处: if (exists && !isdirectory || !exists)………

解决办法: if ((exists && !isdirectory) || !exists)………

6. 警告:warning:the copy bundle resources build phase contains this target's info.plist file

解决办法:将info.plist文件移到resources目录下,而不要直接放在target下。

7.警告:在使用asihttp…第三方库的,运行报错。

解决办法:看你的项目中是否添加cfnetwork.framework、systemconfiguration.framework, mobilecoreservices.framework,

coregraphics.framework和libz.1.2.3.dylib,如果是sdk5.0以上,改添加libz.1.2.5.dylib

8.警告:xxxooo,missingrequiredarchitecturei386infile

解决办法:如果是错误信息的话:target->build settings->search paths, 删除frameworksearch paths 里面内容就可以了。

要只是一个警告的话,真机调试可以过。具体解决方法待大神出现。

9.警告:clang: error:no such file or directory: '/demo2/控件代码/13/recorder/recorder_prefix.pch'

clang: error: no input files

command /developer/platforms/iphonesimulator.platform/developer/usr/bin/clang failed with exit code 1

解决办法: 在你的主工程文件 target搜素,pch ,找到prefix header 把它后面的值,都删除,再运行就解决了。

10.警告:“arc forbids synthesizing a property of anobjective-cobject with unspecified ownership or storage attribute

解决办法:如果定义了arc有效,那么必须要有所有者属性的定义;所以代码改成下面这样

@property(nonatomic,strong,readonly)nsstring*ss;

11. 警告:io6一下的xib均没有自动选择use autolayout, supportingios5 and below with xib of ios 6

解决办法:just un-select “use autolayout” in the file inspector of the xib’s view and we are back to the familiar autosizing in size inspector and boom, it supports ios 5 and below.

12. 警告:warning:multiple build commands for output file xxx.png

解决办法:找到项目里xxx.png重复,删除重复的资源。

//以下是升级到 xcode 5.0.1 之后使用遇到的警告

13.警告:“ios 模拟器”未能安装此应用程序。

解决办法:删除模拟器上当前要运行那个app,重新运行项目。就ok

14.警告:springboard无法启动应用程序 错误:-3

解决办法:退出模拟器,重新运行这个项目。

15.警告:the server certificate failed to verify.

解决办法:1、打开终端(实用工具 -->终端),在终端中输入如下命令:

svn lshttps://192.100.1.11?0/svn/xxxxxx(注意下面的url更换成你自己的url地址)

然后直接输入 “ p ” 确认,就可以重新连接了。

16.警告:bitmasking for introspection of objective-c object pointers is strongly discouraged.

解决办法:

某数字& 0x1的时候是代表要取最低位是否为1,改成了 if(jk_expect_f(((nsuinteger)object)%2))即可。

17.警告:implicit conversion loses integer precision: 'unsigned long' to 'cc_long' (aka 'unsigned int').

解决办法:cc_md5(str,strlen(str), r);,改成了 cc_md5(str, (cc_long)strlen(str), r);即可。

18. 警告:error: failed to launch '/private/var/mobile/applications/xxxxx' -- failed to get the task for process 11140.

解决办法:重启你的开发手机即可,还有一种可能是你的开发者证书与发布证书搞错了,检查在xcode中证书是否一直 。

19. 警告:error: ignoring filxxxxxx/libbaidumobstat.a, missing required architecture x86_64 in filexxxx/libbaidumobstat.a

解决办法:

targets ->build setting 下的architectures 设置为 standard architetures(armv7,armv7s) vaild architectures 设置为armv7,armv7s。

20. 警告:error: directory not found for option '-l/users/joryoubonxx/baidustatistic

解决办法:

删除targets ->build setting 下的library search path不正确的地址,如果还不行,重新添加第三库、clean ,重启xcode.即可。

遇到相关的警告,一般编译器都会提供解决方案,所以,作为新手,我们应该看懂编译器给我们的提示,这样我们解决问题就会事半功倍。

21. 错误信息:

"_objc_class_$ xxxxx ", referenced from:

objc-class-ref in viewcontroller.o

ld: symbol(s) not found for architecture i386

clang: error:linker command failed with exit code 1 (use -v to see invocation)

解决方法:

查看工程,看是不是没有导入相关的框架。或者工程里添加的有相同".m",".h" 文件

22. 错误信息:

couldn't register dy.ckrilitext with the bootstrap server. error:unknown error code.

this generally means that another instance of this process was already running or is hung in the debugger.current language: auto; currently objective-c

解决方法:可能是电脑内存问题引起,重启电脑即可解决。如果重启解决不了问题,那就是你刚刚改动的代码引起的问题。

23. 错误信息:

ios 5是调试正常的,ios 6真机调试的时候,出现如下错误:ld: file is universal (3 slices) but does not contain a(n) armv7s slice: /users/mac4/desktop/my desktop/my app/myapp name 20:09:12 /myapp name/zbarsdk/libzbar.a for architecture armv7serror:linker command failed with exit code 1 (use -v to see invocation)

解决方法:在xcode里,点击相应的target,然后点build settings,找到valid_archs,看里面的是不是arvm7s,如果不是改成arvm7s就可以了。

24. 错误信息:

error:receiver type 'viewcontroller' for instance message does not declare a method with selector 'hidesearchbar:' [4]

viewcontroller 中没有声明一个方法选择'hidesearchbar:

解决方法:

在viewcontroller .h 中声明一下这个方法 “hidesearchbar”即可。

25. 错误信息:当json从服务端请求时得到的字符串,如果这样写的话,会报错,';' after top level declarator

nsstring *ss= @"{"recommend":"世界末日","dogname":"机器人"}";

解决方法:

就是,把 “替换成\" 即可。nsstring *ss= @"{\"recommend\":\"世界末日\",\"dogname\":\"机器人\"}";

26. 错误信息:

error: existing instance variable '_datasource' for property 'datasource' with assign attribute must be __unsafe_unretained

解决方法:

id _datasource; 改为 __unsafe_unretained id _datasource:即可

27. 错误信息:

error: no architectures to compile for (only_active_arch=yes, active arch=x86_64, valid_archs=i386).

解决方法:

targets ->build setting 下的 build active architecture only 设置 no即可.

31. 警告:

warning:semantic issue: incompatible integer to pointer conversion assigning to 'bool *' (aka 'signed char *') from 'bool' (aka 'signed char')

解决办法: 检查 bool *换为bool就可以了,检查是不是多写一个 * 号。

32. jsonkit中的警告

direct access to objective-c's isa is deprecated in favor of object_setclass() and object_getclass()

object->isa 替换为 object_getclass(object)

keyobject->isa 替换为 object_getclass(keyobject)

(id)keys[idx]->isa 替换为 object_getclass((id)keys[idx])

format specifies type 'unsigned long' but the argument has type 'nsuinteger' (aka 'unsigned int')

给变量增加(unsigned long)进行类型转换

33. md5(ios sdk中自带了commoncrypto

implicit declaration of function 'cc_md5' is invalid in c99

[plain] view plaincopy

#define cc_md5_digest_length 16

+(nsstring *)md5hashforstring:(nsstring *)input {

const char *cstr = [input utf8string];

unsigned char result[cc_md5_digest_length];

cc_md5(cstr, strlen(cstr), result);

return [nsstring stringwithformat: @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",

result[0], result[1], result[2], result[3],

result[4], result[5], result[6], result[7],

result[8], result[9], result[10], result[11],

result[12], result[13], result[14], result[15]];

}

引入函数定义的头文件

#import

34. asidatadecompressor中的警告

format specifies type'short' but theargument has type 'int'

在+ (serror *)deflateerrorwithcode:(int)code 和 +(nserror *)inflateerrorwithcode:(int)code中

[nsstring stringwithformat:@"compression of data failed with code %hi",code] 中

将code改为 (short)code,类型转换

35. reachability中警告

using 'stringwithstring:' with a literal is redundant

statusstring = [nsstring stringwithstring: @"not reachable"];

改为:statusstring = @"not reachable";

36. format specifies type 'id' but the argument has type 'const char *'

nscassert(no, @"unhandled error encountered during sax parse. msg is %@", msg);

改为:nscassert(no, @"unhandled error encountered during sax parse. msg is %@", [nsstring stringwithutf8string:msg]);

37. using 'stringwithstring:' with a literal is redundant

改为:self.locationinput.text = @"captured change";

38. 在项目中设置控件的layer属性时,会发生错误,

"property 'c' cannot be found in forward class object 'calayer *",

这时需要引入#import 。

39. 错误

error launching remote program: failed to get the task for process

解决方法:

把真机上的软件,删除,然后,clean 一下,重新运行就可以了。

40. ios真机调试中出现identity(the identity 'iphone developer)证书不匹配的问题

提示(null) error: could not read cfbundleidentifier from info.plist (null)

新建一个同名工程,拷贝其plist文件,将原工程中的plist文件替换掉即可。

41. "no previous prototype for function" warning

[po]:出现原因:.m里的函数,.h里面没有定义

warning:no previous prototype for function "randompoint"。如何取消这个警告错误呢?方法尝试了这两种都可以:

1.方法上加修饰符static

2.或者project-info -> targets ->build settings -> llvm gcc4.2 - warnings组 -> missing function prototypes yes->no

42. 真机调试的时候,出现 [attachment=49364] 这正常,但是不识别机器的。

解决方法:

把 [attachment=49365] 设置为以上相对应的版本就可以了。

43. 真机调试的时候,出现 ios broken pipe

解决方法:

:推出xcode

:断开机器(iphone,ipad,ipod)链接

:重启iphone在联接xcode,就可以了。

44. property'ssynthesizedgetterfollowscocoanamingconventionforreturning

[po]:出现原因:是因为苹果在新的编码,不推荐变量以new、copy等关键字开头

解决方法:重命名

45. expected identifier 报错怎么办?

[po]:解决方案: 常见是多了“[]”,仔细检查是否哪里多了[];

46. use of undeclared identifier 错误:

[po]:基本几种情况:

1. .m文件的东西,.h里面没有定义

2. .h里面的东西,缺少头文件 (如:#import "friendsinfo.plist")

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网