iOS App Dev Tutorials: UIKit essentials

https://developer.apple.com/tutorials/app-dev-training/creating-a-list-view

SwiftUIのチュートリアルは去年の終わりくらいにやって、Flutterに似てとっつきやすいと思っていましたが、 まだまだUIKitの出番が多いとのことで学習することにしました。

チュートリアルをこなす上でつまづいたところや気づきがあったところをメモしております。

Section 1

UIKitのチュートリアルなので、まずはinterfaceでstoryboardを選ばないといけません。

ですが、最初interfaceが選べずそのままnextしたら、SwiftUIになってしまいました。

interfaceが選べない

でも、後でやり直したら、storyboardが選べるようになってました。何が違うんだ?

storyboard見えた

Section 2

ここで若干つまづいたのは、collection view controllerを追加するところです。

そもそもLibrary iconはどこにあるんだ?から始まりましたが、ググるとShift + command + Lで開くことがわかりました。

でも検索結果に何も出ない。

検索結果に何も出ない

で、少ししてstoryboardファイルが選択している時じゃないと検索できないことに気づきました。

その他、このChapterで気づいたところ

DEBUG blockってのが便利そう

import Foundation

struct Reminder {
    var title: String
    var dueDate: Date
    var notes: String? = nil
    var isComplete: Bool = false
}

#if DEBUG
extension Reminder {
    static var sampleData = [
        Reminder(title: "Submit reimbursement report", dueDate: Date().addingTimeInterval(800.0), notes: "Don't forget about taxi receipts"),
        Reminder(title: "Code review", dueDate: Date().addingTimeInterval(14000.0), notes: "Check tech specs in shared folder", isComplete: true),
        Reminder(title: "Pick up new contacts", dueDate: Date().addingTimeInterval(24000.0), notes: "Optometrist closes at 6:00PM"),
        Reminder(title: "Add notes to retrospective", dueDate: Date().addingTimeInterval(3200.0), notes: "Collaborate with project manager", isComplete: true),
        Reminder(title: "Interview new project manager candidate", dueDate: Date().addingTimeInterval(60000.0), notes: "Review portfolio"),
        Reminder(title: "Mock up onboarding experience", dueDate: Date().addingTimeInterval(72000.0), notes: "Think different"),
        Reminder(title: "Review usage analytics", dueDate: Date().addingTimeInterval(83000.0), notes: "Discuss trends with management"),
        Reminder(title: "Confirm group reservation", dueDate: Date().addingTimeInterval(92500.0), notes: "Ask about space heaters"),
        Reminder(title: "Add beta testers to TestFlight", dueDate: Date().addingTimeInterval(101000.0),  notes: "v0.9 out on Friday")
    ]
}
#endif

こんなコードが出てくるんですが、構造体を宣言して、その下でテスト用のデータを設定しています。

やりすぎるとコードが見辛くなると思うんですが、自分は、テストデータを実際のコードの近くに置いておけるのは便利だと思いました。

離れた位置にあると探すのが面倒になるので。