Question

Instead of synthesising my getter/setter I need to define the behaviour of the getter myself.

Doing this, I get a warning telling me I also need to define the setter but I was worried doing this was KVC compliant :

- (void) setPath:(NSString *)path {
    _path = path;
}

Or do I need to use setValue:ForKey: ?

Was it helpful?

Solution

Yes, the setter you've posted is KVC/KVO compliant.

That said, why do you have to define both? Is it because the @property declaration specifies atomic? Assuming that's the case, you should switch to nonatomic. You could make your own accessors atomic, but that's a significant amount of extra work, and unless you have a good, well understood reason for using an atomic property, you probably don't need to.

OTHER TIPS

If you want to override just the getter, you still can (and should) use @synthesize let the compiler auto-sythesize for you. That will synthesize the methods you do not override (in your case, the setter).

Your setter is KVC compliant; it's just unnecessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top