OGeek|极客世界-中国程序员成长平台

标题: ios - Realm 生成模型 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:45
标题: ios - Realm 生成模型

我一直关注this关于 Realm 的教程,我遇到了障碍。 所以它说要生成一个 Realm 模型,为此我们必须通过 Alcaraz 在 Xcode 中安装一个插件。 Shiny 。

现在我面临的问题是,在 Xcode 8+ 中它不允许安装任何外部插件(据我所知,只有那些可以编辑文本的插件)。

我的问题是我如何像本教程所说的那样生成 Realm 模型,现在 Xcode 8+ 不支持外部插件。此外,如果现在不可能,那么我应该如何处理/解决数据模型的这种映射。

我在 Realms git 页面或他们的网站上没有找到任何解决方案。 任何帮助表示赞赏。

我正在使用 Xcode 8.3.2,我正在开发 Swift 3.1

编辑

我已经通过 cocoapods 安装了 Realm。我在问是否有像 Core Data xcdatamodel 这样的可视化生成器,用于 Realm Data 模型,就像以前在 Xcode 插件中一样。



Best Answer-推荐答案


You can use CocoaPods

add following to pods file and install -pod install

 pod 'Realm', git: 'https://github.com/realm/realm-cocoa.git', branch: 'master', submodules: true
  pod 'RealmSwift', git: 'https://github.com/realm/realm-cocoa.git', branch: 'master', submodules: true

  post_install do |installer|
      installer.pods_project.targets.each do |target|
          target.build_configurations.each do |config|
              config.build_settings['SWIFT_VERSION'] = '3.0'
          end
      end
  end

then , Create model class as following

import Foundation
import UIKit
import RealmSwift
import Realm

class ClassName: Object{

required init(value: Any, schema: RLMSchema) {
        super.init(value : value,schema:schema)
        //fatalError("init(value:schema has not been implemented")
    }

    required init() {
        super.init()
        //fatalError("init() has not been implemented")
    }

    required init(realm: RLMRealm, schema: RLMObjectSchema) {
        super.init(realm:realm , schema:schema)
        //fatalError("init(realm:schema has not been implemented")
    }

}

关于ios - Realm 生成模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44198781/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4