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> | |
#import <objc/runtime.h> | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSString *temp = @"world"; | |
int (^impyBlock)(id, int, int) = ^(id _self, int a, int b) |
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> | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSString *text1 = @"String number 1."; | |
NSString *text2 = [NSString stringWithFormat:@"String number %i.", 1]; | |
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
+ (NSString *)mobileprovision | |
{ | |
#if TARGET_IPHONE_SIMULATOR | |
return nil; | |
#endif | |
NSString *result = nil; | |
NSString *profilePath = [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"]; |
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
+ (BOOL)webFileExists:(NSURL *)url | |
{ | |
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]; | |
[request setHTTPMethod:@"HEAD"]; | |
NSHTTPURLResponse* response = nil; | |
NSError* error = nil; | |
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; | |
NSLog(@"Response length: %i", [data length]); | |
NSInteger code = [response statusCode]; | |
[request release]; |
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> | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSDictionary *attributes = @{ @"first": @"first value", | |
@"second" : @3.14, | |
@"third" : @[ @"one", @"two", @4, @5, @YES, @NO] }; |
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> | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
NSData *data = [NSData dataWithContentsOfFile:@"json_file.json"]; | |
NSError *error = nil; | |
id json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error]; |
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 Person : NSObject | |
@property (copy) NSString *firstName; | |
@property (copy) NSString *lastName; | |
- (instancetype)initWithFirstName:(NSString *)firstName andLastName:(NSString *)lastName; | |
@end |
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
+ (void)decompressImage:(UIImage *)image | |
{ | |
if ( image ) { | |
UIGraphicsBeginImageContext(CGSizeMake(1, 1)); | |
[image drawAtPoint:CGPointZero]; | |
UIGraphicsEndImageContext(); | |
} | |
} |
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
- (BOOL)isPhoneValid:(NSString *)phone | |
{ | |
NSCharacterSet *phoneSet = [NSCharacterSet characterSetWithCharactersInString:@"-+0123456789()"]; | |
return [[phone stringByTrimmingCharactersInSet:phoneSet] isEqualToString:@""]; | |
} | |
- (BOOL)isPhoneNumberValid:(NSString *)phone | |
{ | |
NSError *error; | |
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypePhoneNumber error:&error]; |
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
- (NSString *)reverse:(NSString *)source { | |
if (!source) { | |
return nil; | |
} | |
NSMutableString *reversed = [NSMutableString new]; | |
[source enumerateSubstringsInRange:NSMakeRange(0, [source length]) options:NSStringEnumerationReverse | NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | |
[reversed appendString:substring]; | |
}]; | |
OlderNewer