I have a class ViewController.m
where I want to set a property of my other class Singleton.m
which should automatically be saved to the NSUserDefaults
.
I think I have to make the property in Singleton.m
readonly and override the setter, but is this the best way? If yes, how do I do that?
Making the property read-only does not make much sense (if I understand your problem correctly). What you probably want is:
init
method to load the property from the user defaults when the singleton is instantiated,Example: Singleton.h:
Singleton.m:
(Note that both
will call the custom setter method
setMyBoolProp
.)