A iOS SwiftUI framework for displaying data from an api inside a List.

Related tags

Layout swift swiftui
Overview

Swift iOS Apache 2.0

FeedListKit

FeedListKit is a high level framework for representing data from an Api inside a SwiftUi List. It automatically handles refreshing and loading more on scroll.

How to use

Create the Api

First, you need to create an api which conforms to the Api protocol. FeedListKit automatically sends a page parameter to your api, you need to handle paging directly in your api.

FeedListKit works great with NetworkKit:

class MyApi: Api {
    static func fetchRows<T>(_ urlString: String, parameters: [String : String]?, type: T.Type) async -> [T]? where T : Model {
        do {
            return try await NKHttp.getObjectArray(urlString, parameters: parameters, type: type)
        } catch {
            return nil
        }
    }
    
    static func fetchRows<T>(_ urlString: String, parameters: [String : String]?, type: T.Type, callback: @escaping ([T]?) -> ()) where T : Model {
        NKHttp.getObjectArray(urlString, parameters: parameters, type: type, callback: callback)
    }
}

But you can also fetch the data on your own:

class MyApi: Api {
    static func fetchRows<T>(_ urlString: String, parameters: [String : String]?, type: T.Type) async -> [T]? where T : Model {
        // Fetch your data and return the object array asynchronously.
        // You can use URLSession or some other http library.
    }
    
    static func fetchRows<T>(_ urlString: String, parameters: [String : String]?, type: T.Type, callback: @escaping ([T]?) -> ()) where T : Model {
        // Fetch your data and return the object array with callback.
        // You can use URLSession or some other http library.
    }
}

Create a model for your data

The model needs to conform to the Model protocol.

struct Animal: Model {
    var id: String
    var name: String
}

Create a FeedNetworking

Create your first FeedNetworking and pass your object Model and your Api type.

class MyAnimalFeedNetworking: FeedNetworking<Animal, MyApi> {
    // The url to your api endpoint
    override var apiUrl: String {
        "http://mydomain.com/api/animals"
    }
    
    // Your parameters
    override var httpParameters: [String : String] {
        [
            "myKey": myValue
        ]
    }
}

Use FeedList

struct MyAnimals: View {

    init() {
        self._feedNetworking = StateObject(wrappedValue: MyAnimalFeedNetworking())
    }

    @StateObject private var feedNetworking: MyAnimalFeedNetworking

    var body: some View {
        FeedList(feedNetworking: feedNetworking, row: { animal in
            Text(animal.wrappedValue.name)
        }, loadingView: {
            Text("Fetching animals ...")
        }, noDataView: {
            Text("No Animals found! :(")
        })
        .task {
            await feedNetworking.fetch()
        }
    }
}
You might also like...
Autogenerated Twitter v2 API codes for iOS

Swift5 API client for OpenAPIClient Twitter API v2 available endpoints Overview This API client was generated by the OpenAPI Generator project. By usi

This page contains an iOS Application that uses Modelplace.AI Cloud API

Modelplace iOS App This page contains an iOS Application that uses Modelplace.AI

UIViews that update themselves when your data changes, like React.
UIViews that update themselves when your data changes, like React.

StateView is a UIView substitute that automatically updates itself when data changes. Contents: Overview What's it like? Sample apps How does it work?

CompositionalLayoutDSL, library to simplify the creation of UICollectionViewCompositionalLayout. It wraps the UIKit API and makes the code shorter and easier to read.
CompositionalLayoutDSL, library to simplify the creation of UICollectionViewCompositionalLayout. It wraps the UIKit API and makes the code shorter and easier to read.

CompositionalLayoutDSL CompositionalLayoutDSL is a Swift library. It makes easier to create compositional layout for collection view. Requirements Doc

Concise Auto Layout API to chain programmatic constraints while easily updating existing constraints.
Concise Auto Layout API to chain programmatic constraints while easily updating existing constraints.

Concise API for Auto Layout. SnapLayout extends UIView and NSView to deliver a list of APIs to improve readability while also shortening constraint co

Using Kiva's free API, the demo app retrieves its most recent fundraising loans
Using Kiva's free API, the demo app retrieves its most recent fundraising loans

KivaLoan Kiva is a non-profit organization with a mission to connect people through lending to alleviate poverty. Using Kiva's free API, the demo app

What's New In SwiftUI for iOS 16 - Xcode 14 -  SwiftUI 4.0
What's New In SwiftUI for iOS 16 - Xcode 14 - SwiftUI 4.0

SwiftUI4 What's New In SwiftUI for iOS 16 - Xcode 14 - SwiftUI 4.0 (Work in progress....) Swift Charts Presentation Detents(Half Sheet & Small Sheets)

Declarative iOS UI sugar framework built on FlexLayout
Declarative iOS UI sugar framework built on FlexLayout

Declarative iOS UI sugar framework built on FlexLayout

A declarative UI framework for iOS
A declarative UI framework for iOS

Layout Layout is a native Swift framework for implementing iOS user interfaces using XML template files and runtime-evaluated expressions. It is inten

Releases(1.0.0)
Owner
Knoggl
Just trying to make the world a better place.
Knoggl
API Calling - Made an app in swift that gets data from Randomuser api and uses it in UITableView

API_Calling Made an app in swift that gets data from Randomuser api and uses it

Arnav Chhokra 1 Feb 4, 2022
A curated list of Open Source example iOS apps developed in Swift

 A curated list of Open Source example iOS apps developed in Swift. An amazing list for people who are beginners and learning ios development and for ios developers who need any example app or feature.

Jogendra 698 Sep 21, 2022
RMIT SSET Contact List iOS app!

RMIT SSET Contact List "The Contact List is Long, The Circle is Small!" ?? Description This is an iOS application, inspired from the traditional phone

Tom Huynh 4 Sep 22, 2022
LazyHList: Horizontal list with lazy loading with dequeueing

LazyHList LazyVStack and LazyHStack does load content lazly however they do not

Sezer Tunca 0 Dec 17, 2021
Simple App for Creating and maintaining list of goals to be achieved.

Goal-App Simple App for Creating and maintaing list of goals to be acheived. Created while following this desgin: https://dribbble.com/shots/14772731-

Coding Monkey 2 Aug 28, 2022
A custom layout built on top of SwiftUI's Layout API that lays elements out in multiple lines. Similar to flex-wrap in CSS, CollectionViewFlowLayout.

WrapLayout A custom layout built on top of SwiftUI's Layout API that lays elements out in multiple lines. Similar to flex-wrap in CSS, CollectionViewF

Hiroshi Kimura 6 Sep 27, 2022
IOS-PokemonQuizApp - Assignment to make a responsive iOS app. App has to connect with an external API

iOS-PokemonQuizApp Assignment to make a responsive iOS app. App has to connect with an external API. The Project The idea of the project is to make a

BennyDB 0 Jan 9, 2022
ios-queryable is an implementation of IQueryable/IEnumerable for Core Data

#ios-queryable is an Objective-C category that provides IQueryable and IEnumerable-like functionality to Core Data. Tired of writing boilerplate Core

Marty Dill 227 Mar 3, 2022
`SwiftUI` Framework Learning and Usage Guide. 🚀

This article refers to SwiftUI apple example and records the results of the exploration here, I hope to be helpful to you. For the content described i

晋先森 4.4k Sep 22, 2022
The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. Objective-C and Swift compatible.

The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. PureLayout extends UIView/NSView, NSArray, and NSLayoutConstrai

PureLayout 7.6k Sep 26, 2022