细分错误:11-Xcode 10

时间:2018-09-17 23:43:28

标签: ios swift xcode xcode10

  
      
  1. 在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.   
  3. 在RangeText =“ playlists = try时进行类型检查表达式时,将context.fetch(request)用作NSArray!”错误:细分错误:11
  4.   

代码如下:

 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之前它可以工作。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

没有NSArray!这样的类型,并且在任何情况下都没有任何理由要您强制使用它。删除as NSArray!。使用Swift类型。