-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 73d780e
Showing
15 changed files
with
1,397 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
Clocks.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
Clocks.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
25 changes: 25 additions & 0 deletions
25
Clocks.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
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,25 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "swift-algorithms", | ||
"repositoryURL": "https://github.com/apple/swift-algorithms.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "2327673b0e9c7e90e6b1826376526ec3627210e4", | ||
"version": "0.2.1" | ||
} | ||
}, | ||
{ | ||
"package": "swift-numerics", | ||
"repositoryURL": "https://github.com/apple/swift-numerics", | ||
"state": { | ||
"branch": null, | ||
"revision": "6583ac70c326c3ee080c1d42d9ca3361dca816cd", | ||
"version": "0.1.0" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
19 changes: 19 additions & 0 deletions
19
Clocks.xcodeproj/xcuserdata/harshil.xcuserdatad/xcschemes/xcschememanagement.plist
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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>SchemeUserState</key> | ||
<dict> | ||
<key>Clocks (iOS).xcscheme_^#shared#^_</key> | ||
<dict> | ||
<key>orderHint</key> | ||
<integer>1</integer> | ||
</dict> | ||
<key>Clocks (macOS).xcscheme_^#shared#^_</key> | ||
<dict> | ||
<key>orderHint</key> | ||
<integer>0</integer> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
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,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
148 changes: 148 additions & 0 deletions
148
Shared/Assets.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 |
---|---|---|
@@ -0,0 +1,148 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "60x60" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "60x60" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "76x76" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "76x76" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "83.5x83.5" | ||
}, | ||
{ | ||
"idiom" : "ios-marketing", | ||
"scale" : "1x", | ||
"size" : "1024x1024" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "512x512" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "512x512" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
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,57 @@ | ||
// | ||
// Clock.swift | ||
// Clock | ||
// | ||
// Created by Harshil Shah on 25/08/21. | ||
// | ||
|
||
import Combine | ||
import SwiftUI | ||
|
||
final class ClockViewModel: ObservableObject { | ||
@Published var formattedTime = FormattedTime(time: Date()) | ||
|
||
private var cancellable: AnyCancellable? | ||
|
||
init(client: ClockClient) { | ||
cancellable = client.time() | ||
.map(FormattedTime.init) | ||
.receive(on: DispatchQueue.main) | ||
.sink { newTime in | ||
withAnimation { | ||
self.formattedTime = newTime | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct Clock: View { | ||
@ObservedObject var viewModel: ClockViewModel | ||
|
||
var body: some View { | ||
VStack { | ||
HStack { | ||
Digit(digit: viewModel.formattedTime.hours.0) | ||
Digit(digit: viewModel.formattedTime.hours.1) | ||
} | ||
HStack { | ||
Digit(digit: viewModel.formattedTime.minutes.0) | ||
Digit(digit: viewModel.formattedTime.minutes.1) | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct Clock_Previews: PreviewProvider { | ||
struct ClockPreview: View { | ||
@StateObject var viewModel = ClockViewModel(client: .random) | ||
|
||
var body: some View { | ||
Clock(viewModel: viewModel) | ||
} | ||
} | ||
|
||
static var previews: some View { | ||
ClockPreview() | ||
} | ||
} |
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,32 @@ | ||
// | ||
// ClockClient.swift | ||
// ClockClient | ||
// | ||
// Created by Harshil Shah on 25/08/21. | ||
// | ||
|
||
import Combine | ||
import Foundation | ||
|
||
struct ClockClient { | ||
var time: () -> AnyPublisher<Date, Never> | ||
} | ||
|
||
extension ClockClient { | ||
static var live: ClockClient { | ||
ClockClient { | ||
Timer.publish(every: 60, tolerance: nil, on: .main, in: .default, options: nil) | ||
.autoconnect() | ||
.eraseToAnyPublisher() | ||
} | ||
} | ||
|
||
static var random: ClockClient { | ||
ClockClient { | ||
Timer.publish(every: 2, tolerance: nil, on: .main, in: .default, options: nil) | ||
.autoconnect() | ||
.map { _ in Date(timeIntervalSinceNow: .random(in: 0 ... 86400)) } | ||
.eraseToAnyPublisher() | ||
} | ||
} | ||
} |
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 @@ | ||
// | ||
// ClocksApp.swift | ||
// Shared | ||
// | ||
// Created by Harshil Shah on 25/08/21. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@main | ||
struct ClocksApp: App { | ||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
} | ||
} | ||
} |
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,18 @@ | ||
// | ||
// ContentView.swift | ||
// Shared | ||
// | ||
// Created by Harshil Shah on 25/08/21. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
@StateObject var clockViewModel = ClockViewModel(client: .live) | ||
|
||
var body: some View { | ||
Clock(viewModel: clockViewModel) | ||
.padding() | ||
.frame(minWidth: 400) | ||
} | ||
} |
Oops, something went wrong.