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

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

Swift

Swift 4.2 How to get a all values of enum

Introduction This article shows how to use "CaseIterable" protocol which introduced in Swift4.2. This protocol can provede all values of enum type. So, I do not need to implement such a property any more. Before Swift4.2 In Swift4.1 or ear…

Swift4.2 列挙型Enumで全ての要素を取得する

English version below https://hopita.hatenablog.com/entry/2019/01/02/195204 はじめに オブジェクトの状態を定義など、いろいろと便利な列挙型Enumですが、この度Swift4.2で新しい機能が追加されていました。 この記事にはSwift 4.2からの新機能、列挙型…

iOS How to solve the build error related with "CommonCrypto" on Xcode10

Introduction This article shows how to solve the build error related with "CommonCrypto" on Xcode10. After updating the Xcode to version10, I faced on the error messages as below. The CommonCrypto was imported by cocoapods in my case. Rede…

iOS Xcode10 で”CommonCrypto”のおかげでビルドエラーが出た時の対処法

English version below https://hopita.hatenablog.com/entry/2018/09/30/154646 はじめに Xcode10来ましたね。 早速アップデートしてみると次のようなエラー。 CocoaPodsとかで、モジュールをプロジェクトに組み込んでいると出会いやすいっぽいです。 Redef…

iOS How to change a language settings while debugging on the devices

Introduction This article shows how to change a language settings while debugging on the devices. This method is useful for confirming the localized String or text including line breaks. It won't need to change the language from settings a…

iOS 実機でデバッグするときに言語設定を変更する

English version is below. https://hopita.hatenablog.com/entry/2018/09/12/220856 はじめに 実機でデバッグ時に言語設定したい。 ローカライズがきちんとできているか、改行が正しくできているかなど確認するときに便利な方法です。 いちいちデバイス言語…

iOS UIPageViewControllerで"Unbalanced calls to begin/end appearance transitions for" が出たときの対処方法

English version below https://hopita.hatenablog.com/entry/2018/09/09/091925 はじめに UIPageViewControllerを早送りしたときに次のようなエラーが出ました。 Unbalanced calls to begin/end appearance transitions for そのときのコードはこんな感じで…

iOS UIPageViewController How to soleve the error message "Unbalanced calls to begin/end appearance transitions for" .

