SwiftUI Pagination

SwiftUI Pagination

Pagination in SwiftUI & MVVM.

In this example I'll show how to handle pagination:

1) Let's start with our ContentView: a ZStack with a Progress View & a List (Table) of items:

No alt text provided for this image

2) Our ViewModel will have the items array for the data, isLoading bool for the progress animation, and a fake network request function to simulate the request for data fetch:

No alt text provided for this image

3) Last - our custom ListViewCell. something very simple just for the example:

No alt text provided for this image

You can find the code here:


And The Result:

David Chikly

Founder @ Stealth Startup | Sr. Software Engineer

2 年

Nice, another way is to load the items in the ForEach and apply a function to check , because you often need the item in the block, I personally dont like accessing it using the index (viewModel.items[i] , i+ 1 == last ) etc..

Yoav Karsenty

Data Analyst –Extracting business insights from large datasets enabling various profit-maximizing actions. Assists athletes in determining their data-driven market value and how to increase it | Python | SQL | Excel

2 年

looks great!!

要查看或添加评论,请登录

Aviram Netanel的更多文章

  • UIKit vs. SwiftUI - TableView \ List

    UIKit vs. SwiftUI - TableView \ List

    I wrote 2 projects that shows a tableview \ list with expandable cells. The idea is simple: you have a table \ list…

    4 条评论
  • Swift - didSet{...} Property Observer

    Swift - didSet{...} Property Observer

    if you're not familiar with the 'didSet' property observer - this is for you: with this simple trick you can execute a…

    1 条评论
  • Swift - Building a custom framework

    Swift - Building a custom framework

    A quick tutorial for building and importing a custom SDK to your project. save it for a rainy day.

    1 条评论
  • Swift - the 'required' keyword

    Swift - the 'required' keyword

    Did you ever get this error? 'required' initializer 'init(coder:)' must be provided by subclass of..

    1 条评论
  • Swift - Array map, flatMap & compatMap

    Swift - Array map, flatMap & compatMap

    map, flatMap & compactMap are Array methods for manipulation. here are few simple examples to help you understand, and…

  • The keyword 'some' - Swift \ SwiftUI

    The keyword 'some' - Swift \ SwiftUI

    If you ever started a SwiftUI project, you've probably noticed this 'some' keyword. so what's that? The keyword 'some'…

    7 条评论
  • Static - when do we use it?

    Static - when do we use it?

    First, if you don’t know the difference between Type & Instance: Type is the definition of a class \ struct . Instance…

    9 条评论
  • UIViewController - Lifecycle

    UIViewController - Lifecycle

    This is one of the most common questions in interviews, so you better know this one. In General Every view controller…

    9 条评论
  • @escaping closures in Swift

    @escaping closures in Swift

    In short: We will use @escaping when the closure needs to outlive the life of its function More: when we pass a closure…

    5 条评论
  • Arguments and Parameters

    Arguments and Parameters

    Arguments and Parameters What's the difference? Parameter is the variable in the declaration of the function. Argument…

    4 条评论

社区洞察

其他会员也浏览了