iOSアプリ開発のメモ置き場

ささたつがiOSアプリ開発で知ったObjective-Cのtipsなどを書いていく所存

2013-01-01から1年間の記事一覧

NSInteger と int の違いとは?

基本的には同じものとして考えて良い。ちなみに NSNumber はオブジェクト。 詳しくはこちら。 iphone - When to use NSInteger vs int? - Stack Overflow http://stackoverflow.com/questions/4445173/when-to-use-nsinteger-vs-int

NSArray, NSDictionary, NSNumberの省略記法

NSArray @[@"apple", @"banana", @"orange"]; NSDictionary @{@"key1":@"value1", @"key2":@"value2", @"key3":@"value3"}; NSNumber @100 @(3.14 / 2.0)

個人的なコーディング規約メモ

ドット修飾子でアクセスするのはプロパティのみにする // goodCount は profile のプロパティ user.profile.goodCount; // intValue は NSNumber クラスのメソッド [user.profile.goodCount intValue];

Block構文を使ったサンプルコード

ややこしいなー // (戻り値の型 (^)(引数))メソッド名 - (NSArray *)filter:(NSArray *)array block:(BOOL (^)(int))block { NSMutableArray *result = [NSMutableArray array]; for (NSNumber *num in array) { if (block(num.intValue)) { [result addObje…

空の配列 (NSMutableArray) を作成する

NSMutableArray *numbers = [NSMutableArray array]; 追記(4/12) 最近はこっちの方がモダンなのかな〜 iOSアプリ開発 いまさら聞けないモダンな書き方 [@[] mutableCopy]; // 空の mutable array [@{} mutableCopy]; // 空の mutable dictionary

最近気になってる便利そうなライブラリ

Blocksの活用法について - 中継地点 http://d.hatena.ne.jp/h_mori/20120303/1330791880 GTM HTTP Fetcherを利用した通信方法まとめ - プログラミングノート http://d.hatena.ne.jp/ntaku/20120115/1326620484

NSFetchedResultsController について

データを Core Data に入れて UITableView を利用するときに使うものらしい。 NSFetchedResultsController を使えば、Core Data にデータが入ったときにそのイベントを取得してビューを自動で表示したり、データを Core Data に追加したときにはビューにも自…

Objective-C のカテゴリとは?

既存のクラスにメソッドを追加できる機能。 インスタンス変数は宣言できない インスタンスメソッド、クラスメソッドは自由に書ける メソッドのモジュール化ができる

Xcode5 で作ったアプリを実機で動かすための Provisioning Profile の設定

1) Xcode > Preferences > Accounts に、Apple の審査に通ったアカウント(iPhone Developer Programに加入しているアカウント)を追加する (これのことを Provisioning Profile って言うんですかね?) 2) 右下の View Details から詳細を開いて、更新ボタ…

RestKit のマッピングメモ その2

RKObjectManager を継承した ObjectManager とか作って管理すると楽かも。 #import "ObjectManager.h" #import "Stock.h" @implementation ObjectManager - (instancetype)init { NSURL *baseURL = [NSURL URLWithString:@"https://qiita.com"]; AFHTTPClien…

RestKit のマッピングメモ

RKManagedObjectStore *managedObjectStore = [RKManagedObjectStore defaultStore]; RKEntityMapping *entityMapping = [RKEntityMapping mappingForEntityForName:@"Gist" inManagedObjectStore:managedObjectStore]; [entityMapping addAttributeMappings…

.xcdatamodeld ファイルとはいったい!?

Use Core Data ってすると生成されるみたいだなー。Core Data の保存先かな。

RestKit の Example を実行する方法

v0.20.3 を持ってきて、Edit Scheme から Executable のところから実行したいサンプルを選択する

SDWebImage を使うと画像をちょー簡単に非同期読み込みにしてくれる

#import <SDWebImage/UIImageView+WebCache.h> NSURL *userImageURL = [NSURL URLWithString:url]; // setImageWithURL が表示したい画像、placeholderImage が画像を取得してくる間での間とりあえず表示したい画像 [self.imageView setImageWithURL:userImageURL placeholderImage:[UIImage ima</sdwebimage/uiimageview+webcache.h>…

xib ファイルを UITableViewCell として使うときの Tips

普通はこう書くけど、 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } xib ファイルを使…

特定の Web ページを WebView で表示する

親クラスは UIViewController でおk :D - (void)viewDidLoad { [super viewDidLoad]; UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds]; NSURL *url = [NSURL URLWithString:@"http://sasata299.hatenablog.com"]; NSURLRequest *r…

ナビゲーションバーにタイトルを設定する

UINavigationController を使ったアプリを作るときに、表示されている NavigationBar にタイトルを表示させる方法。 self.navigationItem.title = @"タイトル";

AFNetworking で API 叩いて簡単な処理やってみた

#import <AFNetworking/AFNetworking.h> @interface ViewController () @property (nonatomic, strong) NSArray *responseData; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManag</afnetworking/afnetworking.h>…

SVProgressHUD を使ってローディングを表示する

簡単でいいね!! // 読み込み #import <SVProgressHUD/SVProgressHUD.h> // ローディングを表示する [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack]; // 閉じる [SVProgressHUD dismiss];</svprogresshud/svprogresshud.h>

NSDictionaryクラスの要素数(サイズ)を取得するにはcountメソッド

NSLog(@"size: %d", [responseObject count]);

ナビゲーション付きの初期化処理

#import "AppDelegate.h" #import "ViewController.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[U…

UITableView を使うなら実装(オーバーライド)しなきゃいけないメソッド

// 何行あるか - (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section { return [self.responseData count]; } // それぞれのセルの内容 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:…

ブレークポイントを消したいときのために知っておきたいたった一つのこと

掴んで左側のエリアにぽいっとするだけ。いちいち右クリックとかしなくておk!

StoryBoard は使わずに、ボタンをクリックしたときにラベルのテキストを変更する

#import "ViewController.h" @interface ViewController () @property (nonatomic, strong) UILabel *label; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; CGRect rect = CGRectMake(10, 10, 100, 100); self.label = […

Objective-C の @property と @synthesize ってなに?

setterとgetter(アクセッサメソッド)をコンパイルの前に生成させる。以上。 http://d.hatena.ne.jp/nakamura001/20101101/1288632739 https://gist.github.com/wneko/1358266

ボタンを追加する

- (void)viewDidLoad { [super viewDidLoad]; UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(50, 50, 100, 30); [button setTitle:@"click" forState:UIControlStateNormal]; [button addTarget:self a…

ラベルを追加する

- (void)viewDidLoad { [super viewDidLoad]; CGRect rect = CGRectMake(10, 10, 100, 100); UILabel *label = [[UILabel alloc] initWithFrame:rect]; label.text = @"start"; [self.view addSubview:label]; }

Storyboard で作った modal seque を閉じるには?

閉じたいボタンに対して、 - (IBAction)back:(UIButton *)sender { [[self presentingViewController] dismissViewControllerAnimated:YES completion:NULL]; }

SpringBoard failed to launch application with error: -3 みたいなエラーが出たときの解決方法

この辺でなおる。 Window > Organaizer > Projects > Derived Data > Delete シミュレータを一度終了する

Objective-C最初の一歩

#import "AppDelegate.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. return YES; }