Introduction When I tried to transition some pages so rapidly. The Xcode shows an error message as below. Unbalanced calls to begin/end appearance transitions for The code is below. class MyPageViewController: UIPageViewController { var ma…

iOS How to set the Autolayout programatically

Introduction It was difficult and complexity to set the autolayout programatically when the AutoLyaout announced in iOS NSLayoutConstraint(item: button, attribute: .leading, relatedBy: .equal, toItem: self.view, attribute: .leadingMargin, …

iOS AutoLayoutをコードから設定する方法

English version below https://hopita.hatenablog.com/entry/2018/09/06/204428 はじめに AutoLayoutが発表された当初、AutoLayoutをコードから設定するのは面倒でした。 NSLayoutConstraint(item: button, attribute: .leading, relatedBy: .equal, toItem…

iOS How to copy the string to Clipboard

Solution let board = UIPasteboard.general board.string = "ABC"

iOS クリップボードへコピーする

解決方法 ものすごく簡単です。 let board = UIPasteboard.general board.string = "あいうえお"

iOS How to use the Decodable

Introdution This article show the basically usage of Decodable Protocol. What's the Decodable The Decodable give us an easy way to convert the JSON Data type to Class or Struct. Thanks for the Decoable protocol, developer could access each…

iOS Decodableの基本的な使い方

English version below https://hopita.hatenablog.com/entry/2018/09/02/110756 はじめに 今回はSwift4 で追加されたDecodableの使い方について紹介します。 Decodableとは API Requestなどで返ってくるJSONのData型を任意のクラスや構造体に変換する際に便…

iOS How to wait for the async procedure in XCTest

Introduction This article shows how to wait for an async procedure like API Request or some closure. Solution It is easy to wait an async procedure using "expectation" Sample Code let request = SomeRequest() let expect = expectation(descri…

iOS XCTestで非同期処理の完了を待つ

English version below https://hopita.hatenablog.com/entry/2018/09/01/110533 はじめに タイトル通りです。 APIRequestなどXCTestで疎通確認をした際に、非同期処理の完了を待ちたいことはよくあります。 その方法を簡単に紹介 解決方法 expectationを使…

iOS How to solve the error message about Module was not compiled for testing

Introduction This article shows how to solve the error message about “Module was not compiled for testing” on XCTest code. The module was installed by Carthage. Background When I try to do my test code on the XCTest, sometimes I would like…

iOS Carthageでモジュールを導入してXCTestで Module "なにかしらのモジュール" was not compiled for testing が出たときの対処方法

English version below https://hopita.hatenablog.com/entry/2018/08/29/202132 はじめに XCTestでユニットテストを実行し用としたときにぶつかった問題です。 Carthageでモジュールを導入し、ユニットテストでそのモジュールを使用するときに少しつまづき…

iOS ForEach構文でArrayのIndexを取得する

English version below https://hopita.hatenablog.com/entry/2018/08/27/210911 はじめに ForEach文でIndex番号が欲しいことはよくあるので、備忘録です。 解決方法 enumerated()メソッドを利用する for (index, value) in someArray.enumarated() { // な…

iOS How to get an index of array in for each sentence.

Introduction This article shows how to get an index in for each sentence. Solution Using enumarated method. You can get the index of array for (index, value) in someArray.enumarated() { // do something }

iOS How to edit a View in debug mode by LLDB Console

Introduction This article shows how to edit a view in debug mode by LLDB Console. Preparation First of all, Build an app on a simulator or device and open the [Debug View Hierarchy] In this article, I'll show you how to change an informati…

iOS UIViewControllerでバックグラウンドへの遷移を検知する

English version below. https://hopita.hatenablog.com/entry/2018/08/25/201940 はじめに UIViewControllerにおいて、アプリがバックグラウンドなったときやバックグラウンドに戻ってきたときに処理を行いことはよくあります。 今回はそのやり方を紹介した…

iOS How to detect the background transition in UIViewController

Introduction This article shows hot to detect an entering background and activating from background in UIViewController. Solution As you know, UIViewController doesn't have a delegate which is called when it will go background and come bac…

iOS LLDBでViewを操作するTips

English version below https://hopita.hatenablog.com/entry/2018/08/25/203726 はじめに 今回はデバッグ中にLLDBでViewを操作するために役立つTipsを紹介します。 準備 デバッグを開始して、[Debug View Hierarchy]を開いておきます。 今回はUILabelの情報…

iOS How to solve the black screen when a modal view was dismissed with custom animation.

Introduction This article shows how to solve the black screen when a modal view was dismissed with custom animation. When I tried to set an present and modal animation when a modal view was appeared and disappeared. Though the present anim…

iOS UIViewControllerのPresentに対してカスタムアニメーションをつけたらブラックアウトしたときの対処法

English Version below https://hopita.hatenablog.com/entry/2018/08/23/212747 はじめに UIViewControllerのモーダル表示presentメソッドに独自アニメーションをつけたら、dismiss時に画面が黒くなった(ブラックアウトした)ときの対処方法です。 UIViewC…

iOS How to scale an image in UIButton.

Introduction This article shows how to scale an image in UIButton. When UIButton will be a large scale or small scale by Autolayout engine, an image it was contained in the UIButton is not correspond to the scale normally. This article wil…

iOS How to get a monospace font for digits in UIFont.

Intoduction This article shows how to set a monospace font for digits. A monospace font has same width in each character. Sometimes, a font which isn't monospace make the design baddly. Solution To get the monospace font for digits, Apple …

iOS UITextField How to dismiss the keyboard when user tap a retrun key.

Introduction This article show you that how to dismiss the keyboard when user tap a return key on UITextField of iOS. In fact, this way shows on the iOS SDK document. I've never knew it. Solution Adapt the UITextFieldDelegate on your ViewC…

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…