gpt4 book ai didi

ios - RestKit RKObjectMapping Swift 可选

转载 作者:搜寻专家 更新时间:2023-10-30 22:01:04 25 4
gpt4 key购买 nike

我有一个名为 Activity 的 swift 模型,它可以选择附加一个 coordinate

import MapKit

class Activity: NSObject {

var coordinate: CLLocationCoordinate2D?

class func objectMapping() -> RKObjectMapping {
let mapping = RKObjectMapping(forClass: self)

let coordinateMapping = RKAttributeMapping(fromKeyPath: "coordinate", toKeyPath: "coordinate")
coordinateMapping.valueTransformer = RKCLLocationCoordinate2DValueTransformer()
mapping.addPropertyMapping(coordinateMapping)

return mapping
}
}

当启动我的应用程序时,这给了我:

2015-05-05 12:14:30.741 Sample[54338:531558] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key coordinate.'

如果我将 coordinate 更改为非可选的并提供默认值,应用程序将运行。

所以我的问题是如何快速使用 RestKit 关于 Optionals?

最佳答案

使您的属性动态

dynamic var coordinate: CLLocationCoordinate2D?

关于ios - RestKit RKObjectMapping Swift 可选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30058351/

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