Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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
从Objective-c传递CLLLocation数组会导致崩溃_Objective C_Arrays_Swift_Nsarray - Fatal编程技术网

从Objective-c传递CLLLocation数组会导致崩溃

从Objective-c传递CLLLocation数组会导致崩溃,objective-c,arrays,swift,nsarray,Objective C,Arrays,Swift,Nsarray,最近,当我尝试将CLLocation数组从Objective-c模块传递到Swift模块时,我得到: 致命错误:NSArray元素与Swift数组元素匹配失败 类型 这是我如何调用函数的: routeLine = [PreloadedLine lineWithLoadedPath:preloadedPath key:lineKey andNotification:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)];

最近,当我尝试将CLLocation数组从Objective-c模块传递到Swift模块时,我得到:

致命错误:NSArray元素与Swift数组元素匹配失败 类型

这是我如何调用函数的:

routeLine = [PreloadedLine lineWithLoadedPath:preloadedPath 
    key:lineKey 
    andNotification:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)];
这是该功能的Swift签名:

class func lineWithLoadedPath(path: [CLLocation]?, 
    key:String?, 
    andNotification notification:Bool)->Line?
这是它的Objective-c签名:

+ (Line * __nullable)lineWithLoadedPath:(NSArray<CLLocation *> * __nullable)path 
    key:(NSString * __nullable)key 
    andNotification:(BOOL)notification;
+(Line*\uuu nullable)lineWithLoadedPath:(NSArray*\uu nullable)路径
键:(NSString*\uuuu nullable)键
和通知:(BOOL)通知;

请相信错误消息。一些不属于CLLocation的东西进入了NSArray

那么,在Objective-C方面,你是说:

 [PreloadedLine lineWithLoadedPath:preloadedPath ...

…但是,
preforedPath
是一个NSArray,其中包含的东西并不都是CLLocations,因此在Swift方面,应用程序崩溃了。

我还将后一个类及其层次结构移植到Swift,这个问题自行解决。

事实上,我传递的值是CLLocations的NSArray。它们之间应该有一个无令牌的桥接。无论如何,我把这件事当作把这个庞大的类移植到swift的借口,我希望这会改善情况。总而言之,我认为Swift Objective-c互操作性最近正在严重降级,也许是为了促使开发人员采用Swift,我不知道。“总而言之,我认为Swift Objective-c互操作性最近正在严重降级”这是一个活板。你不会明白自己做错了什么,除非你承认自己应该受到责备,而不是在“Swift Objective-C互操作性”中插入了某种神秘的小精灵。也许是这样,但一旦我将该类移植到Swift,问题就消失了。显然,在Objective-c和Swift之间,CLC位置的NSARRARY不适合通行。