Run function on value change Swift Core Data

Discussion in 'iOS Programming' started by semaja2, Jun 2, 2015.

  1. semaja2, Jun 2, 2015
    Last edited by a moderator: Jun 2, 2015

    semaja2 macrumors 6502a

    Joined:
    Dec 12, 2005
    Location:
    Adelaide
    #1
    Hi Guys,

    I am trying to learn Core Data using Swift, however I am lost at how to implement some more technical features.

    Specifically I would like to have a function run before data is saved to the database, for example this could be used to verify or format the data before being saved.

    On a normal class object I can use the below code

    Code:
    var lastAccuracyString: String {
            get {
                if (monitoring) {
                    return NSString(format:"%.2f meters", lastAccuracy) as String
                } else {
                    return "Unmonitored"
                }
            }
        }
    What is the best way to extend the NSManagedObject class
     

Share This Page