1
anonymous No title
Swift
struct TableViewConfigurator: UIViewControllerRepresentable {

    var configure: (UITableView) -> Void = { _ in }

    func makeUIViewController(context: UIViewControllerRepresentableContext<TableViewConfigurator>) -> UIViewController {

        UIViewController()
    }

    func updateUIViewController(_ uiViewController: UIViewController, context: UIViewControllerRepresentableContext<TableViewConfigurator>) {
        DispatchQueue.main.async {
            let tableViews = ViewRetriever.retrieve(parentView: uiViewController.navigationController?.topViewController?.view, inspection: { $0 as? UITableView})
            for tableView in tableViews {
                self.configure(tableView)
            }
        }
    }
}


struct ContentView: View {
    var body: some View {
        List {
            .
            .
            .
        }
        .background(TableViewConfigurator {
            $0.backgroundColor = .clear
            $0.separatorStyle = .none
        })

    }
}
anonymous No title
Swift
    func scrollToBottom(){
        let withTimeInterval = 0.001
        var elapsedTime = 0.0
        let timeOut = 1.0
        Timer.scheduledTimer(withTimeInterval: withTimeInterval, repeats: true, block: { (timer) in
            elapsedTime = elapsedTime + withTimeInterval
            if(elapsedTime >= timeOut){
                timer.invalidate()
            }
            let tableViews = ViewRetriever.retrieve(parentView: self.window?.rootViewController?.view, inspection: {$0 as? UITableView})
            if !tableViews.isEmpty {
                var rowCount = self.user.items?.count ?? 0
                if rowCount == 0 {
                    rowCount = 1
                }
                let tableView = tableViews[0]
                let loadCount = tableView.numberOfRows(inSection: 0)
                if (loadCount == rowCount){
                    tableView.scrollToRow(at: .init(row: rowCount - 1, section: 0), at: .bottom, animated: true)
                    timer.invalidate()
                }
            }else{
                timer.invalidate()
            }
        })
    }
anonymous No title
Swift
 .
 .
 .
@State var items = (0..<100).map{Item(name: "name \($0)")}
 .
 .
 .
List {
  ForEach(self.items){ item in
    Text(item.name)
  }
}
.onAppear{
  DispatchQueue.main.async {
    let tableViews = ViewRetriever.retrieve(parentView: self.window?.rootViewController?.view, inspection: {$0 as? UITableView})
    if !tableViews.isEmpty {
      var rowCount = self.items.count
      let tableView = tableViews[0]
      tableView.scrollToRow(at: .init(row: rowCount - 1, section: 0), at: .bottom, animated: true)
    }
  }
}
anonymous No title
Swift

List{
    //CoreDataから取得したもの
    ForEach(self.user.items?.array as? [Item] ?? [], id:\.self){ item in
      Text(item.name)
    }
}
.onAppear{
  DispatchQueue.main.async {
    let tableViews = ViewRetriever.retrieve(parentView: self.window?.rootViewController?.view, inspection: {$0 as? UITableView})
    if !tableViews.isEmpty {
      let rowCount = self.user.items?.count ?? 1
      tableViews[0].scrollToRow(at: .init(row: rowCount - 1, section: 0), at: .bottom, animated: true)
    }
  }
}


anonymous SwiftUIで、SF Symbolsの画像を使う方法
Swift
Image(systemName: "")
//macのAppStoreでダウンロードできる、SF Symbolsというアプリがあります。そこに表示されているApple標準のベクター画像を使える。
//たとえば paperplane という名前の画像を使う時は、
Image(systemName: "paperplane")でOK!
anonymous No title
Swift
💩
Don't you submit code?
Submit
1