gpt4 book ai didi

ios - 段错误 : 11 - Xcode 10

转载 作者:搜寻专家 更新时间:2023-11-01 06:57:59 26 4
gpt4 key购买 nike

  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

代码如下:

 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 之前有效。有什么想法吗?

最佳答案

没有 NSArray! 这样的类型,而且在任何情况下都没有任何理由让您强制转换为它。删除整个 as NSArray!。使用 Swift 类型。

关于ios - 段错误 : 11 - Xcode 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52377015/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com