Should I use Realm Objective-C or Realm Swift in my mixed Objective-C / Swift project?

泄露秘密 提交于 2020-01-13 09:29:11

问题


My project uses Swift and targets iOS 8.0 and newer, but we use some files from our old Objective-C project, and brings in some Objective-C libraries via CocoaPods. Which Realm interface should I use in this project: Objective-C or Swift? I'm confused because of the announcement in the Realm documentation:

If you’re looking to use Realm from Objective-C, or from mixed Objective-C & Swift apps please see Realm Objective-C instead. Using both Realm Objective-C and Realm Swift simultaneously is not supported.


回答1:


They key detail is whether you intend to access your Realm model classes from only Swift, or both Swift and Objective-C. If you will only access them from Swift you can happily use Realm Swift, even if elsewhere in your application you use code written in Objective-C. If you will access your Realm model classes from both Swift and Objective-C code you'll need to use Realm Objective-C rather than Realm Swift.




回答2:


If you’re looking to use Realm purely from Swift, you should consider using Realm Swift instead. Using both Realm Objective-C and Realm Swift simultaneously is not supported.




回答3:


I would recommend that you use Realm Swift only if you intend to use it from Swift otherwise you should use Realm Objective-C. One of the reasons for this would be that at this point List and RealmOptional properties aren’t accessible from Objective‑C.



来源:https://stackoverflow.com/questions/34328574/should-i-use-realm-objective-c-or-realm-swift-in-my-mixed-objective-c-swift-pr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!