しめ鯖日記

swift, iPhoneアプリ開発, ruby on rails等のTipsや入門記事書いてます

【Swift】BuildTimeAnalyzer-for-Xcodeでコンパイルが遅い原因を探ってみる

こちらのXcodeプラグインを試してみました。

github.com

インストールすると下のようなフォルダ構成になっているのでプロジェクトを立ち上げます。

f:id:llcc:20161208235748p:plain

立ち上げると以下のような画面になります。

f:id:llcc:20161209000033p:plain

ウインドウの指示通り、Other Swift Flagsにフラグを追加します。

f:id:llcc:20161209000120p:plain

フラグを追加したら、Cleanとプロジェクトのビルドを行います。

その後、先程のWindowのプロジェクト名を選択すると下のような画面になります。
どのメソッドがどの程度時間がかかったかが分かるようになりました。

f:id:llcc:20161209000429p:plain

iOS10でAutolayoutのアニメーションが効かなくなってた対策

iOS10になって、以下のようにAutolayoutのconstantを変更 & layoutIfNeededでアニメーションしてくれないという問題に遭遇しました。

constraint.constant = x
UIView.animate(withDuration: 0.1, animations: {
    self.contentView.layoutIfNeeded()
})

ひとまず直接constantとxを代入する事でアニメーションしてくれるようにはなりました。

constraint.constant = x
UIView.animate(withDuration: 0.1, animations: {
    self.contentView.frame.origin.x = x
})

Swift3.0でインスタンスのクラス名を取得する

  • 2017/10: Swift4.0でも動作確認済

Swift3.0でクラス名の取得方法が少し変わっていたのでメモ。
dynamicTypeでなくtypeという大域関数を使うようになりました。

// Swift2.0
let view = UIView()
NSStringFromClass(view.dynamicType)
// Swift3.0
let view = UIView()
NSStringFromClass(type(of: view))

NSStringFromClassを使わずにStringを使うことも可能です。

let view = UIView()
String(reflecting: type(of: view))

Apple Pay と In-App Purchase の使い分け方を調べてみた

最近Suicaが使えると話題のApple Payについてです。
Apple Payについて最近調べていたところ、アプリ内の課金にも使える事がわかりました。

しかしアプリ内課金はIn App purchaseが既にあるので、その辺りの使い分けをどうしたらいいかを調べてみました。

Apple PayとIn App Purchaseの使い分け

Getting Started with Apple Pay - Apple Developer

It is important to understand the difference between Apple Pay and In-App Purchase. In apps, use Apple Pay to sell physical goods such as groceries, clothing, and appliances. Also use Apple Pay for services such as club memberships, hotel reservations, and tickets for events. On the other hand, use In-App Purchase to sell virtual goods such as premium content for your app and subscriptions for digital content. Coming this fall, websites can use Apple Pay for physical goods purchases as well as virtual goods purchases that will not be consumed within an iOS app.

The Apple Pay Programming Guide provides details on how to use the PassKit framework to integrate Apple Pay. The In-App Purchase Programming Guide provides details on how to use the StoreKit framework to integrate In-App Purchases.

公式ドキュメントを読んだ所、アプリ内で食料品、衣服、家電製品などの物理的な商品を購入する際に使うようです。
アプリ内のプレミアム会員や機能開放などのデジタルコンテンツは今まで通りアプリ内課金を使えば良さそうです。

UITableViewCellEditingStyleでnoneを選んだ時にできる空白スペースを削除する

UITableViewCellで、削除ボタンを出さなくした時のスペースを消す方法です。

内容

UITableViewでは以下のようなメソッドを実装する事で編集中に削除ボタンを出さない事ができます。

override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
    return .none
}

しかし消すだけだと左側にスペースが残ってしまいます。

f:id:llcc:20160924131603p:plain

shouldIndentWhileEditingRowAtを実装する事でスペースを消す事ができます。

override func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
    return false
}

f:id:llcc:20160924131742p:plain