Skip to content

Instantly share code, notes, and snippets.

@dataxpress
Created August 26, 2014 04:46
Show Gist options
  • Save dataxpress/479c72bee9a837d039f0 to your computer and use it in GitHub Desktop.
Save dataxpress/479c72bee9a837d039f0 to your computer and use it in GitHub Desktop.
Example for returning an int from a bool
#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