2014-10-31 97 views
-2
NSString *docsDir; 
NSArray *dirPaths; 
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
// Build the path to the database file 
docsDir = dirPaths[0];/// at this point i receive an error that incompatible type error plxxxx help me 
+0

是否有關於錯誤的更多詳細信息? – rmaddy 2014-10-31 05:34:27

+0

先生,我是新的ios開發..我沒有關於這個錯誤的更多細節 – 2014-10-31 05:38:54

+0

我測試你的代碼與我的xcode 6,它運作良好。所以請顯示更多的細節。 – Leo 2014-10-31 05:40:13

回答

0

試試這個

NSString *docsDir; 
NSArray *dirPaths; 
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
// Build the path to the database file 

docsDir=[NSString stringWithFormat:@"%@",dirPaths[0]]; 
+0

在同一範圍內,不能有兩個具有相同名稱的變量。 – rmaddy 2014-10-31 05:43:58

+0

爲什麼你認爲你需要使用'stringWithFormat:'? – rmaddy 2014-10-31 05:44:21

+0

now happy @rmaddy – sanjeet 2014-10-31 05:46:08

0

只需使用下面的代碼

NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

    NSString *sql_Path=[paths objectAtIndex:0]; 

它會幫助你。

+0

這與問題中的代碼有什麼不同?它與你的答案使用舊的數組語法相同,而問題使用新的數組語法。 – rmaddy 2014-10-31 05:45:14

+0

我們可以通過這種方式或者一種方式來給出解決方案。如果他在他的代碼中放置了[paths objectAtIndex:0],它將起作用。這是用於減少代碼的原因,這就是爲什麼我只設置了兩行代碼。 – user3182143 2014-10-31 05:47:27

+0

但是,您的代碼與問題中的代碼實際上是相同的。你的回答並不能解釋爲什麼問題中的代碼無效。 – rmaddy 2014-10-31 05:48:26

相關問題