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
//https://www.hackingwithswift.com/articles/233/whats-new-in-swift-5-5 | |
// - OLD WAY | |
func fetchWeatherHistory(completion: @escaping ([Double]) -> Void) { | |
// Complex networking code here; we'll just send back 100,000 random temperatures | |
DispatchQueue.global().async { | |
let results = (1...100_000).map { _ in Double.random(in: -10...30) } | |
completion(results) | |
} |
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
/// The list of the onboarding steps | |
enum OnboardingStep: String { | |
case overview | |
case documentScan | |
case saveAndLogin | |
} | |
/// The onboarding errors | |
/// | |
/// - failed: Onboarding failed with the described error |
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 SwiftUI | |
@main | |
struct MyMainApp: App { | |
var body: some Scene { | |
WindowGroup { | |
MainView.build() | |
} | |
} | |
} |
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
//Time complexity:O(N), Space complexity: (1) | |
func findCommonSuper(_ view1:inout UIView, _ view2:inout UIView) -> UIView? { | |
//Get the level of the 2 views | |
var level1 = findLevel(view1) | |
var level2 = findLevel(view2) | |
/****/ | |
//Find the 2 views for the same level | |
if level1 > level2 { |
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
/* | |
Content loading is at least three stage process: | |
- Before the loading starts there is the initial moment. | |
- The actual process of loading content. We need to present some progress or activity indication in the UI; | |
- And finally the result, success or failure. | |
SwiftUI encourages creating small, reusable views, and use composition to create the complete picture. | |
Each stage of the content loading process will require a view. The container view will compose the result. | |
*/ |
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
//https://nshipster.com/device-identifiers/ | |
//Besides identifierForVendor.. | |
/* | |
Locale information is the greatest source of identifying information on Apple platforms. | |
The combination of your preferred languages, region, calendar, time zone, | |
and which keyboards you have installed say a lot about who you are | |
especially if you have less conventional preferences. | |
*/ |
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 | |
// Call CGImage mechanism from a UIImage | |
@objc extension UIImage { | |
var isDark: Bool { | |
self.cgImage?.isDark ?? false | |
} | |
} |
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
VIP / Clean Swift | |
//https://zonneveld.dev/the-clean-swift-architecture-explained/ | |
------------------- | |
VC -> Asks the Interactor for an action. | |
Interactor -> Business logic | Can write unit tests against it. | |
Will also handle requests and return object to the presenter | |
Presenter -> Presentation | Parse the object to a view model and give it to the VC to be displayed. |
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
//https://swiftrocks.com/writing-cleaner-view-code-by-overriding-loadview.html | |
/// The HasCustomView protocol defines a customView property for UIViewControllers to be used in exchange of the regular view property. | |
/// In order for this to work, you have to provide a custom view to your UIViewController at the loadView() method. | |
public protocol HasCustomView { | |
associatedtype CustomView: UIView | |
} | |
extension HasCustomView where Self: UIViewController { | |
/// The UIViewController's custom view. |
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
//Documentation | |
//https://blog.scottlogic.com/2015/02/05/swift-events.html | |
//KVO example (not shown in this gist) | |
//https://blog.scottlogic.com/2015/02/11/swift-kvo-alternatives.html | |
public class Event<T> { | |
public typealias EventHandler = T -> () |
NewerOlder