0
我只是轉換一個項目從斯威夫特2至3斯威夫特後我得到一個錯誤,但我不明白爲什麼代碼是一個問題:.MAP生產[T]斯威夫特3從斯威夫特轉換2
var imagesInProject : NSArray?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
print(paths[0])
if let urls = Bundle.main.urls(forResourcesWithExtension: "png", subdirectory: nil) {
imagesInProject = urls.filter {$0.lastPathComponent.hasPrefix("AppIcon") == false} .map {$0.lastPathComponent!}
}
return true
}
的錯誤是:「‘地圖’產生‘[T]’,而不是預期的情境結果類型‘的NSArray?’」
我該如何解決這個問題?我熟悉.map,但我不完全瞭解錯誤或代碼錯誤(現在)
謝謝!
別使用'NSArray',使用一個實際的類型快速數組 – dan