【发布时间】:2011-02-03 19:12:40
【问题描述】:
我开始学习 Objective-C 并帮助我这样做,我正在使用“Head First iPhone Development”。现在我正在学习 SQLite 数据库并让这些数据库正常工作,我被告知 SQLite 文件需要位于应用程序的 Documents 文件夹中,因此我必须移动该文件。
我正在使用书中的示例,但似乎无法使其正常工作。每次我编译它时,我的应用程序都会崩溃。我有以下警告:“初始化'struct NSURL *'的不兼容的Objective-C类型,预期'struct NSString *'
有没有人知道如何解决这个问题?
编辑:
问题似乎出在这两行中,applicationDocumentsDirectory 返回一个 NSURL,但我告诉它返回一个 NSString。我可以告诉它返回一个 NSURL,但这在我使用 stringByAppendingPathComponent 的下一行给我带来了问题。有没有办法解决这个问题?
NSString *documentsDirectory = [self applicationDocumentsDirectory];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"iBountyHunter.sqlite"];
这是应用程序崩溃时调试器控制台输出的内容:
2011-02-04 07:33:42.126 iBountyHunter[591:207] -[NSURL stringByAppendingPathComponent:]: unrecognized selector sent to instance 0x6043f80
2011-02-04 07:33:42.128 iBountyHunter[591:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL stringByAppendingPathComponent:]: unrecognized selector sent to instance 0x6043f80'
*** Call stack at first throw:
(
0 CoreFoundation 0x00f87be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x010dc5c2 objc_exception_throw + 47
2 CoreFoundation 0x00f896fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00ef9366 ___forwarding___ + 966
4 CoreFoundation 0x00ef8f22 _CF_forwarding_prep_0 + 50
5 iBountyHunter 0x00001d8e -[iBountyHunterAppDelegate createEditableCopyOfDatabaseIfNeeded] + 107
6 iBountyHunter 0x00001f24 -[iBountyHunterAppDelegate application:didFinishLaunchingWithOptions:] + 37
7 UIKit 0x002ba1fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
8 UIKit 0x002bc55e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
9 UIKit 0x002c6db2 -[UIApplication handleEvent:withNewEvent:] + 1533
10 UIKit 0x002bf202 -[UIApplication sendEvent:] + 71
11 UIKit 0x002c4732 _UIApplicationHandleEvent + 7576
12 GraphicsServices 0x018bda36 PurpleEventCallback + 1550
13 CoreFoundation 0x00f69064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
14 CoreFoundation 0x00ec96f7 __CFRunLoopDoSource1 + 215
15 CoreFoundation 0x00ec6983 __CFRunLoopRun + 979
16 CoreFoundation 0x00ec6240 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x00ec6161 CFRunLoopRunInMode + 97
18 UIKit 0x002bbfa8 -[UIApplication _run] + 636
19 UIKit 0x002c842e UIApplicationMain + 1160
20 iBountyHunter 0x00001cf8 main + 102
21 iBountyHunter 0x00001c89 start + 53
)
terminate called after throwing an instance of 'NSException'
【问题讨论】:
标签: iphone objective-c sqlite sdk