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 | |
struct HeroAnimationTest: View { | |
let indices = 0 ..< 3 | |
@State | |
var showsOtherView = false | |
@Namespace | |
var namespaceID: Namespace.ID |
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
/// Stores value types on the heap | |
/// | |
/// Arrays are stored on the heap and only the pointer (8 bytes) to the array remains on the stack. | |
/// This behaviour is used to wrap another type into an array, and therefore move it to the heap. | |
/// | |
/// Example usage: | |
/// ``` | |
/// @StoredOnHeap var hugeStruct: HugeStruct | |
/// ``` | |
@propertyWrapper |
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 | |
struct ContentView: View { | |
@State var now = Date() | |
@State var showWindow = false | |
@State var text: String = "" | |
let timer = Timer.publish(every: 1, on: .current, in: .common).autoconnect() | |
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 Foundation | |
class DictionaryDecoder { | |
init() { } | |
func decode<T: Decodable>(_ type: T.Type, from data: [String: Any]) throws -> T { | |
let decoder = _Decoder(codingPath: [], source: data) | |
return try T(from: decoder) | |
} | |
} |
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
struct AnyCodingKey: CodingKey { | |
var stringValue: String | |
var intValue: Int? | |
init?(intValue: Int) { | |
self.intValue = intValue | |
self.stringValue = "\(intValue)" | |
} | |
init?(stringValue: String) { | |
self.intValue = 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
public struct AnyCodable: Codable { | |
public let value: Any? | |
public init(_ value: Any?) { | |
self.value = value | |
} | |
public init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
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
struct Notification<T> { | |
let name: NSNotification.Name | |
} | |
private let notificationData = "_notificationData" | |
extension NotificationCenter { | |
func post<T>(_ notification: Notification<T>, object: Any? = nil, data: T) { | |
post(name: notification.name, object: object, userInfo: [notificationData: data]) | |
} |
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
public struct EncodableDictionary { | |
typealias EncodingFunction = (inout KeyedEncodingContainer<AnyCodingKey>) throws -> Void | |
// MARK: - Private Properties | |
private var data: [String: Any] = [:] | |
private var encodings: [String: EncodingFunction] = [:] | |
// MARK: - Lifecycle | |
public init() { } | |
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
enum SortOrder { | |
case Ascending, Descending, Same | |
} | |
extension Array { | |
typealias Sorter = (Element, Element) -> SortOrder | |
func sortWithPriorities(sorters: Sorter...) -> Array { | |
return sort { (left, right) -> Bool in | |
for sorter in sorters { | |
switch sorter(left, right) { |
NewerOlder