我確信我可以將該錯誤關閉!看看下面的代碼拋出這個錯誤:如何在xCode中使用之前刪除方法必須聲明的錯誤
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString *databaseName = @"TasksDB.db";
NSArray *documentsDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [documentsDir objectAtIndex:0];
databasePath = [documentsDirectoryPath stringByAppendingPathComponent:databaseName];
[self checkAndCreateDatabase];
// Override point for customization after application launch.
return YES;
}
-(void) checkAndCreateDatabase
{
}
引發錯誤,checkAndCreateDatabase無法識別。這也是因爲我沒有在接口文件中聲明checkAndCreate ...方法,我不想這樣做。
我不希望這種方法從外部調用,這就是爲什麼我沒有在我的頭文件中聲明它們。同時問這個問題將增加我對如何將這些錯誤關閉的知識:) – azamsharp 2012-07-31 15:30:32
它只會在你告訴它的時候纔會調用,所以它不會由於某些外部力量在頭文件中被神奇地運行。 – Jeremy1026 2012-07-31 15:31:48
@ Jeremy1026即使看到這些方法,我也不想*外力*。無論如何..問題解決了! (設計一個可重用的庫的原則之一是,你只能公開你希望調用者調用的方法)。類擴展是解決此問題的一種方法。另一個不是在頭文件中聲明它們。 – azamsharp 2012-07-31 15:35:10