-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feature/AppStorage development is done #69
Open
David-Acc
wants to merge
3
commits into
rakutentech:master
Choose a base branch
from
David-Acc:feature/AppStorage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
189 changes: 189 additions & 0 deletions
189
Example/AltSwiftUIExample/ExampleViews/AppStorageExampleView.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
// | ||
// AppStorageExampleView.swift | ||
// AltSwiftUIExample | ||
// | ||
// Created by yang.q.wang on 2021/3/1. | ||
// Copyright © 2021 Rakuten Travel. All rights reserved. | ||
// | ||
|
||
import AltSwiftUI | ||
|
||
enum Day: Int { | ||
case Monday,Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday | ||
} | ||
enum Country: String { | ||
case China = "China" | ||
case Japan = "Japan" | ||
} | ||
struct AppStorageExampleView: View { | ||
var viewStore = ViewValues() | ||
@AppStorage("username" , store:UserDefaults(suiteName: "com.rakuten.www")) var username = "David" | ||
|
||
|
||
@AppStorage("optionalBool") var optionalBool: Bool? | ||
// @AppStorage("optionalInt") var optionalInt: Int? | ||
// @AppStorage("optionalDouble") var optionalDouble: Double? | ||
// @AppStorage("optionalString") var optionalString:String? | ||
// @AppStorage("optionalUrl") var optionalUrl:URL? | ||
// @AppStorage("optionalData") var optionalData:Data? | ||
// | ||
// @AppStorage("initalBool") var initalBool = false | ||
@AppStorage("initalInt") var initalInt = 100 | ||
// @AppStorage("initalDouble") var initalDouble = 100 | ||
// @AppStorage("initalString") var initalString = 100 | ||
// @AppStorage("initalUrl") var initalUrl = URL(string: "http://youtube.com")! | ||
// @AppStorage("initalData") var initalData = "AltSwiftUI AppStorage".data(using: .utf8)! | ||
// | ||
@AppStorage("today") var today = Day.Monday | ||
var body: View { | ||
VStack { | ||
Text("\(self.username)") | ||
TextField("Please enter your name", text: $username) | ||
|
||
|
||
HStack{ | ||
if let tempOptionalBool = self.optionalBool { | ||
if tempOptionalBool { | ||
Text("I am optionalBool variable and I am true").multilineTextAlignment(.leading) | ||
}else{ | ||
Text("I am optionalBool variable and I am false").multilineTextAlignment(.leading) | ||
} | ||
}else{ | ||
Text("I am optionalBool variable and I am nil").multilineTextAlignment(.leading) | ||
} | ||
Spacer() | ||
Button("Set Value") { | ||
if self.optionalBool == nil { | ||
self.optionalBool = true | ||
}else{ | ||
self.optionalBool = !self.optionalBool! | ||
} | ||
} | ||
}.padding() | ||
HStack{ | ||
|
||
switch self.today { | ||
case .Monday: | ||
Text("I am Enum variable and today is Monday").multilineTextAlignment(.leading) | ||
case .Tuesday: | ||
Text("I am Enum variable and today is Tuesday").multilineTextAlignment(.leading) | ||
case .Wednesday: | ||
Text("I am Enum variable and today is Wednesday").multilineTextAlignment(.leading) | ||
case .Thursday: | ||
Text("I am Enum variable and today is Thursday").multilineTextAlignment(.leading) | ||
case .Friday: | ||
Text("I am Enum variable and today is Friday").multilineTextAlignment(.leading) | ||
case .Saturday: | ||
Text("I am Enum variable and today is Saturday").multilineTextAlignment(.leading) | ||
case .Sunday: | ||
Text("I am Enum variable and today is Sunday").multilineTextAlignment(.leading) | ||
} | ||
Spacer() | ||
Button("Set Value") { | ||
if self.today.rawValue < 6{ | ||
self.today = Day(rawValue: self.today.rawValue + 1)! | ||
}else{ | ||
self.today = .Monday | ||
} | ||
|
||
} | ||
}.padding() | ||
|
||
HStack{ | ||
Text("I am IntialInt variable and value is \(self.initalInt)").multilineTextAlignment(.leading) | ||
Spacer() | ||
Button("Set Value") { | ||
self.initalInt += 20 | ||
} | ||
}.padding() | ||
/*HStack{ | ||
if let tempOptionalInt = self.optionalInt { | ||
Text("I am optionalInt variable and I am \(tempOptionalInt)").multilineTextAlignment(.leading) | ||
}else{ | ||
Text("I am optionalInt variable and I am nil").multilineTextAlignment(.leading) | ||
} | ||
Spacer() | ||
Button("Set Value") { | ||
if self.optionalInt == nil { | ||
self.optionalInt = 0 | ||
}else{ | ||
self.optionalInt = self.optionalInt! + 1 | ||
} | ||
} | ||
}.padding() | ||
HStack{ | ||
if let tempOptionalDouble = self.optionalDouble { | ||
Text("I am optionalDouble variable and I am \(tempOptionalDouble)").multilineTextAlignment(.leading) | ||
}else{ | ||
Text("I am optionalDouble variable and I am nil").multilineTextAlignment(.leading) | ||
} | ||
Spacer() | ||
Button("Set Value") { | ||
if self.optionalDouble == nil { | ||
self.optionalDouble = 0.1 | ||
}else{ | ||
self.optionalDouble = self.optionalDouble! + 0.1 | ||
} | ||
} | ||
}.padding() | ||
HStack{ | ||
if let tempOptionalString = self.optionalString { | ||
Text("I am optionalString variable and I am \(tempOptionalString)").multilineTextAlignment(.leading) | ||
}else{ | ||
Text("I am optionalString variable and I am nil").multilineTextAlignment(.leading) | ||
} | ||
Spacer() | ||
Button("Set Value") { | ||
if self.optionalString == nil { | ||
self.optionalString = "Text Value" | ||
}else{ | ||
self.optionalString = self.optionalString! + "|A|" | ||
} | ||
} | ||
}.padding() | ||
HStack{ | ||
if let tempOptionalUrl = self.optionalUrl { | ||
Text("I am optionalUrl variable and I am \(tempOptionalUrl)").multilineTextAlignment(.leading) | ||
}else{ | ||
Text("I am optionalUrl variable and I am nil").multilineTextAlignment(.leading) | ||
} | ||
Spacer() | ||
Button("Set Value") { | ||
if self.optionalUrl == nil { | ||
self.optionalUrl = URL(string: "https://google.com") | ||
}else{ | ||
self.optionalUrl = URL(string: "https://apple.com") | ||
} | ||
} | ||
}.padding() | ||
HStack{ | ||
if let tempOptionalData = self.optionalData { | ||
Text("I am optionalData variable and I am \(String(data: tempOptionalData, encoding: .utf8)!)").multilineTextAlignment(.leading) | ||
}else{ | ||
Text("I am optionalData variable and I am nil").multilineTextAlignment(.leading) | ||
} | ||
Spacer() | ||
Button("Set Value") { | ||
if self.optionalData == nil { | ||
self.optionalData = "123456789".data(using: .utf8) | ||
}else{ | ||
self.optionalData = "abcdefg".data(using: .utf8) | ||
} | ||
} | ||
}.padding() | ||
Text("Inital Value Demo").multilineTextAlignment(.center).background(.red).font(Font.largeTitle) | ||
HStack{ | ||
if self.initalBool { | ||
Text("I am InitalBool variable and I am true").multilineTextAlignment(.leading) | ||
}else{ | ||
Text("I am InitalBool variable and I am false").multilineTextAlignment(.leading) | ||
} | ||
Spacer() | ||
Button("Set Value") { | ||
self.initalBool = !self.initalBool | ||
} | ||
}.padding()*/ | ||
} | ||
} | ||
} | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot of commented code. This can get confusing so it's better to remove if not needed.