Skip to content

Instantly share code, notes, and snippets.

FWIW: I'm not the author of the content presented here (which is an outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

What's an Effective Engineer?

import UIKit
class ExerciseOption: Decodable {
private enum ExerciseOptionCodingKeys: String, CodingKey {
case id
case appleHealthId = "apple_health_id"
case googleFitId = "google_fit_id"
case langsTranslation = "langs_translation"
}
class CarouselPageViewController: UIPageViewController {
fileprivate var items: [UIViewController] = []
override func viewDidLoad() {
super.viewDidLoad()
dataSource = self
decoratePageControl()
populateItems()
// MARK: - DataSource
extension CarouselPageViewController: UIPageViewControllerDataSource {
// code ommited ...
func presentationCount(for _: UIPageViewController) -> Int {
return items.count
}
func presentationIndex(for _: UIPageViewController) -> Int {
guard let firstViewController = viewControllers?.first,
// MARK: - DataSource
extension CarouselPageViewController: UIPageViewControllerDataSource {
func pageViewController(_: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let viewControllerIndex = items.index(of: viewController) else {
return nil
}
let previousIndex = viewControllerIndex - 1
guard previousIndex >= 0 else {
class CarouselPageViewController: UIPageViewController {
fileprivate var items: [UIViewController] = []
override func viewDidLoad() {
super.viewDidLoad()
dataSource = self
populateItems()
if let firstViewController = items.first {
setViewControllers([firstViewController], direction: .forward, animated: true, completion: nil)