Giter Club home page Giter Club logo

flickr-search-1's Introduction

Flickr-Search

This is the basic example for the Flickr image search module. Its will search any keyword based on your keyword and it will display the images with the endless scrolling.

Inside this project UISearchBar using for type keywords and UICollectionView for display search results. It will call request async and display new images based on page count in backgroud simuntaniously.

Getting Started

  • Clone the repo and run Flickr-Search.xcodeproj
  • No pod install or carthage update needed directly use this projects
  • Create a Flickr API key and replace in line number 15 flickrKey with your own key in Router.swift

๐Ÿค” Requirements

  • Deployment target of your App is >= iOS 10.0
  • XCode 9.3 or later
  • Swift 4.0

Flickr API Documentation

Images are retrieved by hitting the Flickr API.

  • Search Path:
https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=YOUR_FLICKR_API_KEY&format=json&nojsoncallback=1&safe_search=1&text=KEYWORD
  • Response includes an array of photo objects, each represented as:
{
    "id": "23451156376",
    "owner": "28017113@N08",
    "secret": "8983a8ebc7",
    "server": "578",
    "farm": 1,
    "title": "Merry Christmas!",
    "ispublic": 1,
    "isfriend": 0,
    "isfamily": 0
}

To load the photo, you can build the full URL following this pattern:

http://farm{farm}.static.flickr.com/{server}/{id}_{secret}.jpg

Thus, using our Flickr photo model example above, the full URL would be:

http://farm1.static.flickr.com/578/23451156376_8983a8ebc7.jpg

Generate your own here:

https://www.flickr.com/services/api/misc.api_keys.html

Keyword search request

UISearchBar priving for keyword search access.

    func searchBarSearchButtonClicked(_ searchBar: UISearchBar){
        searchBar.resignFirstResponder()
        
        //Reset old data first befor new search Results
        resetValuesForNewSearch()
        
        //Requesting here new keyword
        fetchSearchImages()
    }

Endless Scrolling with pagination

For providing infinite scroll using here UIScrollView Delegate method it will calculate size which required for pagination new data model

//MARK :- Getting user scroll down event here
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if scrollView == collectionResult{
            if ((scrollView.contentOffset.y + scrollView.frame.size.height) >= (scrollView.contentSize.height)){
                
                //Start locading new data from here
                fetchSearchImages()
            }
        }
    }
  • Collection View with flowlayout
  • Image Cache

Generics type Async Network request

 router.requestFor(text: searchBar.text ?? "", with: pageCount.description, decode: { json -> Photos? in
        guard let flickerResult = json as? Photos else { return  nil }
        return flickerResult
 }) { [unowned self] result in
            self.labelLoading.text = ""
            switch result{
            case .success(let value):
                self.updateSearchResult(with: value.photos.photo, nil)
            case .failure(let error):
                print(error.debugDescription)
                self.showAlertWithError((error?.localizedDescription) ??
                "Please check your Internet connection or try again.", completionHandler: {[unowned self] status in
                    guard status else { return }
                    self.fetchSearchImages()
            })
      }
  }

๐Ÿ‘ค Author

Anscoder (Anand Nimje)

flickr-search-1's People

Contributors

anscoder avatar

Watchers

James Cloos avatar

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.