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
dispatch_queue_t img_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | |
dispatch_async(img_queue, ^{ | |
NSURL *url = [NSURL URLWithString:@"http://imgs.xkcd.com/comics/formal_logic.png"]; | |
NSError *error = nil; | |
NSData *image = [NSData dataWithContentsOfURL:url options:0 error:&error]; | |
if(!error && image && [image length] > 0) { | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); | |
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"image.png"]; |
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
Ordering from a food cart is a lot like working with an NSNotification. You walk up to the counter, place your order, get a number, and wait for your number to be called. You usually stand around with five other people who are waiting for their number to be called, too. And when the chef is finished preparing your meal, the person behind the counter calls your number, and you sit down to eat. With NSNotification, you become an observer for "your number," and when the object posting the notification is done "making your food," NSNotificationCenter calls your number so you can come get your "food". In this tutorial, instead of waiting for food, we're going to wait for the device to rotate and then send the current orientation to the observer. We'll talk about how to register to receive a notification, post a notification, and pass a string object along with the notification using userInfo. | |
Set Up Your Project | |
Launch Xcode and click File > New > Project. Select an iOS Single View Application and click "Next". |
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
// Create a path to a directory, and make sure it exists. | |
// The iOS documentation will tell you that URLs are preferred, but there is no createDirectory method for | |
// URLs. So we have to use string paths instead. | |
// Create a sub-directory in the application's Documents directory. Return the path on success, or nil on failure. | |
- (void)createDocumentSubdirectory:(NSString*)dirName { | |
NSString *retval = nil; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *dirPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:dirName]; | |
NSFileManager *fm = [[NSFileManager alloc] init]; |
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
// GCC Attribute for autoscoped Obj-C objects | |
// Source: http://www.cocoabuilder.com/archive/message/cocoa/2009/3/13/232287 | |
#define autoscoped __attribute__((cleanup(releaseObject))) | |
static inline void releaseObject(id *object) | |
{ | |
[*object 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
- (void)test | |
{ | |
int foo = 1; | |
void (^block)() = ^() { | |
NSLog(@"%d at %p", foo, &foo); //=> 1 at 0xbfffd65c / エンクロージャの変数fooは参照できる. | |
// 以下は 'Variable is not assignable' コンパイルエラー | |
// foo = 2; | |
}; | |
block(); | |
NSLog(@"%d at %p", foo, &foo); //=> 1 at 0xbfffd6ac / block内のfooとはアドレスが違う. |
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
<!-- Mobile meta & links --> | |
<!-- Reference | |
Custom Icon and Image Creation Guidelines: | |
http://developer.apple.com/library/safari/#documentation/UserExperience/Conceptual/MobileHIG/IconsImages/IconsImages.html | |
Configuring Web Applications: | |
http://developer.apple.com/library/safari/#documentation/appleapplications/reference/safariwebcontent/configuringwebapplications/configuringwebapplications.html |
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
/* | |
* Normalized hide address bar for iOS & Android | |
* (c) Scott Jehl, scottjehl.com | |
* MIT License | |
*/ | |
(function( win ){ | |
var doc = win.document; | |
// If there's a hash, or addEventListener is undefined, stop here | |
if( !location.hash && win.addEventListener ){ |
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
// Original code from http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/ | |
var metas = document.getElementsByTagName('meta'); | |
var i; | |
if (navigator.userAgent.match(/iPhone/i)) { | |
for (i=0; i<metas.length; i++) { | |
if (metas[i].name == "viewport") { | |
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0"; | |
} | |
} |
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
// Original code from http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/ | |
var metas = document.getElementsByTagName('meta'); | |
var i; | |
if (navigator.userAgent.match(/iPhone/i)) { | |
for (i=0; i<metas.length; i++) { | |
if (metas[i].name == "viewport") { | |
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0"; | |
} | |
} |
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
@interface UntitledViewController : UIViewController <UIScrollViewDelegate> | |
{ | |
@private | |
UIScrollView *_scrollView; | |
NSArray *_objects; | |
int refPage, currentPage; | |
UILabel *_detailLabel1; | |
UILabel *_detailLabel2; | |
UILabel *_detailLabel3; |