gpt4 book ai didi

ios - Swift 的核心数据 transient 值

转载 作者:IT王子 更新时间:2023-10-29 05:21:30 25 4
gpt4 key购买 nike

有谁知道或有示例说明如何使用 Swift 处理核心数据 transient 值?我知道在属性之前使用 @NSManaged,但不知道如何编写逻辑代码以使用 Swift 构建 transient 值。

最佳答案

勾选数据模型中特定属性的transient字段(例如sectionTitle)。
为该实体创建类,它看起来像

 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
}
}

更新- Swift4
为 Swift 4 使用 @objc 标签作为:

@objc var sectionTitle: String? {
return time!.getTimeStrWithDayPrecision()
}

关于ios - Swift 的核心数据 transient 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24729190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com