This file contains hidden or 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
[[UIScreen mainScreen] setBrightness:0.5]; |
This file contains hidden or 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
sed 's/$/ \\/' payload.txt > result.txt |
This file contains hidden or 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
/* iOS 5 has a new framework to look for a word definition and present the definition. | |
* | |
* UIReferenceLibraryViewController is a subclas of UIViewController, so you can push | |
* or present it as modal view controller to see the definition. | |
*/ | |
NSString *term = @"Reference"; | |
if ([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:term]) { | |
NSLog(@"Term: %@, has definition", term); |
This file contains hidden or 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
Basically, UIPasteBoard allows us to share data to other application. Below is an example of UIpasteBoard usage. | |
COPY | |
UIPasteboard *appPasteBoard = [UIPasteboard generalPasteboard]; | |
appPasteBoard.persistent = YES; | |
[appPasteBoard setString:@"STRING TO COPY"]; | |
PASTE |
This file contains hidden or 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
This example below list down all files inside the application resource. | |
NSString *documentsDirectory = [[NSBundle mainBundle] resourcePath]; | |
NSError *err; | |
NSArray *directoryContentArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:&err]; | |
NSLog(@"%@", directoryContentArray); | |
This file contains hidden or 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
From Apple. | |
An application that wants to make files accessible to the user can do so through the file sharing feature. File sharing exposes the contents of an application’s Documents directory in iTunes. Exposing this directory allows the user to add files to it or delete files from it. To enable file sharing for your application, do the following: | |
Add the UIFileSharingEnabled key to your application’s Info.plist file and set the value of the key to YES. | |
Put whatever files you want to share in your application’s Documents directory. | |
When the device is plugged into the user’s computer, iTunes displays a File Sharing section in the Apps pane of the selected device. The user can add files to this directory or move files to the desktop. |
This file contains hidden or 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
This is useful so that before you process any URL request from a URL String, this URL String becomeURL encoded and gets replaced to percent escapes. | |
iOS 5: iOS 5 requires A Toll-Free Bridging | |
- (NSString *)escape:(NSString *)text | |
{ | |
return CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes( NULL, (__bridge CFStringRef)text, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding))); | |
} | |
Previous iOS: |
This file contains hidden or 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)searchString:(NSString *)str inArray:(NSArray *)arr{ | |
for (id key in arr) { | |
//check if there is a matching string (key and str) | |
if ([key rangeOfString:str options:NSCaseInsensitiveSearch].location != NSNotFound) { | |
NSLog(@"String: %@ Found", key); | |
} | |
} | |
} | |
This file contains hidden or 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
Getting a reference to your application’s temporary directory is even easier than getting a reference to the Documents directory. The Foundation function called NSTemporaryDirectory() will return a string containing the full path to your application’s temporary directory. To create a filename for a file that will get stored in the temporary directory, we first find the temporary directory: | |
NSString *tempPath = NSTemporaryDirectory(); | |
Then, we create a path to a file in that directory by appending a filename to that path, like this: | |
NSString *tempFile = [tempPath stringByAppendingPathComponent:@”tempFile.txt”]; |
This file contains hidden or 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
(UIImage *)addImage:(UIImage *)image1 toImage:(UIImage *)image2 { | |
UIGraphicsBeginImageContext(image1.size); | |
// Draw image1 | |
[image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)]; | |
// Draw image2 | |
[image2 drawInRect:CGRectMake(0, 0, image2.size.width, image2.size.height)]; | |
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); |