Created
August 26, 2014 04:46
-
-
Save dataxpress/479c72bee9a837d039f0 to your computer and use it in GitHub Desktop.
Example for returning an int from a bool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface SomeClass : NSObject | |
-(BOOL)arrayHasStuff; | |
-(BOOL)otherArrayHasStuff; | |
@property (nonatomic, retain) NSArray *array; | |
@property (nonatomic, retain) NSArray *otherArray; | |
@end | |
@implementation SomeClass | |
-(id)init{ | |
if(self = [super init]) | |
{ | |
_array = @[@"a",@"b",@"c"]; | |
_otherArray = @[@"d",@"e",@"f",@"g"]; | |
} | |
return self; | |
} | |
-(BOOL)arrayHasStuff | |
{ | |
return self.array.count; | |
} | |
-(BOOL)otherArrayHasStuff | |
{ | |
return self.otherArray.count; | |
} | |
@end | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
SomeClass *x = [[SomeClass alloc] init]; | |
if([x arrayHasStuff]) | |
{ | |
NSLog(@"Array has stuff"); // prints | |
} | |
if([x otherArrayHasStuff]) | |
{ | |
NSLog(@"Other Array has stuff"); // prints | |
} | |
if([x arrayHasStuff] == [x otherArrayHasStuff]) | |
{ | |
NSLog(@"Both arrays have the same state of havingness"); // does not print | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment