【问题标题】:Error when attempting to assign CoreData property an NSOrderedSet尝试将 CoreData 属性分配给 NSOrderedSet 时出错
【发布时间】:2016-05-20 02:11:03
【问题描述】:

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

" 无法将类型 'NSOrderedSet' 的值分配给类型 '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 的值,而在另一个项目中却可以,我该如何解决这个问题?

【问题讨论】:

  • 这两个项目是什么?他们有什么不同?数据类型错误,在哪里定义的,模型是不是无意编辑的?
  • @op 你解决了这个问题吗?
  • @lifewithelliott,问题解决了吗?

标签: ios debugging core-data compiler-errors


【解决方案1】:

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

【讨论】:

  • 这是不正确的,Core Data ordered 对多的关系表示为NSOrderedSet
  • 现在您确实可以在 Core Data 中订购关系 - 只需选中“订购”框。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-21
  • 1970-01-01
  • 1970-01-01
  • 2018-03-29
  • 2022-11-22
  • 2018-12-26
  • 1970-01-01
相关资源
最近更新 更多