Search code examples
swiftnsarray

Swift 3.0 passing NSArray as Any


We have a framework in Objective-C that has an init that has NSArray as a parameter.

Using the framework from Swift 3 all is good, except trying to pass an NSArray as a parameter.

Error is:

Cannot convert value of type 'NSArray' to expected argument type '[Any]!'

Tried all sorts of type casting with no luck. Anyway to get this to pass?

Please no comments on using NSArray in Swift, etc.


Solution

  • This code seems to be working in playgrounds and not showing any errors

    func someFunc(nsarray: NSArray) {
        /// some implementation
    }
    
    let array = [Any]()
    
    someFunc(nsarray: array as NSArray)