Objective-cのヘッダーファイルでtypoした話
今後絶対にやってはいけない・・・
メソッドをヘッダーファイルに定義して、外部から読み出しを行っていましたが、
エラーで「Signal SIGABRT」が出てしまいました。
原因は
- ヘッダーファイルで大文字始まり
- メインファイルで小文字始まり
これってエラーにはならないんですね。
外部から読み込む分にはビルドエラーにはならずに、実行時にプロセス中断エラーになります。
なぜだろうかと結構悩んでしまったので、残しておきます。
objective-c と swift のメモ書き
最近両方修正しているのでメモを
- objective-cを書ける人ならだいたい似たような感じでswiftかける気がします
- 技術者としてはobjective-cの人が多い気がします
- objective-cをswiftに置き換える技術は多い気がします
- 現状swiftに置き換えるより、まずリファクタリング作業をする多いです
- Xcode9で ExtractMethod が実装されたりとリファクタリング作業がだいぶ楽になりました
お世話になっている作業用BGMサイト達
iOS端末情報リンクとメモ
wikipediaが充実しています。
端末の情報としてはほぼ十分では無いでしょうか。
iPhone - Wikipedia
早見表を作成されている方も。
風邪に関するメモ書き
ちょっと風邪ひいたので自分自身への注意も兼ねてメモ書きを残します。
風邪をひく場合
- 山登りなど体力を消耗しすぎた時
- 寝不足
- 栄養不足
風邪をひいた時の注意点
- 集中力が落ちる
- 注意力も落ちる
- 風邪に気づけない
- 風邪をひいた時のお前の判断は大体間違っている
定期的にやること
- 体温を毎日計測する
- 体を冷やさない
- 人混みではマスクを使用する
今回は山に登って体力消費したのに食べ過ぎで胃腸にも負担をかけたのが原因っぽいですね・・・
swift改行について
他の人が書いたソースコード読んで、ちょっと混乱したのでメモ
swiftは行終わりに ; を書かなくてもよい、であって書く事もできます。
なので
var strA:String = "strA"; var strB:String = "strB";
という形に一行で複数の変数宣言も可能です。
私はswiftでこの書き方はしませんが、良い使いかたもあるのかも知れませんね。
UIAlertControllerを使ってみる
とりあえず画面にボタンを追加します
ボタン押下時にUIAlertControllerを表示するよう変更
@IBAction func btnClick(_ sender: UIButton) { let ac = UIAlertController(title:"Title", message: "Message", preferredStyle: UIAlertControllerStyle.alert) let aDef = UIAlertAction(title: "default", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction!) in print("Default!") }) let aDes = UIAlertAction(title: "destructive", style: UIAlertActionStyle.destructive, handler: { (action: UIAlertAction!) in print("Default!") }) let aCan = UIAlertAction(title: "cancel", style: UIAlertActionStyle.cancel, handler: { (action: UIAlertAction!) in print("Cancel!") }) ac.addAction(aDef) ac.addAction(aDes) ac.addAction(aCan) self.present(ac, animated: true, completion:popoverPresentationController) }
表示できました。
addActionを2つに減らすと表示されるボタンのスタイルが少し変わります。
できました。
下からの表示に変更します。
UIAlertControllerStyle.alert を UIAlertControllerStyle.actionSheet に変更すれば下からの表示になります。
@IBAction func btnClick(_ sender: UIButton) { let ac = UIAlertController(title:"Title", message: "Message", preferredStyle: UIAlertControllerStyle.actionSheet) let aDef = UIAlertAction(title: "default", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction!) in print("Default!") }) let aDes = UIAlertAction(title: "destructive", style: UIAlertActionStyle.destructive, handler: { (action: UIAlertAction!) in print("Default!") }) let aCan = UIAlertAction(title: "cancel", style: UIAlertActionStyle.cancel, handler: { (action: UIAlertAction!) in print("Cancel!") }) ac.addAction(aDef) ac.addAction(aDes) ac.addAction(aCan) self.present(ac, animated: true, completion:nil) }
できました。
popoverで表示してみます。
UIAlertControllerStyle を actionSheet に変更すると popoverPresentationController の設定を使用できます。
iPhoneだと動作を確認できないので、iPadで実行します。
@IBAction func btnClick(_ sender: UIButton) { let ac = UIAlertController(title:"Title", message: "Message", preferredStyle: UIAlertControllerStyle.actionSheet) let aDef = UIAlertAction(title: "default", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction!) in print("Default!") }) let aDes = UIAlertAction(title: "destructive", style: UIAlertActionStyle.destructive, handler: { (action: UIAlertAction!) in print("Default!") }) let aCan = UIAlertAction(title: "cancel", style: UIAlertActionStyle.cancel, handler: { (action: UIAlertAction!) in print("Cancel!") }) ac.addAction(aDef) ac.addAction(aDes) ac.addAction(aCan) ac.popoverPresentationController?.sourceView = self.view ac.popoverPresentationController?.sourceRect = btn.frame self.present(ac, animated: true, completion:nil) }
sourceRect に吹き出しを指したい位置を指定します。