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
| enum ErrorEnum: Error { | |
| case FooError | |
| case BarError | |
| } | |
| func bar(success: Bool) throws -> String { | |
| if success { | |
| return "bar success" | |
| } | |
| throw ErrorEnum.BarError |
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
| func ==(lhs: EnumString, rhs: String) -> Bool { | |
| return lhs.isEqual(rhs) | |
| } | |
| func ==(lhs: String, rhs: EnumString) -> Bool { | |
| return rhs.isEqual(lhs) | |
| } | |
| class EnumString: NSObject { | |
| let rawValue: String |
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 UIBarButtonItem { | |
| public func programmaticallyTap() { | |
| if let target = target | |
| , let action = action | |
| { | |
| target.value(forKey: NSStringFromSelector(action)) | |
| } | |
| } | |
| } |
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
| class ViewController: UIViewController { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| specialMethod() | |
| } | |
| func specialMethod() { | |
| // overridable method |
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
| class ViewController: UIViewController { | |
| var customizerObject: SpecialProtocol? | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| specialMethod() | |
| } |
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
| protocol SpecialProtocol: class { | |
| func specialMethod(_ vc: ViewController) | |
| } | |
| class VCCustomizer: NSObject, SpecialProtocol { | |
| func specialMethod(_ vc: ViewController) { | |
| // Special implementation | |
| } | |
| } |
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
| @interface SpecialProtocol < | |
| __covariant VIEW_CONTROLLER: UIViewController * | |
| > : NSObject | |
| - (void)specialMethod:(VIEW_CONTROLLER _Nonnull)viewController; | |
| @end |
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
| class ViewController: UIViewController { | |
| var customizerObject: SpecialProtocol<ViewController>? | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| specialMethod() | |
| } |
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
| // SWIFT | |
| class SpecialRed: SpecialProtocol<ViewController> { | |
| override func specialMethod(_ viewController: ViewController) { | |
| // customization | |
| } | |
| } | |
| // Objective-C | |
| @interface SpecialBlue: SpecialProtocol<ViewController *> | |
| @end |
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
| my_viewcontroller.customizerObject = SpecialRed() | |
| my_viewController.customizerObject = SpecialBlue() |