satyadevchauhan / FlickrSearch

Flickr search application written in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FlickrSearch

Flickr search application written in Swift. This project searches for images using Flickr API and displays in 3 column grid and provides endless scrolling. The data is paginated and service takes care of fetching data from Flickr service. The application uses MVVM architecture.

Getting Started

  • Clone the repo and run FlickrSearch.xcodeproj
  • Create a Flickr API key and replace placeholder with key in FlickrConstants.swift
  • Run the project and search for any keyword like "kittens".
  • The application doesn't uses any third party library.

SearchPhoto

Flickr API

Images are retrieved by hitting the Flickr API.

{
"id": "43213681030",
"owner": "164058447@N08",
"secret": "a4bf8df905",
"server": "1937",
"farm": 2,
"title": "Puss under the boot",
"ispublic": 1,
"isfriend": 0,
"isfamily": 0
}

We use the farm, server, id, and secret to build the image path. Flickr Photo Source URLs

Class Details

FlickrSearch

This module consists of all files related to Flickr search and presenting on UI. A single view that contains a UICollectionView to display the retrieved images in a three-column layout. It supports endless scrolling and automatically loads next pages when the user approaches the end of the current page. The search bar supports searching for multi-word phrases not only a single keyword. The view supports all orientations and uses that autolayout to arrange items inside the collection view.

Views

  • ViewControllers: This module consists of primary class FlickrCollectionViewController which consists of collection view and search text field. It also encapsulates functionality like fetching, refreshing and searching. On fetching data it binds this data with viewmodel and hence render it.
  • ImageCollectionViewCell: This is the view which is reused for displaying images fetched from service. It also renders image by downloading it asyncronously using ImageDownloadManager and also handles some important usecase like cancelling downloading while recycling.

ViewModels

  • FlickrViewModel: This class represents data to be rendered in FlickrCollectionViewController via bindings.
  • ImageModel: ImageModel represents data to be rendered in collection view cells, this is been generated while views are recycled.

Models

  • FlickrSearchResults: This class represents the structure of response of request from flicker service for the searched text. This class uses codable protocal and used for parsing.
  • FlickrPhoto: This class represents the structure of pagination details and array of images from FlickrSearchResults. This class uses codable protocal and used for parsing.
  • Photos: This model represents data structure for images details. It encapsultes all related info and hence generates url for fetching images. This class uses codable protocal and used for parsing.

Services

  • FlickrSearchService: This service class is responsible for preparing the request, fetching and parsing response for consecutive pages. It internally uses NetworkManager to perform the request.

NetworkManager

This module consists of classes related to network used to fetch the stream of data, careate request and check reachability of internet.

  • NetworkManager: This class is basically used to fetch data from server. It is used to fetch data using http protocol like GET, POST etc. Has 2 methods on which fetches data as Data type and Image. It takes a URL and retrieve a stream of data contained at this URL no matter what kind of data it is. The advantage of this abstraction is that many other modules in the app can use the same module to retrieve different kinds of data such as images, json ... etc
  • ImageDownloadManager: This class is responsible for caching, queuing and fetching images from server. It is uses ImageDownloadOperation to fetch the data from server.
  • ImageDownloadOperation: This class uses the NetworkManager class to download an image from Flickr API and returns the image object.

UnitTests

This module consists XCTTest classes for testing.

  • FlickrNetworkTests: This class tests the network interactions for fetching image and data, and vallidating its consistency. UI testing is not done due to time constraints.

About

Flickr search application written in Swift


Languages

Language:Swift 100.0%