Giter VIP home page Giter VIP logo

appspotlist's Introduction

Screen-Shot-2018-12-06-at-5-06-53-PM

Appspotlist is a simple ,clean iOS App demonstrating how to make a custom datasource with generic datamodel type

Xcode 9.0 iOS 8.0+ Swift 4.0+

Screen-Shot-2018-12-06-at-5-26-44-PMย  Screen-Shot-2018-12-06-at-5-28-07-PM

How to Use

Simply download or clone this project open in Xcode 9.0 or above hit Run button and there you go

Which ThirdParty libraries are used here

Here i have used two libraries SVProgressHUD and SDWebImage for Loading and Image downloading respectively using CocoaPods

How to install those libraries using CocoaPods

Add the following entry to your Podfile:

 pod 'SVProgressHUD', :git => 'https://github.com/SVProgressHUD/SVProgressHUD.git'
 pod 'SDWebImage', '~> 4.0'

Then run pod install.

What to learn about custom datasource

To make our controller clean and simple , i have used a separate datasource class for handling UITableViewDataSource delegate methods and here this custom datasource class is generic means depending on your datamodeltype you can use this class in your controller

import UIKit

class TableViewCustomDataSource<Model>: NSObject,UITableViewDataSource{
    
    typealias CellConfigurator = (Model,UITableViewCell)-> Void
    var models:[Model]
    private let reuseIdentifier:String
    private let cellConfigurator: CellConfigurator
    init(models:[Model],reuseIdentifier:String,cellConfigurator:@escaping CellConfigurator) {
        
       self.models = models
       self.reuseIdentifier = reuseIdentifier
       self.cellConfigurator = cellConfigurator
    }
    
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return models.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let model = models[indexPath.row]
        let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath)
        cellConfigurator(model,cell)
        return cell
    }
    
}

Happy Coding

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.