0
1

More than 1 year has passed since last update.

【SwiftUI】Pull-to-Refreshの実装

Posted at

はじめに

refreshableを使ったことがなかったので簡単なサンプルを作成してみました

サンプルアプリ

Simulator Screen Recording - iPhone 14 Pro - 2023-07-26 at 20.47.34.gif

実装

import SwiftUI

struct ContentView: View {
    @State private var items: [String] = ["サンプルセル", "サンプルセル"]
    var body: some View {
        List {
            ForEach(items, id: \.self) { item in
                Text(item)
            }
        }
        .refreshable {
            try? await Task.sleep(nanoseconds: 3 * NSEC_PER_SEC)
            items.append("サンプルセル")
        }
    }
}

おわり

Twitter的なアプリを簡単に作れますね

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1