Kentaro Kuribayashi's blog

Software Engineering, Management, Books, and Daily Journal.

iOS SDK Development勉強会 #2

今日は第2章。Twitterに投稿するだけのアプリを、webviewを使って表示もできるように。

iOS SDK Development

iOS SDK Development

勉強会のやりかたとしては、

  • できるだけその場でコードを書きながらやる
  • きれいな資料とか作るとだるいので、以下のようなメモ書きだけで、あとは本のPDFを表示しながらその場で説明
  • 細かいところは話さない。あとで読んだらいい。

というわけで、以下、メモ書き。

Introducing Objective-C

本見ながら説明。ざっくりと。

  • クラスの宣言
  • 継承
  • メソッド

とか。

ARC

  • objcのメモリ管理はリファレンスカウント
  • iOS5からARCがデフォルト

- 実は4.3から使えるけどweak修飾子がなかったりする

  • いい感じにretainしたりreleaseしたりする
  • CレベルのAPI使う場合はあれこれする必要があるよ(ここでは詳しくは立ち入らない)

アプリを改良しよう

Our original app lets us send a tweet, but there’s no way to tell if we were successful. We’ll gradually improve that throughout this chapter and the next. For starters, let’s use iOS’s built- in web browser to bring up our Twitter page inside the app

  • buttonとwebviewをドラドロではる
  • 自分のtwitterのページがみえるように

property

  • インスタンス変数を直接宣言するのはこの本ではやんない
  • property使おう
  • storyboardで、viewからヘッダファイルにビッってできる
@property (nonatomic, weak) IBOutlet UIWebView *twitterWebView;
  • readwrite/readonly
  • atmic/nonatmic
    • nonatmicにしとけ

For any UIKit property, we can always set nonatomic, because UIKit methods and properties should only ever be accessed from the main thread, the one that started the app. With that convention, there’s no point enforcing thread safety in the property: there should never be two threads attempting to set the property, since main is the only one that should access it at all.

  • assign/retain/copy
  • strong/weak
    • 循環参照すると困る時にweak
    • weakはzeroingしてくれるからdangling pointerにmessage送って死んだりしない

ほんでもって@synthesize書くよー(Xcode4.4からはいらない)。

f:id:antipop:20120911093801j:plain
f:id:antipop:20120911093812j:plain

Xcode4.4での変更点

webviewで自分のツイートページを表示

ViewControllerにハンドラ追加:

- (IBAction) handleShowMyTweetsTapped: (id) sender {
    [self.twitterWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.twitter.com/kentaro"]]];
}
  • Show My Tweetボタンと、このハンドラをひもづける
  • ピってやる

なんかいろいろ細かい話

本見ながら。

国際化

  • language
  • time and date formatting
  • currency symbols and separators
  • ロケール追加
  • Xcode4.4からは、Infoタブのとこで追加する(本の説明と違う)
  • 日本語でやってみよう