本文介绍了使用Swift的核心数据瞬态值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有人知道或有一个例子,如何使用Swift处理核心数据瞬态值?我知道在属性之前使用@NSManaged,但是不能弄清楚如何使用Swift来构建瞬态值的逻辑。
Does anyone know, or have an example of, how to handle core data transient values with Swift? I know to use @NSManaged before the properties, but can't figure out how to code the logic to build the transient values using Swift.
推荐答案
在特定属性(例如 sectionTitle
)的数据模型中选中瞬态字段。
创建类对于该实体,它将类似于
Check mark the transient field in your data model for particular attribute(e.g. sectionTitle
).
Create class for that entity, it will look something like
class Message: NSManagedObject {
@NSManaged var body: String?
@NSManaged var time: NSDate?
@NSManaged var sectionTitle: String?
}
编辑它,如下所示:
class Message: NSManagedObject {
@NSManaged var body: String?
@NSManaged var time: NSDate?
var sectionTitle: String? {
return time!.getTimeStrWithDayPrecision()
//'getTimeStrWithDayPrecision' will convert timestamp to day
//just for e.g.
//you can do anything here as computational properties
}
}
这篇关于使用Swift的核心数据瞬态值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!