Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 不兼容类型错误?我不明白我做错了什么?_Ios_Xcode - Fatal编程技术网

Ios 不兼容类型错误?我不明白我做错了什么?

Ios 不兼容类型错误?我不明白我做错了什么?,ios,xcode,Ios,Xcode,试试这个 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 incomp

试试这个

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 

只需使用下面的代码

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

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

这将对您有所帮助。

关于这个错误还有更多的细节吗?先生,我是ios开发新手。我没有关于这个错误的更多细节。我用我的xcode 6测试您的代码,它工作得很好。因此请显示更多详细信息。在同一范围内不能有两个名称相同的变量。为什么您认为需要使用
stringWithFormat:
?没有,因为您仍然不需要使用
stringWithFormat
dirpath[0]
已经是一个
NSString
。你为什么要问别人为什么不上传你自己的答案?这是我的(sanjeet)代码不是mady code@Muhammad Ali这与问题中的代码有何不同?答案是一样的,只是你的答案使用了旧的数组语法,而问题使用了新的数组语法。我们可以这样或那样给出解决方案。如果他在代码中加入[paths objectAtIndex:0],它会工作的。这是用来减少代码的,这就是为什么我只设置了两行。但是你的代码实际上与问题中的代码相同。你的回答没有解释问题中的代码不起作用的原因。是的,你完全正确。这可能不是问题。另一部分的代码实际上是错误的。
  NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

  NSString *sql_Path=[paths objectAtIndex:0];