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 Color { | |
| /// Return a random color | |
| static var random: Color { | |
| return Color( | |
| red: .random(in: 0...1), | |
| green: .random(in: 0...1), | |
| blue: .random(in: 0...1) | |
| ) | |
| } | |
| } |
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 SKAction { | |
| static func write<Root: AnyObject, Value>( | |
| value: Value, | |
| to keyPath: ReferenceWritableKeyPath<Root, Value>, | |
| on object: Root | |
| ) -> SKAction { | |
| SKAction.customAction(withDuration: 0) { [weak object] _, _ in | |
| object?[keyPath: keyPath] = value | |
| } |
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
| struct Foo: Codable { | |
| var name: String | |
| @Ignore var foo: Int? | |
| } | |
| let model = Foo(name: "Ian", foo: 42) | |
| let data = try! JSONEncoder().encode(model) | |
| print(String(data: data, encoding: .utf8)!) // {"name":"Ian"} | |
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
| /// Get the payload of a video asset and export it to a local temp file. | |
| /// The resulting publsher will emit values until completed or cancelled. The `Double` is the progress, | |
| /// which is a combination of the download progress and the export progress, so it will range from 0 to 1 but the | |
| /// last export part is probably a lot quicker than the download part. | |
| /// | |
| /// Calling cancel() on the publisher will cancel both the image request and the export as appropriate | |
| func exportAVAsset(forPHAsset phAsset: PHAsset) -> (AnyPublisher<(URL?, Double), MediaError>) { | |
| let avAssetOptions = PHVideoRequestOptions() | |
| avAssetOptions.isNetworkAccessAllowed = true | |
| avAssetOptions.deliveryMode = .highQualityFormat |
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 | |
| struct CircleWave: Shape { | |
| let N = 360 | |
| let SPEED: Double = 1 / 1000.0 | |
| let SHIFT: Double = 2 * Double.pi / 3 | |
| let FREQUENCY: Double = 8 | |
| var factor: Double | |
| var colorIndex: Double | |
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
| // | |
| // Created by https://quickplan.app on 2020/11/8. | |
| // | |
| import SwiftUI | |
| /// Control if allow to dismiss the sheet by the user actions | |
| /// - Drag down on the sheet on iPhone and iPad | |
| /// - Tap outside the sheet on iPad | |
| /// No impact to dismiss programatically (by calling "presentationMode.wrappedValue.dismiss()") |
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
| // | |
| // ContentView.swift | |
| // | |
| // | |
| // Created by Bernstein, Joel on 7/4/20. | |
| // | |
| import SwiftUI | |
| struct ElementModel: Identifiable |
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
| // | |
| // TipsView.swift | |
| // Stonks | |
| // | |
| // Created by Paul Stamatiou on 7/3/20. | |
| // | |
| import SwiftUI | |
| import PlaygroundSupport |
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 | |
| import PlaygroundSupport | |
| // constants | |
| let cardWidth: CGFloat = 343 | |
| let cardHeight: CGFloat = 212 | |
| let spacing = 36 | |
| let animation = Animation.spring() | |
| let cardColors = [ | |
| Color(UIColor.systemRed), |
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 | |
| let colors = [ | |
| Color.pink, | |
| Color.blue, | |
| Color.green, | |
| Color.orange, | |
| Color.purple, | |
| Color.black, | |
| ] |