问题
While type-checking statement at 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] } }
}"
- While type-checking expression at RangeText="playlists = try? context.fetch(request) as NSArray!" error: Segmentation fault: 11
Here is the code:
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]
}
}
}
It works before i updated to Xcode 10. Any idea ?
回答1:
There is no such type as NSArray!
and in any case there was never any reason for you to cast to it. Delete as NSArray!
throughout. Use Swift types.
来源:https://stackoverflow.com/questions/52377015/segmentation-fault-11-xcode-10