swift - 在 Realm 中存储字符串数组列表

标签 swift realm

如果我只想在 Realm 中存储字符串数组,是否必须将其包装在扩展 Object 的自定义类中?

示例:

class ExampleObject : Object {
   var stringArray : List<String> 
}

最佳答案

从 Realm-Cocoa 3.0.0 开始就没有了。

Loosen RLMArray and RLMResults's generic constraint from RLMObject to NSObject. This may result in having to add some casts to disambiguate types.

List can now contain values of types Bool, Int, Int8, Int16, Int32, Int64, Float, Double, String, Data, and Date (and optional versions of all of these) in addition to Object subclasses.

Querying Lists containing values other than Object subclasses is not yet implemented.

所以以下应该可以正常工作:

class Student : Object {
    let stringArray = List<String>()
}

关于swift - 在 Realm 中存储字符串数组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51430521/

相关文章:

iOS Firebase 分离观察者监听器

ios - 项目加载时的 Xcode 自动布局问题

ios - Xcode 10.2 中的 Realm Swift - Swift 5.0 编译器无法导入错误 : Module compiled with Swift 4. 2

swift2 - Realm Swift2 : Best practice for model and Realm model class separation

swift - 如何在 Swift 扩展中重新定义默认类 init() ?

swift - struct 中的 swift 类在分配期间是否通过副本传递?

ios - Realm 迁移不起作用

java - 现有 Realm 文件中字段 'String' 的无效类型 'id'

swift - 标题没有显示,每次我连接源和委托(delegate)时,程序都会崩溃,当我不连接它们时,它不会打印任何内容

android - Realm.io - 是否可以通过其子对象找到对象?