In Objective c how to define custom boolean type? -


typedef signed char bool;  // bool explicitly signed @encode(bool) == "c" rather "c"  // if -funsigned-char used.  #if __has_feature(objc_bool) #define yes __objc_yes #define no  __objc_no #else #define yes ((bool)1) #define no  ((bool)0) #endif 

above how bool defined in ios. following same way trying define boolean value on off , did below.

typedef signed char onoff;  #if __has_feature(objc_bool) #define on __objc_yes #define off  __objc_no #else #define on ((onoff)1) #define off  ((onoff)0) #endif 

when type defined parameter autocompletion write 'int' instead of 'onoff'. bool type rightly writing 'bool'.

is possible create custom boolean type works bool in aspects?

for properties readability better on/off, hence trying above.

any suggestions?

edit

one quick work around use on/off in place of yes/no is

typedef yes on; typedef no off; 

but still wondering why cannot create own boolean type.

keep simple?

typedef bool onoff; #define on yes #define off no 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -