@property setter for BOOL

I'm having trouble setting up BOOL using @propertyand @synthesize. I use @property BOOL isPaused;And I can get it using [myObject isPaused];, but I can not install it. I would like to use [myObject setPaused: NO];. I also tried @property (setter=setPaused) BOOL isPaused;, but if I'm not mistaken, then I need to write this setter myself.

+3
source share
1 answer

Why not use dot notation?

myObject.isPaused = YES;
return myObject.isPaused;

If your property is declared as @property BOOL isPaused, then the installer is always called as

[myObject setIsPaused:YES];

To rename a setter, you must provide a full signature, including colons:

@property(setter=setPaused:) BOOL isPaused;
...
[myObject setPaused:YES];

BTW, the naming convention does not include verbs in a property.

@property(getter=isPaused) BOOL paused;
+6

Source: https://habr.com/ru/post/1746732/


All Articles