I posted this on StackOverflow http://stackoverflow.com/q/43500536/7542315 and was asked to post here as well. I am migrating an existing project to Swift 3 and have run into an issue where Xcode is giving errors about required inits for Realm. These inits use RLMRealm instead of Realm and require importing Realm as well.
RLMRealm initializers should not be required when using RealmSwift
Xcode error says 'required' initializer 'init(realm:schema:)' must be provided by subclass of 'Object', however these inits use RLMRealm and require importing Realm
See example here: http://stackoverflow.com/q/43500536/7542315
check http://stackoverflow.com/q/43500536/7542315
See http://stackoverflow.com/q/43500536/7542315
Realm framework version: 2.6.1
Xcode version: 8.3.2
iOS/OSX version: iOS 10.3.1
Dependency manager + version: Cocoapods 1.2.0
Those initializers are required to be implemented by Realm so that we can construct objects for you from values using APIs such as Realm.create(_:value:update:) among others.
However, you don't need to ever see those if you create "convenience" initializers such as is documented here: https://realm.io/docs/swift/latest/#adding-custom-initializers-to-object-subclasses
Copied here for your _convenience_ 馃槈
When creating your model
Objectsubclasses, you may sometimes want to add your own custom initialization methods for added convenience.Due to some present limitations with Swift introspection, these methods cannot be designated initializers for the class. Instead, they need to be marked as convenience initializers using the Swift keyword of the same name:
class MyModel: Object { dynamic var myValue = "" convenience init(myValue: String) { self.init() //Please note this says 'self' and not 'super' self.myValue = myValue } }
I answered on StackOverflow and it was accepted. I think this issue seems to be closeable. Feel free to reopen if you have further questions.
You don't need to override
init(realm:schema:)andinit(realm:schema:), just define convenience requiredinit(node:in:) throwslike the following.
class BaseModel : RealmSwift.Object, MappableBase, Identifiable {
convenience required init(node: Node, in context: Context) throws {
try self.init(node: node, in: context)
}
...
}
Most helpful comment
Those initializers are required to be implemented by Realm so that we can construct objects for you from values using APIs such as
Realm.create(_:value:update:)among others.However, you don't need to ever see those if you create "convenience" initializers such as is documented here: https://realm.io/docs/swift/latest/#adding-custom-initializers-to-object-subclasses
Copied here for your _convenience_ 馃槈