Skip to content

Commit 5084346

Browse files
ActivityAlertView Initializer (#10)
* Public Initializers on ActivityAlertView * Added SPI documentation; Updated Actions * Updated upload-artifact action
1 parent 2c355b1 commit 5084346

File tree

5 files changed

+41
-54
lines changed

5 files changed

+41
-54
lines changed

.github/workflows/swift.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
steps:
1717
- name: Checkout Source
18-
uses: actions/checkout@v3
18+
uses: actions/checkout@v4
1919

2020
- name: Build (macOS)
2121
run: swift build -v
@@ -27,20 +27,20 @@ jobs:
2727
run: xcrun llvm-cov export -format="lcov" .build/debug/${{ env.PACKAGE_NAME }}PackageTests.xctest/Contents/MacOS/${{ env.PACKAGE_NAME }}PackageTests -instr-profile .build/debug/codecov/default.profdata > build/reports/coverage.lcov
2828

2929
- name: Upload Artifacts
30-
uses: actions/upload-artifact@v3
30+
uses: actions/upload-artifact@v4
3131
with:
3232
name: test-results
3333
path: |
3434
build/reports/junit.xml
3535
build/reports/coverage.lcov
3636
3737
- name: Publish Test Results
38-
uses: EnricoMi/publish-unit-test-result-action/composite@v1
38+
uses: EnricoMi/publish-unit-test-result-action/macos@v2
3939
with:
4040
files: build/reports/junit.xml
4141

4242
- name: Publish Code Coverage
43-
uses: vebr/jest-lcov-reporter@v0.2.1
43+
uses: lifeart/jest-lcov-reporter@v0.4.0
4444
with:
4545
github-token: ${{ secrets.GITHUB_TOKEN }}
4646
lcov-file: build/reports/coverage.lcov
@@ -51,7 +51,7 @@ jobs:
5151

5252
steps:
5353
- name: Checkout Source
54-
uses: actions/checkout@v3
54+
uses: actions/checkout@v4
5555

5656
- name: Build (Ubuntu)
5757
run: swift build -v

.spi.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: 1
2+
builder:
3+
configs:
4+
- documentation_targets: [CodeQuickKit]

README.md

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,8 @@
22

33
A Swift library for simplifying some everyday tasks.
44

5-
<p>
6-
<img src="https://github.com/richardpiazza/CodeQuickKit/workflows/Swift/badge.svg?branch=main" />
7-
<img src="https://img.shields.io/badge/Swift-5.5-orange.svg" />
8-
<a href="https://twitter.com/richardpiazza">
9-
<img src="https://img.shields.io/badge/twitter-@richardpiazza-blue.svg?style=flat" alt="Twitter: @richardpiazza" />
10-
</a>
11-
</p>
12-
13-
## 💻 Installation
14-
15-
This software is distributed using [Swift Package Manager](https://swift.org/package-manager).
16-
You can add it using Xcode or by listing it as a dependency in your `Package.swift` manifest:
17-
18-
```swift
19-
let package = Package(
20-
...
21-
dependencies: [
22-
.package(url: "https://github.com/richardpiazza/CodeQuickKit", .upToNextMajor(from: "7.0.0")
23-
],
24-
...
25-
targets: [
26-
.target(
27-
name: "MyPackage",
28-
dependencies: [
29-
"CodeQuickKit"
30-
]
31-
)
32-
]
33-
)
34-
```
5+
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Frichardpiazza%2FCodeQuickKit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/richardpiazza/CodeQuickKit)
6+
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Frichardpiazza%2FCodeQuickKit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/richardpiazza/CodeQuickKit)
357

368
## 📌 Features
379

