This file contains hidden or 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
| private final class WeakRefVirtualProxy<T: AnyObject> { | |
| private weak var object: T? | |
| init(object: T) { | |
| self.object = object | |
| } | |
| } | |
| extension WeakRefVirtualProxy: ConformingProtocol where T: ConformingProtocol { | |
| func methodFromProtocol(aBoolProperty: Bool) { |
This file contains hidden or 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 | |
| // Overload that allows some bindings to be optional. E.g. having an optional | |
| // property bound to the TextField | |
| // TextField("", text: $optionalProperty ?? "default value") | |
| func ??<T>(lhs: Binding<Optional<T>>, rhs: T) -> Binding<T> { | |
| Binding( | |
| get: { lhs.wrappedValue ?? rhs }, | |
| set: { lhs.wrappedValue = $0 } |
This file contains hidden or 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
| extension Date { | |
| var age: Int { | |
| get { | |
| let calendar = Calendar.current | |
| let ageComponents = calendar.dateComponents([.year], from: self, to: Date()) | |
| return ageComponents.year ?? 0 | |
| } | |
| } | |
| } |
This file contains hidden or 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
| extension String { | |
| var localized: String { | |
| return NSLocalizedString(self, comment: "") | |
| } | |
| func localized(comment: String) -> String { | |
| return NSLocalizedString(self, comment: comment) | |
| } | |
This file contains hidden or 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 | |
| public enum AttributeConstructor { | |
| public enum Attribute { | |
| case lineHeight(CGFloat) | |
| case lineHeightMultiple(CGFloat) | |
| case alignment(NSTextAlignment) | |
| case font(UIFont) | |
| case kern(CGFloat) | |
| case color(UIColor) |
This file contains hidden or 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 Storyboarded { | |
| static func instantiate(storyboardName: String?) -> Self | |
| } | |
| extension Storyboarded where Self: UIViewController { | |
| static func instantiate(storyboardName: String?) -> Self { | |
| // this pulls out "MyApp.MyViewController" | |
| let fullName = NSStringFromClass(self) |