Search code examples
objective-carraysswiftnsarray

Passing a CLLLocation array from Objective-c produces a crash


Since recently when I try to pass an array of CLLocation from an Objective-c module to a Swift one I get:

fatal error: NSArray element failed to match the Swift Array Element type

This is how I call the functions:

routeLine = [PreloadedLine lineWithLoadedPath:preloadedPath 
    key:lineKey 
    andNotification:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)];

and here is the Swift signature for the function:

class func lineWithLoadedPath(path: [CLLocation]?, 
    key:String?, 
    andNotification notification:Bool)->Line?

And this is the Objective-c signature for it:

+ (Line * __nullable)lineWithLoadedPath:(NSArray<CLLocation *> * __nullable)path 
    key:(NSString * __nullable)key 
    andNotification:(BOOL)notification;

Solution

  • I also ported the latter class to Swift along with its hierarchy and this problem got away by itself.