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 private var preferences = PreferencesModel() | |
var body: some View { | |
VStack { | |
HStack { | |
Text("Value: ") | |
Text(preferences.theNumber.formatted()).bold() |
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 { | |
@Environment(PreferencesModel.self) var preferences | |
var body: some View { | |
Text("Salary: \(preferences.salary)") | |
} | |
} |
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 | |
import SwiftUI | |
protocol Achievement { | |
var id: UUID { get } | |
var name: String { get } | |
var description: String { get } | |
var isAchieved: Bool { get set } | |
var primaryTint: Color { get } | |
var secondaryTint: Color { get } |
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 FallWithRotationModifier: ViewModifier { | |
let isHidden: Bool | |
var yOffset: CGFloat { | |
return isHidden ? 1000 : 0 | |
} | |
var rotationDegrees: Double { | |
guard isHidden else { return 0 } | |
let degrees = Double.random(in: 30...90) |
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
/** | |
Most of this file has been omitted to only focus on the caching aspect, but in reality | |
it would be a standard widget template. | |
**/ | |
struct MyWidgetProvider: IntentTimelineProvider { | |
// Initialise the cache. | |
private let cache = MyWidgetCache() | |
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 | |
import MapKit | |
struct ContentView: View { | |
@State private var mapRegion = MKCoordinateRegion( | |
center: CLLocationCoordinate2D( | |
latitude: 51.5, | |
longitude: -0.12 | |
), |
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 ScrollingEmojiView: View { | |
@Environment(\.accessibilityReduceMotion) var reduceMotion | |
@State private var isAnimating = false | |
/* | |
In Personal Best (getpersonalbest.com) I get a random emoji to represent a workout type, | |
using an extension to HKWorkoutActivityType. Here I've stubbed it out with a more basic | |
implementation. |
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 ScreenShotView: View { | |
var body: some View { | |
GeometryReader { geo in | |
VStack { | |
Text("Hello world") | |
Button("Take screenshot") { | |
let generatedImage = self.takeScreenshot( |
NewerOlder