[英]How can I cast an NSMutableArray to a Swift array of a specific type?
[英]NSMutableArray cast to swift Array of custom type
我想弄清楚如何指定NSMutableArray或將其轉換為自定義類型的swift Array。 我目前有2個文件:
let newArray: [CustomType]!
我需要將NSMutableArray作為參數傳遞給第二個文件中的函數,該文件需要[CustomType]。 當簡單地調用它時:
let newVC = UIViewController(array: mutableArray)
它一直告訴我'CustomType' is not identical to 'AnyObject'
。 我嘗試使用mutableArray as [CustomType]
調用該函數,該函數也不起作用。 如何使Swift Array函數接受我的NSMutableArray?
這對我有用:
var swiftArray = NSArray(array:mutableArray) as Array<CustomType>
swiftArray
然后是CustomType對象的Swift數組。 您可以按預期傳遞數組並對其進行迭代。
我需要的是:
讓newVC = UIViewController(數組:mutableArray作為AnyObject作為[CustomType])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.