Skip to content

Commit 1c9e3e9

Browse files
authored
Merge pull request #2 from renaudjenny/add-widget-to-tell-time
Add widget to tell time
2 parents 95b62c0 + ce98a7f commit 1c9e3e9

File tree

8 files changed

+316
-15
lines changed

8 files changed

+316
-15
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ A tiny iOS Swift project with SwiftUI.
66

77
📲 App Store: https://apps.apple.com/gb/app/tell-time-uk/id1496541173
88

9+
## Features
10+
11+
👾 Today Widget gives you the current time
12+
913
## Minimum required
1014

1115
Works with Xcode 11.
@@ -15,3 +19,4 @@ Works with Xcode 11.
1519
* ✅ Deploy on real iOS device
1620
* ✅ Add an icon
1721
* ✅ Improve UI for iPad format
22+
* 🛠 Improve the documentation by giving some features of the app

telltime.xcodeproj/project.pbxproj

+192-1
Large diffs are not rendered by default.

telltime.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
"version": "1.7.2"
1111
}
1212
},
13+
{
14+
"package": "SwiftClockUI",
15+
"repositoryURL": "https://github.com/renaudjenny/SwiftClockUI",
16+
"state": {
17+
"branch": null,
18+
"revision": "9a099cf9e7dca0fb375339a0dc6beaf12da2c0a5",
19+
"version": "0.0.1"
20+
}
21+
},
1322
{
1423
"package": "SwiftPastTen",
1524
"repositoryURL": "https://github.com/renaudjenny/SwiftPastTen",

telltime.xcodeproj/xcuserdata/renaudjenny.xcuserdatad/xcschemes/xcschememanagement.plist

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
<key>orderHint</key>
1010
<integer>0</integer>
1111
</dict>
12+
<key>widget.xcscheme_^#shared#^_</key>
13+
<dict>
14+
<key>orderHint</key>
15+
<integer>1</integer>
16+
</dict>
1217
</dict>
1318
<key>SuppressBuildableAutocreation</key>
1419
<dict>

telltime/TTS/Engine.swift

-14
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,3 @@ extension TTS {
5252
}
5353
}
5454
}
55-
56-
private extension String {
57-
static func fromDate(_ date: Date) -> String {
58-
let minute = Current.calendar.component(.minute, from: date)
59-
let hour = Current.calendar.component(.hour, from: date)
60-
return Self.fromHour(hour, minute: minute)
61-
}
62-
63-
private static func fromHour(_ hour: Int, minute: Int) -> String {
64-
let minute = minute > 9 ? "\(minute)" : "0\(minute)"
65-
let hour = hour > 9 ? "\(hour)" : "0\(hour)"
66-
return "\(hour):\(minute)"
67-
}
68-
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="M4Y-Lb-cyx">
3+
<device id="retina6_1" orientation="portrait" appearance="light"/>
4+
<dependencies>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
6+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
7+
</dependencies>
8+
<scenes>
9+
<!--Today View Controller-->
10+
<scene sceneID="cwh-vc-ff4">
11+
<objects>
12+
<viewController id="M4Y-Lb-cyx" customClass="TodayViewController" customModule="widget" customModuleProvider="target" sceneMemberID="viewController">
13+
<containerView key="view" opaque="NO" contentMode="scaleToFill" id="3qR-hO-pfc">
14+
<rect key="frame" x="0.0" y="0.0" width="320" height="37"/>
15+
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
16+
<connections>
17+
<segue destination="0HF-20-t4C" kind="embed" destinationCreationSelector="addSwiftUIView:" id="aRs-pY-MNf"/>
18+
</connections>
19+
</containerView>
20+
<extendedEdge key="edgesForExtendedLayout"/>
21+
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
22+
<size key="freeformSize" width="320" height="37"/>
23+
</viewController>
24+
<placeholder placeholderIdentifier="IBFirstResponder" id="vXp-U4-Rya" userLabel="First Responder" sceneMemberID="firstResponder"/>
25+
</objects>
26+
<point key="canvasLocation" x="137.68115942028987" y="76.674107142857139"/>
27+
</scene>
28+
<!--Hosting Controller-->
29+
<scene sceneID="Mag-LX-eTl">
30+
<objects>
31+
<hostingController id="0HF-20-t4C" sceneMemberID="viewController"/>
32+
<placeholder placeholderIdentifier="IBFirstResponder" id="2CL-jK-0UM" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
33+
</objects>
34+
<point key="canvasLocation" x="796" y="76"/>
35+
</scene>
36+
</scenes>
37+
</document>

widget/Info.plist

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleDisplayName</key>
8+
<string>Tell Time UK</string>
9+
<key>CFBundleExecutable</key>
10+
<string>$(EXECUTABLE_NAME)</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>$(PRODUCT_NAME)</string>
17+
<key>CFBundlePackageType</key>
18+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
<key>NSExtension</key>
24+
<dict>
25+
<key>NSExtensionMainStoryboard</key>
26+
<string>MainInterface</string>
27+
<key>NSExtensionPointIdentifier</key>
28+
<string>com.apple.widget-extension</string>
29+
</dict>
30+
</dict>
31+
</plist>

widget/TodayViewController.swift

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import UIKit
2+
import NotificationCenter
3+
import SwiftUI
4+
import SwiftPastTen
5+
import SwiftClockUI
6+
7+
// SwiftUI for Today Widget:
8+
// https://medium.com/@code_cookies/swiftui-embed-swiftui-view-into-the-storyboard-a6fc96e7a0a1
9+
10+
struct WidgetView: View {
11+
@Environment(\.calendar) var calendar
12+
13+
var body: some View {
14+
HStack {
15+
ClockView().allowsHitTesting(false)
16+
Spacer()
17+
Text(time)
18+
Spacer()
19+
}.padding()
20+
}
21+
22+
private var time: String {
23+
let formattedDate = SwiftPastTen.formattedDate(Date(), calendar: calendar)
24+
guard let time = try? SwiftPastTen().tell(time: formattedDate) else {
25+
return "Error"
26+
}
27+
return time
28+
}
29+
}
30+
31+
class TodayViewController: UIViewController, NCWidgetProviding {
32+
@IBSegueAction func addSwiftUIView(_ coder: NSCoder) -> UIViewController? {
33+
let viewController = UIHostingController(coder: coder, rootView: WidgetView())
34+
viewController?.view.backgroundColor = .clear
35+
return viewController
36+
}
37+
}

0 commit comments

Comments
 (0)