在RangeText =“ { playlistNames = [] let requestLibrary = NSFetchRequest(entityName:“ Library”)
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Playlist") request.sortDescriptors = [playlistSortDescriptor] playlists = try? context.fetch(request) as NSArray! print("Playlist Count - ",playlists.count) let librarys:NSArray! = try? context.fetch(requestLibrary) as NSArray! for library in librarys{ let libraryName = (library as AnyObject).value(forKey: "library") as! String playlistNames += [libraryName] } for playlist in playlists{ let playlistName = (playlist as AnyObject).value(forKey: "playlistName") as! String if playlistName == "Library" { playlistNames.insert(playlistName, at: 0) }else { playlistNames += [playlistName] } }
}”
- 在RangeText =“ playlists = try时进行类型检查表达式时,将context.fetch(request)用作NSArray!”错误:细分错误:11
代码如下:
func refreshPlaylists(){
playlistNames = []
let requestLibrary = NSFetchRequest<NSFetchRequestResult>(entityName: "Library")
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Playlist")
request.sortDescriptors = [playlistSortDescriptor]
playlists = try? context.fetch(request) as NSArray!
print("Playlist Count - ",playlists.count)
let librarys:NSArray! = try? context.fetch(requestLibrary) as NSArray!
for library in librarys{
let libraryName = (library as AnyObject).value(forKey: "library") as! String
playlistNames += [libraryName]
}
for playlist in playlists{
let playlistName = (playlist as AnyObject).value(forKey: "playlistName") as! String
if playlistName == "Library" {
playlistNames.insert(playlistName, at: 0)
}else {
playlistNames += [playlistName]
}
}
}
在我更新到Xcode 10之前它可以工作。有什么想法吗?
答案 0 :(得分:2)
没有NSArray!
这样的类型,并且在任何情况下都没有任何理由要您强制使用它。删除as NSArray!
。使用Swift类型。