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 Foundation | |
| let obj = NSNumber(int: 2) | |
| func correct<T>() -> T? { | |
| if let val = obj as? T { | |
| println("matching types") | |
| return val | |
| } |
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
| /* Domain model */ | |
| // A Profile consists of a person name and an optional avatar | |
| struct Profile { | |
| let personName: PersonName | |
| let avatarURL: NSURL? | |
| } | |
| // These are the UX rules for showing a greeting: |
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
| // We can use Phantom Types to provide strongly typed acces to NSUserDefaults | |
| // Similar to: http://www.objc.io/blog/2014/12/29/functional-snippet-13-phantom-types/ | |
| // A key to UserDefaults has a name and phantom type | |
| struct Key<T> { | |
| let name: 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
| import UIKit | |
| @UIApplicationMain | |
| class AppDelegate: UIResponder, UIApplicationDelegate { | |
| var window: UIWindow? | |
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
| print(process(MyFoo())) | |
| return true | |
| } |
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
| /// - returns: `true` when dynamic type is `Equatable` and `==` returns `true`, otherwise `false`. | |
| func areEquatablyEqual(_ lhs: Any, _ rhs: Any) -> Bool { | |
| func receiveLHS<LHS>(_ typedLHS: LHS) -> Bool { | |
| guard | |
| let rhsAsLHS = rhs as? LHS | |
| else { return false } | |
| return areEquatablyEqual(typedLHS, rhsAsLHS) | |
| } | |
| return _openExistential(lhs, do: receiveLHS) | |
| } |
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
| // | |
| // DarwinNotificationCenter.swift | |
| // | |
| // Created by Nonstrict on 2023-12-07. | |
| // | |
| import Foundation | |
| import Combine | |
| private let center = CFNotificationCenterGetDarwinNotifyCenter() |
OlderNewer