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

Use structs to represent parsing keys #114

Open
khaledannajar opened this issue Jun 23, 2018 · 0 comments
Open

Use structs to represent parsing keys #114

khaledannajar opened this issue Jun 23, 2018 · 0 comments

Comments

@khaledannajar
Copy link

I found this feature here in another tool which is putting the parsing keys in a struct for reuse preventing duplication in the keys.
EX.
`private struct SerializationKeys {

static let Id = "Id"

static let timeRange = "timeRange"

}`

This is to be used like this:
`init(fromDictionary dictionary: [String:Any]){

    Id = dictionary[SerializationKeys.Id] as? Int

    if let timeRangeData = dictionary[SerializationKeys.timeRange] as? [String:Any]{

        timeRange = TimeRange(fromDictionary: timeRangeData)

    }

}`

and like this:
`func toDictionary() -> [String:Any]
{
var dictionary = String:Any

    if Id != nil{

        dictionary[SerializationKeys.Id] = Id

    }

    if timeRange != nil{

        dictionary[SerializationKeys.timeRange] = timeRange.toDictionary()

    }

    return dictionary

}`
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

1 participant