iosswiftsqlitedbaccess

Swift - SharkORM ignore and encrypt property


I'm using SharkORM to create a SQLite database but I have the following question.

How can I encrypt and ignore a property in sharkORM?

class Example: SRKObject {

    dynamic var birthdate : NSDate?
    dynamic var age : NSNumber?

}

I'm trying to calculate the age from the birthdate, and I don't want to have a column in the table for the age.

Also, my data should be secure so I want to encrypt the birthdate, how can this be implemented?

Thanks for your support.


Solution

  • It appears that I might be wrong about ignoreEntities - that's not what you need. It appears that their documentation is not updated to reflect this but what you actually need is ignoredProperties :)

    The actual Swift code you need to ignore a property on an object would look like this - I am using an example Person object to illustrate the code:

    class Person: SRKObject {
        dynamic var name : String?
        dynamic var age : NSNumber?
        dynamic var payrollNumber : NSNumber?
    
        override class func ignoredProperties() -> [Any] {
            return ["age"]
        }
    }
    

    Since I have not worked with SharkORM before, I tested the code to make sure that the above does indeed work correctly :)

    On the subject of the implementation for ignoredProperties, generally, the unit tests for a project (if they exist) are a good place to start to see how to use a certain method. But strangely enough, SharkORM does not seem to implement any tests to see if ignoredProperties works as it should. Hopefully, somebody from the development team sees this and fixes this oversight :)

    With regards to encrypting a specific property, I believe all you need to do is implement encryptedPropertiesForClass. Since the implementation will be similar to the above one for ignoredProperties, I will leave the actual implementation to you :)