I want to be able to use Realm in a iOS Swift 3.0.2 project.
For the project to compile and run.
Getting error messages at compile time:
Genre.swift:23:1: 'required' initializer 'init()' must be provided by subclass of 'Object'
Genre.swift:23:1: 'required' initializer 'init(realm:schema:)' must be provided by subclass of 'Object'
Genre.swift:23:1: 'required' initializer 'init(value:schema:)' must be provided by subclass of 'Object'
Podfile
platform :ios, '8.0'
use_frameworks!
pod 'Fabric'
pod 'Crashlytics'
pod 'RealmSwift'
target 'MyProject' do
source 'https://github.com/CocoaPods/Specs.git'
pod 'XCGLogger', '~> 4.0.0'
end
target 'MyProject Tests' do
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0.2'
end
end
end
Genre.swift
import Foundation
import RealmSwift
class Genre: Object {
// MARK: Properties
dynamic var id: Int
dynamic var name: String
init?(id: Int, name: String) {
self.id = id
self.name = name
super.init()
}
override class func primaryKey() -> String? {
return "id"
}
override class func indexedProperties() -> [String] {
return ["name"]
}
}
ProductName: Mac OS X
ProductVersion: 10.12.2
BuildVersion: 16C67
/Applications/Xcode.app/Contents/Developer
Xcode 8.2.1
Build version 8C1002
/Users/thomas/.rbenv/shims/pod
1.2.0
Realm (2.4.1)
RealmSwift (2.4.1)
/bin/bash
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)
carthage not found
(not in use here)
/usr/bin/git
git version 2.10.1 (Apple Git-78)
Hi @thomasgravina! Thanks for reaching out. I'll have someone review what you've provided and respond with a solution or follow-up questions soon. 馃樃
Hi! Thanks for reaching out to us, and sorry you're seeing this error.
To fix this error, you can set initial values on your properties, and then make your initializer a convenience initializer:
class Genre: Object {
dynamic var id: Int = 0
dynamic var name: String = ""
convenience init(id: Int, name: String) {
self.init()
self.id = id
self.name = name
}
// ...
}
Hope that helps, let us know if you have any other questions! Thanks for using Realm!
Closing due to inactivity. @thomasgravina: Please follow-up if you need additional help and we can re-open the issue.
Most helpful comment
Hi! Thanks for reaching out to us, and sorry you're seeing this error.
To fix this error, you can set initial values on your properties, and then make your initializer a convenience initializer:
Hope that helps, let us know if you have any other questions! Thanks for using Realm!