Skip to content

Commit 8b3313a

Browse files
committed
Update example to leverage ios 15 format
1 parent 2e5dcae commit 8b3313a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

TipCalculator/TipCalculator.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
isa = PBXProject;
103103
attributes = {
104104
LastSwiftUpdateCheck = 1100;
105-
LastUpgradeCheck = 1100;
105+
LastUpgradeCheck = 1340;
106106
ORGANIZATIONNAME = "Fickle Bits";
107107
TargetAttributes = {
108108
B5508B8F22B41C70001AB895 = {
@@ -192,6 +192,7 @@
192192
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
193193
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
194194
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
195+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
195196
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
196197
CLANG_WARN_STRICT_PROTOTYPES = YES;
197198
CLANG_WARN_SUSPICIOUS_MOVE = YES;
@@ -252,6 +253,7 @@
252253
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
253254
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
254255
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
256+
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
255257
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
256258
CLANG_WARN_STRICT_PROTOTYPES = YES;
257259
CLANG_WARN_SUSPICIOUS_MOVE = YES;

TipCalculator/TipCalculator/ContentView.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct ContentView : View {
5252
VStack(spacing: 20) {
5353
Spacer()
5454

55-
TextField("Total", value: $totalInput, formatter: currencyFormatter)
55+
totalTextField
5656
.font(.largeTitle)
5757
.padding()
5858
.background(Color.white)
@@ -75,6 +75,15 @@ struct ContentView : View {
7575
.navigationBarTitle(Text("Tip Calculator"))
7676
}
7777
}
78+
79+
private var totalTextField: some View {
80+
let currencyCode = Locale.current.currencyCode ?? "USD"
81+
if #available(iOS 15.0, *) {
82+
return TextField("Total", value: $totalInput, format: .currency(code: currencyCode))
83+
} else {
84+
return TextField("Total", value: $totalInput, formatter: currencyFormatter)
85+
}
86+
}
7887

7988
private func summaryLine(label: String, amount: String, color: Color) -> some View {
8089
HStack {
@@ -90,8 +99,8 @@ struct ContentView : View {
9099

91100
private var segmentedTipPercentages: some View {
92101
Picker(selection: $selectedTipPercentage, label: Text("")) {
93-
ForEach(0..<tipPercentages.count) { index in
94-
Text(self.formatPercent(self.tipPercentages[index])).tag(index)
102+
ForEach(tipPercentages.indices, id: \.self) { index in
103+
Text(formatPercent(tipPercentages[index])).tag(index)
95104
}
96105
}.pickerStyle(SegmentedPickerStyle())
97106
}

0 commit comments

Comments
 (0)