なんとかするから、なんとかなる

エンジニア関係のことを書きます

iOS

iOS UITableView deleteRows(at:with:) was crashed

Introdution UITableView is one of the most popular UI system in iOS developer. But, sometimes this UI system make us annoying. In this time, when I try to delete the UITableViewCell from swipe or delete button, it would be crashed. So, thi…

iOS It’s difficult to animate UIView by themselves when it appeared.

Introduction This article explains its difficult to animate an UIView by themselves when it appeared. Conclusion There two solution for the problem. • Call some animation start method by UIViewController • Observe the didBecomeActive event…

iOS How to detect the instance is inheritance of some class or not.

Intoroduction This are article shows how to detect the instance is inheritance of some class or not. Solution if someInstane is SomeClass { // The Instance is inheritance of some class. } else { // Instance is not inheritance of some class.…

iOS How to detect an user interacion while animating

Introduction This article shows how to detect an user interaction while animating on UIView or UIbutton or etc. Solution Set the ".allowUserIntercation" properties in option at UIView.animate method. UIView.animate(withDuration: 1.0, delay…

iOS UITableViewCellで選択されたCellをもとに戻す

English version below. https://hopita.hatenablog.com/entry/2018/08/22/225145 はじめに 選択されたCellをもとに戻す。よくやることですが、恥ずかしながら勘違いして覚えていたので備忘録。 解決方法 override func tableView(_ tableView: UITableView,…

iOS How to deselect a cell which was tapped by user.

Introduction This article shows how to deselect an cell when user tapped it. Solution It's a easy way to do it. override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { //Change the selected background view …

iOS How to rotate a UIView in 360 degrees.

Introduction This article shows how to rotate360 degrees for UIView. First I thought of using UiView.animate method and AffineTransform the UIView. It was figured out that if I set a transform property as below view.transform = CGAffineTra…

iOS UIViewを360度回し続ける

English version below https://hopita.hatenablog.com/entry/2018/08/20/225027 はじめに UIViewは360度回し続けるのは意外と面倒だったので紹介 すぐ思いつく方法 すぐに思いつく方法はUIView.animateで、transformを設定する方法だと思います。 しかしや…

iOS LLDBでの基本的なデバッグの方法

はじめに LLDBを使っていますか? LLDBを使うと効率的なデバッグが簡単にできるようになります。 今まで再コンパイルで使っていた時間が嘘のように短くなります。 今回はそんなLLDBの使い方の基礎をまとめたいと思います。 基本的にはWWDC2018 Advanced Debu…

iOS UIView transform doesn't scale propery while transition animetion.

Sorry for my poor English skill. Introduction This article shows how to solve the problem that UIView transform doesn't scale correctly while transition animation. Transition animation make an app interactively. But, sometimes it meka deve…

iOS 画面遷移アニメーションにてUIViewで拡大して縮小したら戻らなかったときの解決方法

English version below URL https://hopita.hatenablog.com/entry/2018/08/18/160658 はじめに 画面遷移時にカスタムアニメーションを使うことはよくあります。 カスタムアニメーションを使うことで、アプリの表現の幅はかなり広げられます。 しかし、このア…

iOS UIButtonやUIViewでアニメーション中にタップイベントを検知する

English version below https://hopita.hatenablog.com/entry/2018/08/22/225953 はじめに UIViewやUIButtonでアニメーション中にタップイベントを受け取る方法です。 解決方法 UIView.animate関数のオプションに".allowUserIntercation"を追加するだけです…

iOS 特定のクラスインスタンスであるかを確認する。

English version is below https://hopita.hatenablog.com/entry/2018/08/22/230146 はじめに とあるインスタンスがあるクラスのインスタンスであるかを確認する方法です。 意外と使いたい機会が多いですが、すぐ忘れてしまいます。 解決方法 とても単純です…

iOS UIView自身で画面表示時にアニメーションすることは難しい

English version below https://hopita.hatenablog.com/entry/2018/08/22/230421 はじめに UIView自身で画面に表示されるたびにアニメーションを実行したかったのですが、方法が思いつかなくて挫折した話です。 結論 UIViewControllerからメソッド呼ぶか 画…

iOS UIButtonの画像の比率を固定して拡縮する

English Version below https://hopita.hatenablog.com/entry/2018/08/22/231143 はじめに UIButtonのサイズ変更に追随して、内部の画像サイズを変更したい場合の対処方法です。 解決方法 以下の3つのプロパティをセットすればOKです。 button.imageView?.c…

iOS UIFontで数字の等幅フォントを取得する

English version below. https://hopita.hatenablog.com/entry/2018/08/22/230929 UIFontで等幅フォントを取得する 等幅フォントとは、すべての文字で幅が等しいフォントです。 等幅でないフォントでは1 と8 の幅が全く異なります。その結果、文字が変わるご…

iOS UITextField でRetrunを押したときにキーボードを閉じる。

English version below. https://hopita.hatenablog.com/entry/2018/08/22/230826 はじめに 意外と忘れてしまうことの方法。 実はきちんとAppleの公式ドキュメントにも書かれています。 やり方 UITextFieldDelegate に適合する 対象のUITextFieldインスタン…

RxSwift ObserverとPublishObject, BehaviorSubject

はじめに 今さらながらRxSwiftを試して見ました。 Disposable Observerしている情報を保持しているオブジェクト Disposable.dispose()を呼び出すことで通知の解除が可能 複数のDiposableを一度に処理するためにDisposableBagがある ObserverとPublishObject …

iOS Carthage で"dyld: Library not loaded: Reason: image not found"の対処法

背景 Carthageで Cartfileに記述 例ではGitHub上の"YOUR_LIBRARY"というフレームワークを導入。 github "YOUR_LIBRARY" ~> 1.0 コマンドラインでコードを実行 $ carthage update --platform iOS ビルドしてみると次のエラー発生。 dyld: Library not loaded:…

iOS UITableViewのdeleteRows(at:with:)で落ちる

English version is below. https://hopita.hatenablog.com/entry/2018/08/22/230653 はじめに UITableViewを使っていて、deleteRow(at:with:) を読んだときにクラッシュする問題にぶつかりました。 その解決方法について紹介します。 問題 次のようなコード…

iOS Decodableで初期化したのに値が適用されない

背景 Decodableで構造体を初期化した際、値が代入されていなかったので、備忘録。 起きたこと 次のようなコードを書いたときに初期化時に値が入りませんでした。 json形式の値を受け取り、初期化したときに失敗しました。 struct SomeStruct: Decodable { le…

iOSでステータスバーの色を変更する

はじめに iOSのStatusBarの色を変更したいことはよくあります。 でも、やりかたをよく忘れてしまいます。 なので、まとめます。 アプリ全体での色の設定 info.plistで "View controller-based status bar appearance"にNOを設定 appDelegate.swift のdidFini…

iOSでViewControllerのライフサイクルでsuperを呼ぶべき?呼ばなくても良い?

背景 iOSの開発をしていると必ず必要となるViewController。 ViewControllerにはライフサイクルがあります。 ここまでは、普通の話ですがライフサイクル中のメソッドviewDidLoadなどで 親クラスのメソッドsuperを呼び忘れることがあります。その場合大丈夫な…

iOSで.xcodeproj/project.pbxproj ファイルを編集したときにエラーが起きた時の解決方法

背景 Gitでマージがコンフリクトすることはよくあります。 今回は xcodeproj/project.pbxproj がコンフリクトしたときに少し詰まったのでその解決方法を紹介。 起こったこと Gitで xcodeproj/project.pbxprojに手作業で修正したとき次のようなエラーがでまし…

Xcode「...nib but the view outlet was not set」というエラーが出たとき

背景 xibファイルを利用してCustomViewを作成して、ViewControllerと接続したときに遭遇した問題です。 解決方法 File's OwnerのCustomClassを設定する OutletsのViewとviewを接続する Interface Builderへ行き、~~ViewController.xibのFile's Ownerの上でCo…

JenkinsでiOSアプリをテスト後にレポートを確認する

概要 JenkinsでiOSアプリをテスト後にレポートを生成する方法 少し前に試した内容なので少し情報が古いことがあると思います。 背景 iOSアプリをテストする場合、xcodebuildをコマンドラインで実行することでテストができる。 ただし、xcodebuildで実行した…

iOSのUIColorをカラーコードで設定する

UIColorをカラーコードで指定したいときって多いですよね。どうして公式対応してもらえないのだろう。 私はいつの以下のようなExtensionで拡張しています。 extension UIColor { /// Hex表記でカラーを生成 /// /// - Parameters: /// - hex: カラーコード /…

iOS でCarthage updateでエラーが発生したときの対処法

Carthage updateをしたときに次のようなエラーが発生した際の対処法 A shell task ("YOUR_PRODUCT_PATH" CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES -list) failed with exit code 72: xcrun: error: unable to find utility "xcodebuild",…

iOSのUINavigationControllerを利用した画面遷移まとめ

UINavigationControllerを利用した、画面遷移にメソッドのまとめです。 画面を閉じる/戻る dismissViewController Modalダイアログで表示された場合に画面を閉じる popViewController UINavigationControllerで管理されている場合に画面遷移を戻る popToRooV…

自前でUITableViewCellクラスを作成する

UITableViewCellはよく使うクラスの1つだと思います。 少しiOS開発に慣れてくるとUITableViewCellをカスタマイズしたくなります。 その際の手順を簡単に紹介 UITableViewCell を継承する init(style: UITableViewCellStyle, reuseIdentifier: String?)をオ…