Segmentation fault: 11 - Xcode 10

淺唱寂寞╮ 提交于 2019-12-14 02:31:52

问题


  1. 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]
        }
    }
    

    }"

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!