Reputation: 1554
When implementing a getter or setter for an NSString it appears as
-(NSString *)nameOfSomething
however when you get or set a Boolean you don't us an asterisks to point to something
-(BOOL)nameOfSomething
I was wondering why you have to do this? Shouldn't the asterisks still be needed in order to point? Is there a certain reason a Boolean doesn't need one?
Thanks
Upvotes: 3
Views: 119
Reputation: 2985
It is a primitive type, just like an int. In theory, it could be an object, but it is so a very simple concept that makes it of almost no use.
Consider this analogies. (Left for primitive types, right for classes)
int : Integer (Integer from java)
BOOL : ---
--- : NSString
and so on.
If you really require an object, make a wrapper.
Upvotes: 1
Reputation: 535167
It's a good idea to learn C before trying to program iOS, because you're going to be using Objective-C, and Objective-C is C. There is a difference between a plain data type and a pointer. The asterisk has to do with pointers. (Objective-C "object" types are all pointers, but C has other types.)
The most important aspects of C needed for iOS programming are discussed here:
http://www.apeth.com/iOSBook/ch01.html
As that chapter explains, a BOOL is like an NSInteger - it's just a number, not an object.
Upvotes: 4
Reputation: 46543
BOOL
are just signed char
, you don not take its address/reference.
You directly assign to it.
If you see its definition which is as :
typedef signed char BOOL;
// BOOL is explicitly signed so @encode(BOOL) == "c" rather than "C"
// even if -funsigned-char is used.
#if __has_feature(objc_bool)
#define YES __objc_yes
#define NO __objc_no
#else
#define YES ((BOOL)1)
#define NO ((BOOL)0)
#endif
You use to see its value by %d
not %@
.
Upvotes: 0