schmru
schmru

Reputation: 619

Realm swift creates objective c files

I just started working with realm in my project.

I have a Cocos2D game project, created with spritebilder. The code is in swift, except the appdelegate, which I don't know why, is in objective-c. I just added, folowing thi instructions https://realm.io/docs/swift/latest/, realm to my project.

I hope i got all the settings right since, the project settings have changed a little in last few xcode versions.

But now when I create new model, instead of being in swift it creates objective-c (.h and .m) files.

Does anyone know why and/or how to fix this?

Thanks for any help

EDIT:

Also tried again with realm objective-c since, I noticed that if I want to create project for iOS 7 i have to use this version https://realm.io/docs/objc/latest/ but still don't know how to create model for swift.

Upvotes: 0

Views: 211

Answers (1)

pteofil
pteofil

Reputation: 4163

Don't use the create new model from the Xcode new file.

Create instead a Swift file and write the Realm object yourself.

This is how a Realm object looks like in Swift:

import RealmSwift

// Dog model
class Dog: Object {
    dynamic var name = ""
    dynamic var owner: Person? // Can be optional
}

More on that in the documentation. It shows you how to create a model right at the beginning, after installation steps.

Upvotes: 2

Related Questions