swift – 可选Int在领域
发布时间:2020-12-14 05:40:52 所属栏目:百科 来源:网络整理
导读:我想在国内使用一个可选的Int,而且我想到了一个旧的错误. 码 dynamic var reps: Int? = nil 错误 'Property cannot be marked dynamic because its type cannot be represented in Objective-C' 我在XCode 7.1中使用Realm 0.96.1 我在领域文档中明白,Int不支
我想在国内使用一个可选的Int,而且我想到了一个旧的错误.
码 dynamic var reps: Int? = nil 错误 'Property cannot be marked dynamic because its type cannot be represented in Objective-C' 我在XCode 7.1中使用Realm 0.96.1 我在领域文档中明白,Int不支持可选,但是https://twitter.com/realm/status/656621989583548416.这是来自领土twitter,所以我为什么感到困惑.是否支持可选内容?
从领域文件:
String,NSDate和NSData属性可以使用标准Swift语法声明为可选或非可选. 可选数字类型使用RealmOptional声明: class Person: Object { // Optional string property,defaulting to nil dynamic var name: String? = nil // Optional int property,defaulting to nil // RealmOptional properties should always be declared with `let`,// as assigning to them directly will not work as desired let age = RealmOptional<Int>() } let realm = try! Realm() try! realm.write() { var person = realm.create(Person.self,value: ["Jane",27]) // Reading from or modifying a `RealmOptional` is done via the `value` property person.age.value = 28 } RealmOptional支持Int,Float,Double,Bool和Int(Int8,Int16,Int32,Int64)的所有大小版本. 更新: Realm的Tweet中提到的可选Ints只是关于RealmOptional实现一个可选数字值与大小版本的Int的错误修复 如果您想在Realm对象中具有可选数字值,那么According给来自领域的人员仍然需要使用RealmOptional.您不能像其他可选类型一样使用它. 所以动态var reps:Int?不管用. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- iphone – 查找objc运行时数据不安全
- 如何从dojo插件中的require failure中恢复?
- “JInstaller ::安装:找不到Joomla XML安装文件”:无法安
- swift – IOS:模糊使用init(CGImage)
- c# – System.Net.HttpWebResponse返回System.IO.Stream.Nu
- 机房收费系统:(二)VB中强制大小写转换和记录集操作
- 疯狂XML学习笔记(6)-----------XML拓展
- ruby-on-rails – 处理API速率限制?
- 需要Flex说明:width,min(max)Width,explicitWidth,explici
- c# – 将数字增加1
推荐文章
站长推荐
热点阅读