mogenerator icon indicating copy to clipboard operation
mogenerator copied to clipboard

Read only transient variables

Open iwllyu opened this issue 8 years ago • 2 comments

Expected Behavior

I saw this SO on how to implement a transient core data property in swift http://stackoverflow.com/a/36162207/1552116

Actual Behavior

The machine generated file generates this for transient properties

    @NSManaged public
    var saved_date_section_title: String?

When I go to override it in the human file like so

    override public var saved_date_section_title: String? {
        get{
            return savedDate?.getStorageString()
        }
    }

it gives the errors

Cannot override mutable property with read-only property 'saved_date_section_title'

Getter for 'saved_date_section_title' with Objective-C selector 'saved_date_section_title' conflicts with getter for 'saved_date_section_title' from superclass '_CachedOfferImpl' with the same Objective-C selector

I can implement it like so

    override public var saved_date_section_title: String? {
        get{
            return savedDate?.getStorageString()
        }
        set {
            //noop
        }
    }

but surely that's a code smell

Question

So what's the proper way for implementing a transient property using mogenerator?

iwllyu avatar Aug 26 '16 14:08 iwllyu

I think making the custom setter empty is the correct way. Effectively, anything passed to the var is ignored. Also, you can't provide a custom getter without providing the custom setter.

bofiaza avatar Sep 09 '16 17:09 bofiaza

what you need to do is use mogenerator mogenerator.readonly key-value runtime attribute with value YES . https://github.com/rentzsch/mogenerator/wiki/Core-Data-User-Info-Keys

haashem avatar Oct 17 '16 15:10 haashem