我目前正在练习 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/