Realm:从 ObjC 迁移到 Swift [英] Realm: Migrating from ObjC to Swift

查看:67
本文介绍了Realm:从 ObjC 迁移到 Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 ObjC 编写的应用程序.我选择了 Realm 作为我的数据库.

I have an app written in ObjC. I've chosen Realm as my DataBase.

我想开始将我的应用程序的某些部分迁移到 Swift.

I would like to start migrating some parts of my app to Swift.

到 Realm 时我很困惑.

When getting to Realm I get confused.

有两个 pods.根据我从文档中了解到的,RealmSwift 适用于纯 Swift 项目,对吗?

There are two pods. From what I understood from the docs, RealmSwift is for pure Swift projects, right?

但是,是否可以在没有 RealmSwift pod 的情况下将模型类迁移到 Swift?

But, is it possible to migrate model classes to Swift without the RealmSwift pod?

推荐答案

据我所知,Realm Swift 并不是纯 Swift 项目的专属,但如果你确实在 iOS 应用程序中使用它,你就无法做出任何从任何 Objective-C 代码调用它.因此,如果您打算将所有 Realm 代码移至 Swift,那么应该没问题.

As I understand it, Realm Swift isn't exclusive for pure Swift projects, but if you do use it in an iOS app, you can't make any calls to it from any Objective-C code. So if you plan to move all of your Realm code to Swift, then it should be okay.

如果您仍然在 Objective-C 中有任何 Realm 代码,那么最好坚持使用 Realm Objective-C 框架,并通过 Swift 桥接头进行任何 Swift 调用.

If you've still got any Realm code in Objective-C, then it would be better to stick with the Realm Objective-C framework, and make any Swift calls via the Swift bridging header.

Realm 文件非常独立于平台,因此如果您在 Swift 中简单地重写 Objective-C 模型类,只要模型属性和类型完全相同,它应该仍然可以正常工作.

Realm files are very platform independent, so if you simply rewrote the Objective-C model classes in Swift, as long as the model properties and types were exactly the same, it should still simply work.

这篇关于Realm:从 ObjC 迁移到 Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