Skip to content

Commit 6c6d834

Browse files
committed
Format
1 parent 5553a4d commit 6c6d834

File tree

38 files changed

+303
-298
lines changed

38 files changed

+303
-298
lines changed

Examples/CaseStudies/CaseStudies/CaseStudiesApp.swift

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import DependenciesAdditions
22
import SwiftUI
3+
34
#if canImport(UIKit)
4-
import UIKit
5+
import UIKit
56
#endif
67

78
@main
@@ -12,23 +13,23 @@ struct Case_StudiesApp: App {
1213
model: withDependencies {
1314
$0.persistentContainer = .default(inMemory: true).withInitialData()
1415
#if targetEnvironment(simulator)
15-
// Note: This will emit warnings, as using these `$` accessors should only
16-
// be used for previews and testing, but we do so here because the following
17-
// values are undefined when running on the simulator.
18-
// We are furthermore forced to perform a `context` danse to avoid emitting
19-
// runtime warning, as one shouldn't access `$` device properties
20-
// in a `live` context. So we temporarily switch to a `preview` context
21-
// to avoid the warning when we access the values two lines below.
22-
var dependencies = $0
23-
withDependencies { inner in
24-
inner.context = .preview
25-
} operation: {
26-
dependencies.device.$batteryLevel = 0.72
27-
dependencies.device.$batteryState = UIDevice.BatteryState.charging
28-
}
29-
$0 = dependencies
30-
$0.device.$isBatteryMonitoringEnabled = .constant(true)
31-
$0.context = .live
16+
// Note: This will emit warnings, as using these `$` accessors should only
17+
// be used for previews and testing, but we do so here because the following
18+
// values are undefined when running on the simulator.
19+
// We are furthermore forced to perform a `context` danse to avoid emitting
20+
// runtime warning, as one shouldn't access `$` device properties
21+
// in a `live` context. So we temporarily switch to a `preview` context
22+
// to avoid the warning when we access the values two lines below.
23+
var dependencies = $0
24+
withDependencies { inner in
25+
inner.context = .preview
26+
} operation: {
27+
dependencies.device.$batteryLevel = 0.72
28+
dependencies.device.$batteryState = UIDevice.BatteryState.charging
29+
}
30+
$0 = dependencies
31+
$0.device.$isBatteryMonitoringEnabled = .constant(true)
32+
$0.context = .live
3233
#endif
3334
} operation: {
3435
.init()

Examples/CaseStudies/CaseStudies/Studies/CompressionStudy.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct CompressionStudyView: View {
6666
} header: {
6767
Text("Text")
6868
} footer: {
69-
Gauge(value: max(1 - model.compressionRatio, 0), in: 0 ... 1) {
69+
Gauge(value: max(1 - model.compressionRatio, 0), in: 0...1) {
7070
Text("Compression Ratio")
7171
} currentValueLabel: {
7272
Text(model.compressionRatio.formatted(.percent.precision(.fractionLength(0))))
@@ -103,7 +103,7 @@ struct CompressionStudyView: View {
103103
#if os(iOS)
104104
.listStyle(.grouped)
105105
#endif
106-
.navigationTitle("Codable & Compression")
106+
.navigationTitle("Codable & Compression")
107107
}
108108
}
109109

@@ -112,14 +112,14 @@ struct CompressionStudyView_Previews: PreviewProvider {
112112
NavigationStack {
113113
CompressionStudyView(
114114
model:
115-
withDependencies {
116-
let encoder = JSONEncoder()
117-
encoder.outputFormatting.insert(.prettyPrinted)
118-
encoder.outputFormatting.insert(.sortedKeys)
119-
$0.encode = DataEncoder(encoder)
120-
} operation: {
121-
.init()
122-
}
115+
withDependencies {
116+
let encoder = JSONEncoder()
117+
encoder.outputFormatting.insert(.prettyPrinted)
118+
encoder.outputFormatting.insert(.sortedKeys)
119+
$0.encode = DataEncoder(encoder)
120+
} operation: {
121+
.init()
122+
}
123123
)
124124
}
125125
}

Examples/CaseStudies/CaseStudies/Studies/CoreDataStudy.swift

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import _CoreDataDependency
2-
import _SwiftUIDependency
31
import Dependencies
42
import SwiftUI
53
import SwiftUINavigation
4+
import _CoreDataDependency
5+
import _SwiftUIDependency
6+
67
@MainActor
78
final class CoreDataStudy: ObservableObject {
89
enum Destination {
@@ -159,7 +160,9 @@ struct CoreDataStudyView: View {
159160
}
160161
}
161162
} header: {
162-
Text("^[\(songsByYear.count) \("song")](inflect: true) from \(songsByYear.id.formatted(.number.grouping(.never)))")
163+
Text(
164+
"^[\(songsByYear.count) \("song")](inflect: true) from \(songsByYear.id.formatted(.number.grouping(.never)))"
165+
)
163166
}
164167
}
165168
}
@@ -234,7 +237,7 @@ struct AddSongView: View {
234237
var body: some View {
235238
Form {
236239
TextField("Name", text: $model.song.editor.name.emptyIfNil())
237-
Stepper(value: $model.song.editor.year, in: 1960 ... 1970) {
240+
Stepper(value: $model.song.editor.year, in: 1960...1970) {
238241
LabeledContent("Year", value: "\(model.song.year)")
239242
}
240243
}
@@ -260,46 +263,46 @@ struct CoreDataStudyView_Previews: PreviewProvider {
260263
NavigationStack {
261264
CoreDataStudyView(
262265
model:
263-
withDependencies {
264-
$0.persistentContainer = .default(inMemory: true).withInitialData()
265-
} operation: {
266-
CoreDataStudy()
267-
}
266+
withDependencies {
267+
$0.persistentContainer = .default(inMemory: true).withInitialData()
268+
} operation: {
269+
CoreDataStudy()
270+
}
268271
)
269272
}
270273

271274
// TODO: Having two previews creates navigation glitches.
272-
// NavigationStack {
273-
// AddSongView(
274-
// model:
275-
// withDependencies {
276-
// $0.persistentContainer = .canonical(inMemory: true).withInitialData()
277-
// $0.uuid = .incrementing
278-
// } operation: {
279-
// @Dependency(\.persistentContainer) var persistentContainer
280-
// @Dependency(\.uuid) var uuid
281-
//
282-
// return AddSongModel(song: try! persistentContainer.insert(Song.self) {
283-
// $0.identifier = uuid()
284-
// $0.year = 1970
285-
// $0.name = "Let it be"
286-
// })
287-
// }
288-
// )
289-
// }
275+
// NavigationStack {
276+
// AddSongView(
277+
// model:
278+
// withDependencies {
279+
// $0.persistentContainer = .canonical(inMemory: true).withInitialData()
280+
// $0.uuid = .incrementing
281+
// } operation: {
282+
// @Dependency(\.persistentContainer) var persistentContainer
283+
// @Dependency(\.uuid) var uuid
284+
//
285+
// return AddSongModel(song: try! persistentContainer.insert(Song.self) {
286+
// $0.identifier = uuid()
287+
// $0.year = 1970
288+
// $0.name = "Let it be"
289+
// })
290+
// }
291+
// )
292+
// }
290293
}
291294
}
292295

293-
public extension Binding {
294-
func nilIfEmpty() -> Binding<Value?> where Value: RangeReplaceableCollection {
296+
extension Binding {
297+
public func nilIfEmpty() -> Binding<Value?> where Value: RangeReplaceableCollection {
295298
Binding<Value?> {
296299
self.wrappedValue.isEmpty ? nil : self.wrappedValue
297300
} set: { newValue, _ in
298301
self.transaction(transaction).wrappedValue = newValue ?? .init()
299302
}
300303
}
301304

302-
func emptyIfNil<T>() -> Binding<T> where Value == T?, T: RangeReplaceableCollection {
305+
public func emptyIfNil<T>() -> Binding<T> where Value == T?, T: RangeReplaceableCollection {
303306
Binding<T> {
304307
self.wrappedValue ?? .init()
305308
} set: { newValue, _ in

0 commit comments

Comments
 (0)