kwigbo

Adventures in iOS!

Posts tagged snippet

1 note &

Check if Current Device is iPad

This is a simple method I use in all my apps to easily tell if the current device is iPad. I add the import for this class to the Prefix.pch file so I can easily check what device I am on without having to import.

//Device.h
@interface Device : NSObject 
{
}
+ (BOOL) isPad;
@end
 
//Device.m
#import "Device.h"
 
@implementation Device
+ (BOOL) isPad
{
#ifdef UI_USER_INTERFACE_IDIOM
	return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
#endif
	return NO;
}
@end

Filed under snippet

1 note &

Check if NSString Contains a Sub String

This is a simple category that allows you to see if an instance of NSString contains a specific sub string.

@interface NSString (SubString)
- (BOOL) hasSubString:(NSString *) str;
@end
 
@implementation NSString (SubString)
- (BOOL) hasSubString:(NSString *) str
{
	return [self rangeOfString:str].location != NSNotFound;
}
@end

Filed under snippet