Open daraujofs opened 6 years ago
Hi,
I've just tested the principal and it all works fine.
Definition:
@objc class Country: SRKObject, Decodable {
@objc dynamic var name: String?
@objc dynamic var code: String?
private enum CodingKeys: String, CodingKey {
case name
case code = "alpha2Code"
}
}
Activity:
let c = Country()
c.name = "Great Britain"
c.code = "GB"
c.commit()
If the database is completely empty then it may be that the ORM has not started properly. The most common problem is that you need to set the delegate before opening the file.
I just followed the "Setting up your project" tutorial from GitHub. Firstly, I created the Country class inside the ViewController (just testing the library). I opened the db file and some tables was created, including Country table with a large name. Tried to insert data from an API (2500 entries) and the sequencial works, but name and code are always empty.
After that, I separated Country class from ViewController, renamed the database filename in delegate. The db file is created but whitout any tables.
AppDelegate:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
SharkORM.setDelegate(self)
SharkORM.openDatabaseNamed("countries")
return true
}
ViewController:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let country = Country()
country.name = "Brasil"
country.code = "BR"
country.commit()
}
Country
class Country: SRKObject, Decodable {
@objc dynamic var name: String?
@objc dynamic var code: String?
private enum CodingKeys: String, CodingKey {
case name
case code = "alpha2Code"
}
}
Okay, I will try to recreate that here.
Ok, thanks.
Hello!
I'm trying to use SharkORM. I have followed the tutorial, but the .db file is empty.
I'm using objects with SRKObject and Swift 4 Decodable. I have tried to use only SRKObject too and I got the same error.
Country.class `class Country: SRKObject, Decodable { @objc dynamic var name: String? @objc dynamic var code: String?
}`