ios - 尝试将 CoreData 属性分配给 NSOrderedSet 时出错

标签 ios debugging core-data compiler-errors

我目前正在练习 CoreData 并处理我在网上找到的一个项目。我在一个项目上遇到错误,但在另一个项目上没有。但是我不清楚问题是什么。

" Cannot assign value of type 'NSOrderedSet' to type 'Location?' "

func saveRun()
{
    let savedRun = NSEntityDescription.insertNewObjectForEntityForName( "Run", inManagedObjectContext: managedObjectContext!) as! Run
    savedRun.distance = distance
    savedRun.duration = seconds
    savedRun.timestamp = NSDate()

    var savedLocations = [Location]()
    for location in locations
    {
        let savedLocation = NSEntityDescription.insertNewObjectForEntityForName( "Location", inManagedObjectContext: managedObjectContext! ) as! Location
        savedLocation.timestamp = location.timestamp
        savedLocation.latitude = location.coordinate.latitude
        savedLocation.longitude = location.coordinate.longitude

        savedLocations.append( savedLocation )
    }
    savedRun.locations = NSOrderedSet(array: savedLocations)
}

我的问题很简单,为什么我不能在一个项目中为属性位置分配 NSOrderedSet 的值,而在另一个项目中可以,我该如何解决这个问题?

最佳答案

我很确定 CoreData 根本不支持 NSOrderedSet。它可能支持 NSSet 的一对多关系。 NSSorderedSet 是一个有趣的类,它可以让您将项目视为一个集合,同时能够同时对它们进行索引,它很少被使用。

关于ios - 尝试将 CoreData 属性分配给 NSOrderedSet 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37336883/

相关文章:

c++ - Qt 调试器控制台看不到调试 session

android - 在 logcat 中显示额外的 Intent

ios - 如何在 Objective C 中异步加载数据 UITableview 滚动和核心数据获取

ios - 实体关系中的数据属性更改但不触发 nsfetchresultsController

ios - dispatch_group_notify 在所有任务完成之前被调用

ios - NSObject 无法转换

ios - 我应该使用哪种方法在 UICollectionViewCell 之间执行某些操作?

c# - 变量未声明或从未分配?和数据读取器不工作?

ios - Swift 选择 map 图钉并在 tableView Cell 上显示详细信息时如何操作

iphone - utc 和本地日期时间转换