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

Read only transient variables #344

Open
iwllyu opened this issue Aug 26, 2016 · 2 comments
Open

Read only transient variables #344

iwllyu opened this issue Aug 26, 2016 · 2 comments

Comments

@iwllyu
Copy link

iwllyu commented Aug 26, 2016

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?

@bofiaza
Copy link

bofiaza commented Sep 9, 2016

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.

@haashem
Copy link

haashem commented Oct 17, 2016

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

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

3 participants