mnewmedia mnewmedia - 10 months ago 50
Swift Question

why to i have to cast NSMutableArray to NSMutableArray?

In my function arguments I declared that

argument has to be of type
. Why does Xcode then say that the
argument is of typ
and I have to cast it to

internal func downloadMultiple(files: NSMutableArray, remoteBaseUrl: NSURL, completion: (result: Int)->()) -> Void {
self.filesToDownload = files.mutableCopy() as! NSMutableArray // why this cast necessary?
self.cb = completion

for item in files {
print("file ", item["file"] as! String)["file"] as! String)!)

Answer Source

mutableCopy is implemented by NSObject and defined as:

func mutableCopy() -> Any

So therefore when you call mutableCopy() the resulting object needs to be cast.