This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application(_ application: UIApplication, | |
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { | |
let isUnitTesting = ProcessInfo.processInfo.environment["IS_UNIT_TESTING"] == "1" | |
if isUnitTesting == false { | |
// Do UI-related setup, which can be skipped when testing | |
} | |
return true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FileOpener { | |
let urlOpener: URLOpening | |
init(urlOpener: URLOpening = UIApplication.shared) { | |
self.urlOpener = urlOpener | |
} | |
func open(identifier: String) { | |
guard let url = URL(string: "iosappscheme://open?id=\(identifier)") else { | |
debugPrint("Failed to load URL") | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol URLOpening { | |
func canOpenURL(_ url: URL) -> Bool | |
func open(_ url: URL, | |
options: [UIApplication.OpenExternalURLOptionsKey : Any], | |
completionHandler completion: ((Bool) -> Void)?) | |
} | |
extension UIApplication: URLOpening {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FileOpener { | |
let application: UIApplication | |
init(application: UIApplication = UIApplication.shared) { | |
self.application = application | |
} | |
func open(identifier: String) { | |
guard let url = URL(string: "iosappscheme://open?id=\(identifier)") else { | |
debugPrint("Failed to load URL") | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FileOpener { | |
func open(identifier: String) { | |
guard let url = URL(string: "iosappscheme://open?id=\(identifier)") else { | |
debugPrint("Failed to convert URL") | |
return | |
} | |
if UIApplication.shared.canOpenURL(url) { | |
UIApplication.shared.open(url, options: [:], completionHandler: nil) | |
} else { | |
debugPrint("Failed to open URL") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FetchRestaurantInventoryOperation: Operation { | |
var restaurantData: RestaurantData | |
var networkProvider: NetworkProvider | |
// 1 | |
private var _executing = false { | |
willSet { | |
willChangeValue(forKey: "isExecuting") | |
} | |
didSet { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* I put the first DispatchQueue method intentionally to indicate that we're on | |
the background queue. Just to support the explanation for beginner developers | |
This is not necessary in real-life, URLSession is thread-safe. Whenever you call URLSession | |
it'll start executing on background. */ | |
DispatchQueue.global().async { | |
let url = URL(string: "https://theswiftpost.co/") | |
if let url = url { | |
DispatchQueue.main.sync { | |
showLoadingIndicator() // UI Operation; has to run on the main queue | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let url = URL(string: "https://theswiftpost.co/") | |
if let url = url { | |
showLoadingIndicator() // UI Operation; has to run on the main queue | |
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in | |
if error != nil { | |
showErrorAlert(error) // UI operation; has to run on the main queue!! | |
} else if let data = data { | |
debugPrint(usableData) //JSONSerialization | |
} | |
debugPrint(“Completed”) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adding a view controller to another | |
let childViewController = UIViewController() | |
let parentViewController = UIViewController() | |
parentViewController.addChild(childViewController) | |
parentViewController.view.addSubview(childViewController.view) | |
// setup auto-layout constraints for childViewController.view | |
childViewController.didMove(toParent: parentViewController) | |
// Removing the child view controller from parent | |
childViewController.willMove(toParent: nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
protocol ViewCustomized { | |
func createView<T>(_ viewClass: T.Type, parentView: UIView) -> T where T: UIView, T: ViewRenderable | |
} | |
protocol ViewRenderable { | |
func render() | |
} |
NewerOlder