Swift

【Swift】Optionalの配列からnilを取り除くにはflatMap()またはcompactMap()

mapとflatMapという便利メソッドを理解する - Qiita によると flatMap() を使うとのことだが、Swift 4 から deprecation warning になる場合があるので、その時には compactMap で置き換える。 [1, 2, 3, nil].flatMap { $0 } // → [1, 2, 3]

【iOS】frameとboundsの違いを一言で

何回聞いても忘れるので。 frame は親ビューから見た相対座標 bounds はビュー自身の座標系から見た座標 子ビューには bounds を渡す。 let child = UIView() child.frame = self.bounds

【Swift3】アプリの設定画面に遷移する

UIApplicationOpenSettingsURLString を使えばよい。 func goToAppSetting () { guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else { return } if UIApplication.shared.canOpenURL(settingsUrl) { UIApplication.shared.open(…