Git Product home page Git Product logo

hitendradeveloper / hssearchable Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 1.0 547 KB

The easiest way to search from UITableView using UISearchBar or UISearchBarController in the minimum line of code.

Home Page: https://medium.com/@hitendrahckr

License: MIT License

Swift 97.18% Ruby 2.82%
uisearchbar uitableview uiviewcontroller cocoapods serchable hssearchable hitendra solanki hitendra-solanki-ios hitendra-solanki

hssearchable's Introduction

HSSearchable

Easiest way to search from UITableView using UISearchBar in minimum line of code in UIViewController

HSSearchable

How to integreat source?

  1. Directly drag and drop the HSSearchable.swift into your xcode project.

  2. Most recommanded: install via cocoapods (How to use cocoapods)

    pod 'HSSearchable'
    

How to use in code ? Just follow the simple steps :)

import HSSearchable

//Suppose this is your datamodel
struct UserDM {
  var name: String
  var city: String
 }
  1. extend your class or Structure using the SearchableData delegate

    extension UserDM: SearchableData {
     var searchValue: String{
       return self.name + " " + self.city //this will search from the name and city both
    
       //return self.name //this will search from the name only
     }
    }
    
  2. Create a variable of 'SearchableWrapper' in the viewController as property

    var usersData = SearchableWrapper()
    var users: [UserDM] { //use this array as you are using array for your tableview controller
       return self.usersData.dataArray as! [UserDM]
    }
    
  3. Set the searchbar delegate and Searching callback

    override func viewDidLoad() {
       super.viewDidLoad()
       self.searchbar.delegate = self.usersData
       self.usersData.searchingCallBack = { isSearching, searchText in
           print("searching Text:= \(searchText)")
           self.tableView.reloadData()
       }
       self.loadDummyData()
    }
    
  4. Set the local array or load data from the server usign API|Webservice call

     func loadDummyData(){
           //This is just an example data
           let user1 = UserDM(name: "Hitendra Solanki", city: "Ahmedabad")
           let user2 = UserDM(name: "Justina Flores", city: "Arizona")
           let user3 = UserDM(name: "Lisa Minick", city: "Casper")
           let user4 = UserDM(name: "Moises Patrick", city: "Reno")
           let user5 = UserDM(name: "Martha Fisher", city: "Tacoma")
           let user6 = UserDM(name: "Martha McDaniel", city: "Irvine")
           let array : Array<UserDM = [
               user1,
               user2,
               user3,
               user4,
               user5,
               user6
           ]
           //In most of the cases, this data will come from the server side
           self.usersData.serverArray = array;
           self.tableView.reloadData()
     }
    
  5. Optional Setps: HSSearchable also supports the optional customDelegate, using this you can handle default UISearchabarDelegate methods in your own viewControllers.

       self.usersData.customDelegate = self //implement UISearchbarDelegate in your class       
    

It's Done

It's Done

Contact:

twitter: @hitendrahckr

hssearchable's People

Contributors

hitendradeveloper avatar hitendraspaceo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

pratik-sodha

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.