-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from nonstrict-hq/update
Refactor internals
- Loading branch information
Showing
48 changed files
with
377 additions
and
634 deletions.
There are no files selected for viewing
237 changes: 117 additions & 120 deletions
237
...dStorage-tvOS13.xcodeproj/project.pbxproj → ...torage-Example2.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 3 additions & 1 deletion
4
...stacklayer/Content.imageset/Contents.json → ...xcassets/AppIcon.appiconset/Contents.json
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "tv" | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
|
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions
17
Examples/CloudStorage-Example2/CloudStorage-Example2/CloudStorage_Example2App.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,17 @@ | ||
// | ||
// CloudStorage_Example2App.swift | ||
// Untitled 1 | ||
// | ||
// Created by Nonstrict on 2023-04-20. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@main | ||
struct CloudStorage_Example2App: App { | ||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
Examples/CloudStorage-Example2/CloudStorage-Example2/ContentView.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,73 @@ | ||
// | ||
// ContentView.swift | ||
// Untitled 1 | ||
// | ||
// Created by Nonstrict on 2023-04-20. | ||
// | ||
|
||
import SwiftUI | ||
import CloudStorage | ||
|
||
struct ContentView: View { | ||
|
||
var body: some View { | ||
NavigationStack { | ||
NavigationLink("Detail") { | ||
DetailView() | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
struct DetailView: View { | ||
|
||
|
||
var body: some View { | ||
VStack { | ||
TopView() | ||
Divider() | ||
MiddleView() | ||
Divider() | ||
BottomView() | ||
} | ||
.padding() | ||
} | ||
} | ||
|
||
|
||
struct TopView: View { | ||
@CloudStorage("myBool") var myBool = false | ||
|
||
var body: some View { | ||
Toggle("My Bool", isOn: $myBool) | ||
} | ||
} | ||
|
||
struct MiddleView: View { | ||
@CloudStorage("myBool") var myBool = false | ||
|
||
var body: some View { | ||
Toggle("My Bool", isOn: $myBool) | ||
} | ||
} | ||
|
||
struct BottomView: View { | ||
@StateObject var viewModel = ViewModel() | ||
|
||
var body: some View { | ||
Toggle("My Bool", isOn: $viewModel.myBool) | ||
|
||
Button("Toggle") { viewModel.myBool.toggle() } | ||
} | ||
} | ||
|
||
class ViewModel: ObservableObject { | ||
@CloudStorage("myBool") var myBool = false | ||
} | ||
|
||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView() | ||
} | ||
} |
File renamed without changes.
38 changes: 0 additions & 38 deletions
38
Examples/CloudStorage-iOS13/CloudStorage-iOS13/CloudStorage+Codable.swift
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
Examples/CloudStorage-iOS14/CloudStorage-iOS14/CloudStorage+Codable.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,37 @@ | ||
// | ||
// CloudStorage+Codable.swift | ||
// CloudStorage-iOS14 | ||
// | ||
// Created by Tom Lokhorst on 2020-07-18. | ||
// | ||
|
||
import SwiftUI | ||
import CloudStorage | ||
|
||
private let sync = CloudStorageSync.shared | ||
|
||
extension CloudStorage where Value: Codable { | ||
public init(wrappedValue: Value, _ key: String) { | ||
func syncGet() -> Value { | ||
guard let data = sync.data(for: key) else { return wrappedValue } | ||
do { | ||
let decoder = PropertyListDecoder() | ||
let value = try decoder.decode(Value.self, from: data) | ||
return value | ||
} catch { | ||
assertionFailure("\(error)") | ||
return wrappedValue | ||
} | ||
} | ||
func syncSet(_ newValue: Value) { | ||
do { | ||
let encoder = PropertyListEncoder() | ||
let data = try encoder.encode(newValue) | ||
sync.set(data, for: key) | ||
} catch { | ||
assertionFailure("\(error)") | ||
} | ||
} | ||
self.init(keyName: key, syncGet: syncGet, syncSet: syncSet) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...OS13/CloudStorage-iOS13/ContentView.swift → ...OS14/CloudStorage-iOS14/ContentView.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
2 changes: 1 addition & 1 deletion
2
...ge-iOS13/CloudStorage-iOS13/MyColor.swift → ...ge-iOS14/CloudStorage-iOS14/MyColor.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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// | ||
// MyColor.swift | ||
// CloudStorage-iOS13 | ||
// CloudStorage-iOS14 | ||
// | ||
// Created by Tom Lokhorst on 2020-07-18. | ||
// | ||
|
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...Storage-iOS13/Resources/AppDelegate.swift → ...Storage-iOS14/Resources/AppDelegate.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...orage-iOS13/Resources/SceneDelegate.swift → ...orage-iOS14/Resources/SceneDelegate.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
Oops, something went wrong.