Kodeco Forums

Video Tutorial: Intermediate Realm on iOS Part 6: Conclusion

Review what you learned in our Intermediate Realm on iOS video tutorial series.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3245-intermediate-realm-on-ios/lessons/7

Another very good tutorial @icanzilb, thanks! :+1: I ran into a few issues running this on Swift 3, which I was able to resolve. So just thought I’d share in case anyone else wants to run through this using Swift 3 before it (and RealmSwift) are updated/released for Swift 3.

  • As with the Beginning tutorial series, I needed to update the Podfile to this before running pod install:
use_frameworks!

target 'Exams' do
    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
end
  • status.realm needed to be upgraded. I also upgraded default_v1.0.realm. To upgrade, just open the files with Realm Browser and it will prompt you.
  • The sha512 extension needed to be rewritten to use withUnsafeMutableBytes(_:). Here’s my implementation:
var sha512: Data? {
    guard var data = self.data(using: .utf8)?.base64EncodedData() else { return nil }
    let count = Int(CC_SHA512_DIGEST_LENGTH)
    var hash = [UInt8](repeating: 0, count: count)
            
    data.withUnsafeMutableBytes {
        _ = CC_SHA512($0, CC_LONG(data.count), &hash)
    }
    
    let result = Data(bytes: hash, count: count)
    return result
}
  • Status needed to be added to objectTypes array in RealmConfig.mainConfig to avoid getting the Invalid class sublist list error:
    objectTypes: [Exam.self, Status.self]

I published my project for this tutorial here.