Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible? or how do I use a Decodable object with SQLTable? #62

Closed
waelsaad opened this issue Oct 1, 2019 · 2 comments
Closed

Comments

@waelsaad
Copy link

waelsaad commented Oct 1, 2019

Hi,

I like this wrapper it is very simple and lightweight but I am wondering about the following:

I have the follwong decodable object so how can I use SQLTable with it? or do I need to create a seperate model for SQLTable?:-

struct Chapter: Decodable {
let chapter: Int
}

Thanks

Wael

@FahimF
Copy link
Owner

FahimF commented Oct 2, 2019

You'd need to make your Chapter class a sub-class of SQLTable - refer to the example project to see how this works. Then you can inherit the functionality provided in SQLTable.

@FahimF FahimF closed this as completed Oct 2, 2019
@TeksniOS
Copy link

TeksniOS commented Apr 15, 2020

I have the same question. I have multiple columns and created a model class for JSON response. I wish to store all these data to SQLite using SQLTable.

For example, Here is my model class:

import SwiftyJSON

class TripData{

	var avgSpeed : Int!
	var createdAt : Int!
	var deviceUuid : String!
	var distancekm : Int!
	var distractions : Int!

init(fromJson json: JSON!){
		if json.isEmpty{
			return
		}
		avgSpeed = json["avg_speed"].intValue
		createdAt = json["createdAt"].intValue
		deviceUuid = json["device_uuid"].stringValue
		distancekm = json["distancekm"].intValue
		distractions = json["distractions"].intValue
}
}

As you said, I have tried to make my TripData class a sub-class of SQLTable (class TripData : SQLTable) but it throws this warning,

'required' initializer 'init()' must be provided by subclass of 'SQLTable'

I don't understand how to use the same class as SQLTable also. Could anyone of you help me please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants