分段错误:11 - Xcode 10
Posted
技术标签:
【中文标题】分段错误:11 - Xcode 10【英文标题】:Segmentation fault: 11 - Xcode 10 【发布时间】:2018-09-17 23:43:28 【问题描述】:
在 RangeText=" 的类型检查语句中 播放列表名称 = [] 让 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) as 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 之前它可以工作。有什么想法吗?
【问题讨论】:
我不清楚到底什么是段错误 - 这不是你的应用程序在运行时?是 XCode 还是 Swift 编译器? @Rup 我尝试编译并运行,但它显示了这个错误。 【参考方案1】:没有像NSArray!
这样的类型,在任何情况下,你都没有任何理由去转换它。彻底删除as NSArray!
。使用 Swift 类型。
【讨论】:
以上是关于分段错误:11 - Xcode 10的主要内容,如果未能解决你的问题,请参考以下文章
由于信号分段错误,命令失败 11 Xcode 9 - iOS 模拟器