我正在跟上美妙的 RubyMotion 的速度,但在更新 NSManagedObject 字段时遇到了问题,我的项目基于示例应用程序Locations
locations_store.rb 中的代码有一个创建和删除...
def add_location
# Yield a blank, newly created Location entity, then save the model.
yield NSEntityDescription.insertNewObjectForEntityForName('Location', inManagedObjectContext:@context)
save
end
def remove_location(location)
# Delete the given entity, then save the model.
@context.deleteObject(location)
save
end
但是,我正在努力寻找一种方法来实现类似的方法来更新数据存储,在我的新 location_details_controller.rb 中,我正在存储一个这样的位置实例,
def showDetailsForLocation(location)
@location = location
navigationItem.title = "%0.3f, %0.3f" % [location.latitude, location.longitude]
end
然后当点击保存按钮时触发......
def saveLocation(sender)
LocationsStore.shared.update_location(@objectid, "field1updatevalue", "field2updatevalue")
end
但是,我尝试了很多方法来破解它,但找不到用这种方法更新记录的方法......
def update_location(location, f1, f2)
location.f1 = f1
location.f2 = f2
save
end