Skip to content

Latest commit

 

History

History
85 lines (66 loc) · 2.79 KB

README.md

File metadata and controls

85 lines (66 loc) · 2.79 KB

NYTTopStories

App review to demonstrate the following: collection view, custom delegation, persistence using UserDefaults and Documents directory, setting up UI Programmatically, animaation and gestures.

  • Collection view
  • Custom pogrammatic collection view cell
  • User defaults
  • Search
  • Subclass UITabBarController
  • FileManager and documents directory
  • Custom delegation
  • Programmatic UI
  • Segueing view controllers in code
  • Animations
  • Gestures
  • Unit test

Running this project

In order to run this project you will need an API key to access the New York Times Top Stories API. Once you've registered and acquired an API key, do the following:

  1. Clone this repo
  2. Open the Xcode project and navigate to Supporting Files folder delete the Config.swift file and create a new Config.swift file
  3. Open the newly created Config.swift file and enter the following code below:
struct Config {
  static let apiKey = "YOUR API KEY FOR THE NEW YORK TIMES TOP STORIES API GOES HERE"
}
  1. Run the project

Encapsulating our view controller properties, using dependency injection with designated initializers (Programmatically)

Creating a designated initializer programmatically

private var dataPersistence: DataPersistence<Article>
private var userPreference: UserPreference

init(_ dataPersistence: DataPersistence<Article>, userPreference: UserPreference) {
  self.userPreference = userPreference
  self.userPreference.delegate = self
  self.dataPersistence = dataPersistence
  super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
  fatalError("init(coder:) has not been implemented")
}

Using dependency injection on a view controller programmatically

let newsFeedVC = NewsFeedViewController(dataPersistence, userPreference: userPreference)

Encapsulating our view controller properties, using dependency injection with designated initializers (Storyboard)

Creating a designated initializer for Storyboard injection

init?(coder: NSCoder, image: UIImage) {
  self.image = image
  super.init(coder: coder)
}

required init?(coder: NSCoder) {
  fatalError("init(coder:) has not been implemented")
}

Using dependency injection via Storyboard

let image = newsDetailView.newImageView.image ?? UIImage(systemName: "photo")!
let storyboard = UIStoryboard(name: "ZoomImage", bundle: nil)
let zoomImageVC = storyboard.instantiateViewController(identifier: "ZoomImageViewController", creator: { (coder)  in
  return ZoomImageViewController(coder: coder, image: image)
})
zoomImageVC.modalTransitionStyle = .crossDissolve
present(zoomImageVC, animated: true)

news-feed