Basic data. How do I store a custom object as a convertible attribute?

I currently have a class called Place, defined like this:

class Place  {

    let name: String
    let address: String
    let coordinate: CLLocationCoordinate2D
    let type: String
    var photoReference: String?
    var photo: UIImage?

    /* functions etc */
}

      

In my data model, I have an object called FoundPlaces. It has one attribute of place

type "transformable".

I am going crazy trying to find a Swift solution to store this object. Is the data model in error?

Any guidance is appreciated. Thank!

+3


source to share


2 answers


I noticed that there is a subclass of NSValueTransformer that is required for this. It converts to and from NSData, so your instance can be saved and retrieved.



0


source


Objects stored in transitional attribute, you must implement the protocol NSCoding

( init(coder:)

and encodeWithCoder:

).



The easiest way is to inherit the class Place

from NSObject

and implement the above methods.

0


source







All Articles