Install Realm in Swift App

I am trying to add Realm to my application written quickly. I followed the tutorial, and I can’t get it to work. The biggest problem is that when I try to import Realm, I get No such module 'Realm'I don’t know what else to try. You can see my efforts below.

Here you can see the instructions: http://realm.io/docs/cocoa/0.85.0/#swft

I also copied the following instructions:

Due to the lack of proper infrastructure for managing Swift dependency, using Realm in your project requires the following steps:

  • Add Realm as a submodule by opening the terminal, cd-ing in the top-level project directory and issuing the git subodule add git @ github.com command: realm / realm- cocoa.git
  • Open the realm-cocoa folder and drag Realm.xcodeproj into the file navigator of your Xcode project.
  • In Xcode, go to the target configuration window by clicking the blue project icon and selecting the target application program in the "Targets" section of the sidebar.
  • In the tab bar at the top of this window, open the Build Phases panel.
  • Expand the Goal Dependencies gorup and add the iOS Realms infrastructure.
  • Expand the "Link Binary with Libraries" group and add the iOS Realms infrastructure as well as libC ++. dylib.
  • Click the + button in the upper left corner of the panel and select "New phase of copy files." Rename this new step to Copy Frames, set the Assignment to Frames, and add Realm.framework.
  • realm- cocoa/Realm/Swift/RLMSupport.swift Xcode, " , ".

, :

enter image description hereenter image description hereenter image description hereenter image description hereenter image description here

+4
3

Realm, , Realm <= 0.85 . , 0.86, , . , . https://github.com/smitt04/testRealm

0.86 , .

+4

, , :

  • .

  • , ,

    • Objective-C xcode.
    • ,
    • Objective-C

  • :

    #import "Realm/Realm.h"

  • Import Realm, RLMSupport.swift

  • . , , ViewController.swift

    import UIKit
    
    class Person: RLMObject {
        dynamic var name = ""
        dynamic var birthdate = NSDate(timeIntervalSince1970: 1)
    }
    
    class ViewController: UIViewController {
        override func viewDidLoad() {
            super.viewDidLoad()
    
            let author = Person()
            author.name = "David Foster Wallace"
    
            // Get the default Realm
            let realm = RLMRealm.defaultRealm()
    
            // Add to the Realm inside a transaction
            realm.beginWriteTransaction()
            realm.addObject(author)
            realm.commitWriteTransaction()
    
            // Print all Persons
            println(Person.allObjects())
        }
    }
    

:

RLMArray <0x7a243760> (
    [0] Person {
        name = David Foster Wallace;
        birthdate = 1970-01-01 00:00:01 +0000;
    }
)
+7

Swift , , .

Follow the installation instructions here .

+2
source

All Articles