简体   繁体   中英

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

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.

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.

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM