Skip to content

Instantly share code, notes, and snippets.

@keicoder
keicoder / snippet.m
Created December 27, 2013 12:30
objective-c : 아이클라우드 이용 가능 여부 체크 (Checking for iCloud availability)
아이클라우드 이용 가능 여부 체크 (Checking for iCloud availability)
in application:didFinishLaunchingWithOptions method
id currentToken = [[NSFileManager defaultManager] ubiquityIdentityToken];
if (currentToken) {
NSLog(@"iCloud access on with id %@", currentToken);
} else {
NSLog(@"No iCloud access");
}
@keicoder
keicoder / snippet.m
Created December 28, 2013 02:04
objective-c : Subclassing UIDocument 심플 예제
Subclassing UIDocument 심플 예제
.h
@property (strong) NSString * noteContent;
.m
//Two override points, one when read and one when write.
@keicoder
keicoder / snippet.m
Created January 2, 2014 05:27
objective-c : iCloud Setup on AppDelegate
iCloud Setup on AppDelegate
- (void)setupiCloud
{
dispatch_queue_t background_queue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
0);
dispatch_async(background_queue, ^{
@keicoder
keicoder / snippet.m
Created January 2, 2014 10:59
objective-c : 아이폰과 아이패드의 인터페이스 오리엔테이션
아이폰과 아이패드의 인터페이스 오리엔테이션
1. XCode -> View based application 생성
2. ViewController -> UIImageView 삽입
3. Resources 그룹에 임의의 이미지 삽입. 이 이미지를 UIImageView의 디폴트 이미지가 되도록 수정.
4. ViewController.m 파일의 shouldAutorotateToInterfaceOrientation: 메소드를 다음과 같이 수정.
@keicoder
keicoder / snippet.m
Created January 7, 2014 03:02
objective-c : 오브젝트와 클래스의 차이
distinction between an object and its class
//ice cream class
@interface IceCream : NSObject
@property (nonatomic, strong) NSString *flavor;
@property (nonatomic, assign) int scoops;
- (void)eatIt;
@end
@keicoder
keicoder / snippet.m
Created January 7, 2014 09:48
objective-c : 구조체
Structs
//for example :
typedef struct {
CLLocationDegrees latitude;
CLLocationDegrees longitude;
} CLLocationCoordinate2D;
@keicoder
keicoder / snippet.m
Created January 8, 2014 08:11
objective-c : Finding the Current First Responder
Finding the Current First Responder 
In iOS there is no simple call to retrieve the current first responder (without resorting to private APIs)
#import "UIResponder+FirstResponder.h"
static __weak id currentFirstResponder;
@implementation UIResponder (FirstResponder)
@keicoder
keicoder / snippet.m
Created January 8, 2014 08:21
objective-c : Directory Paths on the iPhone and iPad
Directory Paths on the iPhone and iPad
//The correct way to retrieve the path of the documents directory in iOS is, according to Apple Documentation:
NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [arrayPaths objectAtIndex:0];
//Objective-C class for the path of the documents directory
@interface Directories : NSObject {
@keicoder
keicoder / snippet.m
Created January 8, 2014 08:25
objective-c : Handy UIKit Debugging Functions
Handy UIKit Debugging Functions
//before
NSLog(@"self.bounds (%g,%g,%g,%g)"
self.bounds.origin.x,
self.bounds.origin.y,
self.bounds.size.width,
self.bounds.size.height);
//after : handy string conversions functions in UIKit
@keicoder
keicoder / snippet.m
Created January 9, 2014 04:13
objective-c : assign and copy properties
assign and copy properties
Property with ’retain (or strong)’ attribute must be of object type
so, declare a property as assign if it has a primitive value
@property (nonatomic, assign) int someNumber;
You also use assign for structs, because they aren’t objects either
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;