Swift敲代码时出现的错误总结
来源:互联网 发布:电脑锣编程培训 编辑:程序博客网 时间:2024/06/04 19:04
- func touchesEnded(touches: Set, withEvent event: UIEvent) {}方法在xocde7.1中变为了:
func touchesEnded(touches:Set<UITouch>,withEvent event: UIEvent?) {}.
否则会出现 method does not override any method…的错误。
2 . 出现Cannot convert value of type ‘[String: String?] to expected argument type ‘NSDictionary’ 的错误时,应检查定义的变量是否为OPtionl类型,如果是,在其后面加一个 ‘!’。
3.使用带throws方法时,应写成:
do{ // NSManagedObjectContext对象保存 try context.save() }catch let error as NSError{ print(error.localizedDescription) }
4.Xcode7 使用NSURLSession发送HTTP请求的问题 :Application Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file.
应在plist文件中,加入:
<plist> <dict> .... <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> </dict> </plist>
中的部分代码
原因:在iOS9beta中,苹果将原http协议改成了https协议,使用 TLS1.2 SSL加密请求数据。
5.Swift2.0后,Swift中的find函数不能使用了,需要用到indexOf方法,以前的使用方式是:
let arr:Array = ["a","b","c"]find(arr, "c")! // 2find(arr, "d") // nil
现在需要改为(即使用indexOf方法):
let arr = ["a","b","c"]let indexOfA = arr.indexOf("a") // 0let indexOfB = arr.indexOf("b") // 1let indexOfD = arr.indexOf("d") // nil
更详细的解释在:http://stackoverflow.com/questions/24028860/how-to-find-index-of-list-item-in-swift
6.在做跳转到注册和登录页面时出现了:Attempt to present on whose view is not in the window hierarchy! 的错误,它指的是要加载的ViewController并没有加载。这时应该是:由于在 viewDidLoad 里面调用引起的,解决办法是转移到 viewDidAppear 方法里面。
具体见:http://www.cnblogs.com/xunziji/p/4025009.html
7.在调用fmdb库时出现了以下的错误:
Ld /Users/user1319/Library/Developer/Xcode/DerivedData/Directory-app normal armv7 cd /Users/user1319/Desktop/app/app setenv IPHONEOS_DEPLOYMENT_TARGET 5.0 setenv PATH "/Developer/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Developer/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch armv7 -isysroot /Developer/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -L/Users/user1319/Library/Developer/Xcode/DerivedData/app_Directory-bnkhohrmxdhrusarswxeqvxlljct/Build/Products/Distribution-iphoneos -F/Users/user1319/Library/Developer/Xcode/DerivedData/app-bnkhohrmxdhrusarswxeqvxlljct/Build/Products/Distribution-iphoneos -filelist "/Users/user1319/Library/Developer/Xcode/DerivedData/app-bnkhohrmxdhrusarswxeqvxlljct/Build/Intermediates/app Directory.build/Distribution-iphoneos/app.build/Objects-normal/armv7/app.LinkFileList" -Xlinker -rpath -Xlinker / -dead_strip -miphoneos-version-min=5.0 -lsqlite3 -lsqlite3.0 -framework AddressBook -framework AddressBookUI -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/user1319/Library/Developer/Xcode/DerivedData/app-bnkhohrmxdhrusarswxeqvxlljct/Build/Products/Distribution-iphoneos/app.app/appld: warning: ignoring file /Developer/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/libsqlite3.dylib, missing required architecture armv7 in fileld: warning: ignoring file /Developer/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/libsqlite3.0.dylib, missing required architecture armv7 in fileUndefined symbols for architecture armv7: "_sqlite3_reset", referenced from: -[FMDatabase executeUpdate:error:withArgumentsInArray:orVAList:] in FMDatabase.o -[FMStatement reset] in FMDatabase.o -[FMResultSet next] in FMResultSet.o "_sqlite3_bind_blob", referenced from: -[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o "_sqlite3_changes", referenced from: -[FMDatabase changes] in FMDatabase.o "_sqlite3_prepare_v2", referenced from: -[FMDatabase executeQuery:withArgumentsInArray:orVAList:] in FMDatabase.o -[FMDatabase executeUpdate:error:withArgumentsInArray:orVAList:] in FMDatabase.o -[FMDatabase(FMDatabaseAdditions) validateSQL:error:] in FMDatabaseAdditions.o "_sqlite3_open", referenced from: -[FMDatabase open] in FMDatabase.o "_sqlite3_open_v2", referenced from: -[FMDatabase openWithFlags:] in FMDatabase.o "_sqlite3_bind_text", referenced from: -[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o "_sqlite3_step", referenced from: -[FMDatabase executeUpdate:error:withArgumentsInArray:orVAList:] in FMDatabase.o -[FMResultSet next] in FMResultSet.o "_sqlite3_next_stmt", referenced from: -[FMDatabase close] in FMDatabase.o "_sqlite3_bind_double", referenced from: -[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o "_sqlite3_threadsafe", referenced from: +[FMDatabase isThreadSafe] in FMDatabase.o "_sqlite3_bind_int", referenced from: -[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o "_sqlite3_last_insert_rowid", referenced from: -[FMDatabase lastInsertRowId] in FMDatabase.o "_sqlite3_column_blob", referenced from: -[FMResultSet dataForColumnIndex:] in FMResultSet.o -[FMResultSet dataNoCopyForColumnIndex:] in FMResultSet.o "_sqlite3_finalize", referenced from: -[FMDatabase close] in FMDatabase.o -[FMDatabase executeQuery:withArgumentsInArray:orVAList:] in FMDatabase.o -[FMDatabase executeUpdate:error:withArgumentsInArray:orVAList:] in FMDatabase.o -[FMStatement close] in FMDatabase.o -[FMDatabase(FMDatabaseAdditions) validateSQL:error:] in FMDatabaseAdditions.o "_sqlite3_column_text", referenced from: -[FMResultSet kvcMagic:] in FMResultSet.o -[FMResultSet stringForColumnIndex:] in FMResultSet.o -[FMResultSet UTF8StringForColumnIndex:] in FMResultSet.o "_sqlite3_column_bytes", referenced from: -[FMResultSet dataForColumnIndex:] in FMResultSet.o -[FMResultSet dataNoCopyForColumnIndex:] in FMResultSet.o "_sqlite3_column_int64", referenced from: -[FMResultSet longForColumnIndex:] in FMResultSet.o -[FMResultSet longLongIntForColumnIndex:] in FMResultSet.o "_sqlite3_bind_parameter_count", referenced from: -[FMDatabase executeQuery:withArgumentsInArray:orVAList:] in FMDatabase.o -[FMDatabase executeUpdate:error:withArgumentsInArray:orVAList:] in FMDatabase.o "_sqlite3_column_count", referenced from: -[FMResultSet columnCount] in FMResultSet.o -[FMResultSet setupColumnNames] in FMResultSet.o -[FMResultSet kvcMagic:] in FMResultSet.o "_sqlite3_column_name", referenced from: -[FMResultSet setupColumnNames] in FMResultSet.o -[FMResultSet kvcMagic:] in FMResultSet.o -[FMResultSet columnNameForIndex:] in FMResultSet.o "_sqlite3_errmsg", referenced from: -[FMDatabase lastErrorMessage] in FMDatabase.o -[FMDatabase executeUpdate:error:withArgumentsInArray:orVAList:] in FMDatabase.o -[FMResultSet next] in FMResultSet.o "_sqlite3_column_type", referenced from: -[FMResultSet stringForColumnIndex:] in FMResultSet.o -[FMResultSet dateForColumnIndex:] in FMResultSet.o -[FMResultSet dataForColumnIndex:] in FMResultSet.o -[FMResultSet dataNoCopyForColumnIndex:] in FMResultSet.o -[FMResultSet columnIndexIsNull:] in FMResultSet.o -[FMResultSet UTF8StringForColumnIndex:] in FMResultSet.o -[FMResultSet objectForColumnIndex:] in FMResultSet.o... "_sqlite3_libversion", referenced from: +[FMDatabase sqliteLibVersion] in FMDatabase.o "_sqlite3_errcode", referenced from: -[FMDatabase lastErrorCode] in FMDatabase.o -[FMResultSet hasAnotherRow] in FMResultSet.o "_sqlite3_column_int", referenced from: -[FMResultSet intForColumnIndex:] in FMResultSet.o "_sqlite3_close", referenced from: -[FMDatabase close] in FMDatabase.o "_sqlite3_column_double", referenced from: -[FMResultSet doubleForColumnIndex:] in FMResultSet.o "_sqlite3_data_count", referenced from: -[FMResultSet resultDict] in FMResultSet.o "_sqlite3_bind_int64", referenced from: -[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o "_sqlite3_bind_null", referenced from: -[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.old: symbol(s) not found for architecture armv7clang: error: linker command failed with exit code 1 (use -v to see invocation)
解决办法:
1.到 Build Phases > Link Binary with Libraries > + > Add other
2.接着按快捷键 command”+shift+G (快速打开文件)到/ usr/lib/ 目录下
3.找到并一一添加 libz.dylib 和 ibsqlite3.dylib 文件,这样就OK了
具体参考:http://stackoverflow.com/questions/9762727/missing-required-architecture-armv7
http://stackoverflow.com/questions/31420166/libsqlite3-dylib-and-libz-dylib-missing-in-xcode-7-how-do-i-use-parse
8.ios8在UIViewController与xib文件关联时,会出现xib上的控件与视图控制器关联失败,运行时会出现控件为空:nil的错误。
解决办法:在视图控制器类的文件前加上一个@objc(类名):
@objc(ViewController) class ViewController: UIViewController {}
- Swift敲代码时出现的错误总结
- Swift敲代码时出现的错误总结
- swift按钮通过代码添加点击事件时出现unrecognized selector sent to instance 0x136ea5010错误
- Swift使用SnapKit给控件添加约束时出现的三个错误
- Swift中出现“no such module cocoa”的错误
- 代码生成器生成项目运行时出现的错误
- 在xcode 调试C++ 代码时出现的EXC_BAD_ACCESS 错误
- 写代码时容易出现的错误(持续更新)
- 重构遗留系统时出现的错误-总结
- ARC总结,学习arc时出现的错误
- iOS巅峰之编译时出现的错误(总结)
- 在编译hbase代码出现的错误
- 自己项目中出现的错误总结:
- dx使用出现的错误总结
- Qt中出现的错误总结
- Qt中出现的错误总结
- Qt中出现的错误总结
- Qt中出现的错误总结
- Qt线程中的一些关键字
- 5.10
- Oracle 12c 多租户 CDB 与 PDB 备份
- 经典排序——希尔排序——C语言版
- 利用JQuery一步步打造无缝滚动新闻
- Swift敲代码时出现的错误总结
- 在JavaScript中创建表格
- 进程、线程
- 子网掩码
- kibana visualize添加自定义查询
- 图像金字塔
- Android签名打包的作用
- 机器学习——感知器算法及python实现
- studio的快捷键(全面)