Skip to content

Commit

Permalink
just setting up my clocks
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshilShah committed Aug 25, 2021
0 parents commit 73d780e
Show file tree
Hide file tree
Showing 15 changed files with 1,397 additions and 0 deletions.
524 changes: 524 additions & 0 deletions Clocks.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Clocks.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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>
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
}
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>
11 changes: 11 additions & 0 deletions Shared/Assets.xcassets/AccentColor.colorset/Contents.json
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 Shared/Assets.xcassets/AppIcon.appiconset/Contents.json
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
}
}
6 changes: 6 additions & 0 deletions Shared/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
57 changes: 57 additions & 0 deletions Shared/Clock.swift
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()
}
}
32 changes: 32 additions & 0 deletions Shared/ClockClient.swift
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()
}
}
}
17 changes: 17 additions & 0 deletions Shared/ClocksApp.swift
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()
}
}
}
18 changes: 18 additions & 0 deletions Shared/ContentView.swift
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)
}
}
Loading

0 comments on commit 73d780e

Please sign in to comment.