我必须将以下几行 Objective-c 代码翻译成 swift。这是来自 Objective-c JSONModel-Framework的示例,其中框架Optional
提供的协议应用于类型为 的实例变量NSString
。我找到了一个相关的帖子,但我没有设法实现它。随着我的MYModel.swift
实施 Xcode 抱怨Cannot specialize non-generic type NSString
谢谢你的帮助!
MYModel.swift
@objc(MYModel) public class MYModel : JSONModel {
...
public var name : NSString<Optional>
...
}
MYModel.h
@interface MYModel : JSONModel
...
@property (strong, nonatomic) NSString<Optional>* name;
...
...
/**
* Protocol for defining optional properties in a JSON Model class. Use like below to define
* model properties that are not required to have values in the JSON input:
*
* @property (strong, nonatomic) NSString<Optional>* propertyName;
*
*/
@protocol Optional
@end
...