Sources/CodeQuickKit/SwiftUI/ActivityAlertView.swift

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,35 @@ import SwiftUI
88
public struct ActivityAlertView: UIViewControllerRepresentable {
99

1010
/// A binding to a Boolean value that determines whether to present the view.
11-
@Binding public var isPresented: Bool
11+
public let isPresented: Binding<Bool>
1212
/// The header text of the presented alert
13-
public let title: String?
13+
public let title: Binding<String>?
1414
/// The body text of the presented alert
15-
public let message: String?
15+
public let message: Binding<String>?
1616
/// Inset values that should be used in place of defaults.
17-
public var padding: EdgeInsets? = nil
17+
public let padding: EdgeInsets?
18+
19+
public init(isPresented: Binding<Bool>, title: String?, message: String?, padding: EdgeInsets? = nil) {
20+
self.isPresented = isPresented
21+
self.title = (title != nil) ? .constant(title!) : nil
22+
self.message = (message != nil) ? .constant(message!) : nil
23+
self.padding = padding
24+
}
25+
26+
public init(isPresented: Binding<Bool>, title: Binding<String>? = nil, message: Binding<String>? = nil, padding: EdgeInsets? = nil) {
27+
self.isPresented = isPresented
28+
self.title = title
29+
self.message = message
30+
self.padding = padding
31+
}
1832

1933
public func makeCoordinator() -> UIAlertController {
2034
var insets: UIEdgeInsets?
2135
if let padding = padding {
2236
insets = UIEdgeInsets(top: padding.top, left: padding.leading, bottom: padding.bottom, right: padding.trailing)
2337
}
2438

25-
return UIAlertController.makeActivityAlert(title: title, message: message, padding: insets)
39+
return UIAlertController.makeActivityAlert(title: title?.wrappedValue, message: message?.wrappedValue, padding: insets)
2640
}
2741

2842
public func makeUIViewController(context: Context) -> some UIViewController {
@@ -31,9 +45,14 @@ public struct ActivityAlertView: UIViewControllerRepresentable {
3145

3246
public func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
3347
let alertController = context.coordinator
34-
switch (isPresented, uiViewController.presentedViewController) {
48+
switch (isPresented.wrappedValue, uiViewController.presentedViewController) {
3549
case (true, nil):
50+
alertController.title = title?.wrappedValue
51+
alertController.message = message?.wrappedValue
3652
uiViewController.present(alertController, animated: true)
53+
case (true, _):
54+
alertController.title = title?.wrappedValue
55+
alertController.message = message?.wrappedValue
3756
case (false, alertController):
3857
alertController.dismiss(animated: true)
3958
default:

Tests/CodeQuickKitTests/Foundation/DateTests.swift

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,14 @@ class DateTests: XCTestCase {
4444
XCTAssertTrue(now.isSame(today))
4545
}
4646

47-
func testLastWeek() {
47+
func testLastWeek() throws {
4848
let now = Date()
4949
let lastWeek = Date.lastWeek
5050

5151
XCTAssertTrue(lastWeek.isBefore(now))
5252

53-
let offset = TimeZone.current.daylightSavingTimeOffset(for: lastWeek)
54-
let minutesToToday = 10080 + Int(offset / 60)
55-
56-
guard let today = lastWeek.dateByAdding(minutes: minutesToToday) else {
57-
XCTFail()
58-
return
59-
}
53+
let minutesToToday = 60 * 24 * 7
54+
let today = try XCTUnwrap(lastWeek.dateByAdding(minutes: minutesToToday))
6055

6156
XCTAssertTrue(today.isAfter(lastWeek))
6257
XCTAssertTrue(now.isSame(today))
@@ -92,16 +87,13 @@ class DateTests: XCTestCase {
9287
XCTAssertTrue(now.isSame(today))
9388
}
9489

95-
func testNextWeek() {
90+
func testNextWeek() throws {
9691
let now = Date()
9792
let nextWeek = Date.nextWeek
9893

9994
XCTAssertTrue(nextWeek.isAfter(now))
10095

101-
guard let today = nextWeek.dateByAdding(minutes: -10080) else {
102-
XCTFail()
103-
return
104-
}
96+
let today = try XCTUnwrap(nextWeek.dateByAdding(days: -7))
10597

10698
XCTAssertTrue(today.isBefore(nextWeek))
10799
XCTAssertTrue(now.isSame(today))

0 commit comments

Comments
 (0)