Skip to content

Commit 25819bc

Browse files
committed
Add initial package
0 parents  commit 25819bc

10 files changed

+221
-0
lines changed

.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## Xcode
2+
.DS_Store
3+
4+
## Build generated
5+
build/
6+
DerivedData/
7+
build.log
8+
9+
## Various settings
10+
*.pbxuser
11+
!default.pbxuser
12+
*.mode1v3
13+
!default.mode1v3
14+
*.mode2v3
15+
!default.mode2v3
16+
*.perspectivev3
17+
!default.perspectivev3
18+
xcuserdata/
19+
20+
## Other
21+
*.moved-aside
22+
*.xcuserstate
23+
24+
## Obj-C/Swift specific
25+
*.hmap
26+
*.ipa
27+
*.dSYM.zip
28+
*.dSYM
29+
30+
## Playgrounds
31+
timeline.xctimeline
32+
playground.xcworkspace
33+
34+
## Swift Package Manager
35+
.build/
36+
.swiftpm/

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2015-2022 SwifterSwift (https://github.com/swifterswift)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Package.swift

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// swift-tools-version: 5.6
2+
3+
import PackageDescription
4+
5+
// Add your modules here
6+
7+
let modules = [
8+
"Stdlib",
9+
"Foundation",
10+
]
11+
12+
let package = Package(
13+
name: "SwifterSwift",
14+
platforms: [
15+
.iOS(.v10),
16+
.macOS(.v10_10),
17+
.tvOS(.v9),
18+
.watchOS(.v2),
19+
],
20+
products: products(modules),
21+
targets: targets(modules)
22+
)
23+
24+
// MARK: - Private Helpers
25+
26+
private func products(_ modules: [String]) -> [Product] {
27+
let main = Product.library(name: "SwifterSwift", targets: ["SwifterSwift"])
28+
return [main] + modules.map(library(module:))
29+
}
30+
31+
func library(module: String) -> Product {
32+
.library(name: "Swifter\(module)", targets: ["Swifter\(module)"])
33+
}
34+
35+
func targets(_ modules: [String]) -> [Target] {
36+
let main = Target.target(
37+
name: "SwifterSwift",
38+
dependencies: modules.map { .init(stringLiteral: "Swifter\($0)") },
39+
path: "Sources/SwifterSwift"
40+
)
41+
return [main] + modules.map(target) + modules.map(testTarget)
42+
}
43+
44+
func target(module: String) -> Target {
45+
return Target.target(name: "Swifter\(module)", path: "Sources/\(module)")
46+
}
47+
48+
func testTarget(module: String) -> Target {
49+
return Target.testTarget(
50+
name: "\(module)Tests",
51+
dependencies: [.init(stringLiteral: "Swifter\(module)")],
52+
path: "Tests/\(module)"
53+
)
54+
}

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SwifterSwift v6
2+
3+
A temporary repository to serve as a PoC for SwifterSwift v6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#if canImport(Foundation)
2+
import Foundation
3+
4+
public extension Calendar {
5+
/// SwifterSwift: Return the number of days in the month for a specified 'Date'.
6+
///
7+
/// let date = Date() // "Jan 12, 2017, 7:07 PM"
8+
/// Calendar.current.numberOfDaysInMonth(for: date) -> 31
9+
///
10+
/// - Parameter date: the date form which the number of days in month is calculated.
11+
/// - Returns: The number of days in the month of 'Date'.
12+
func numberOfDaysInMonth(for date: Date) -> Int {
13+
return range(of: .day, in: .month, for: date)!.count
14+
}
15+
}
16+
#endif

Sources/Stdlib/BoolExtensions.swift

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public extension Bool {
2+
/// SwifterSwift: Return 1 if true, or 0 if false.
3+
///
4+
/// false.int -> 0
5+
/// true.int -> 1
6+
///
7+
var int: Int {
8+
return self ? 1 : 0
9+
}
10+
}
11+
12+
public extension Bool {
13+
/// SwifterSwift: Return "true" if true, or "false" if false.
14+
///
15+
/// false.string -> "false"
16+
/// true.string -> "true"
17+
///
18+
var string: String {
19+
return self ? "true" : "false"
20+
}
21+
}
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@_exported import SwifterStdlib
2+
@_exported import SwifterFoundation

SwifterSwift.podspec

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Pod::Spec.new do |s|
2+
s.name = 'SwifterSwift'
3+
s.version = '6.0.0'
4+
s.summary = 'A handy collection of native Swift extensions to boost your productivity.'
5+
s.homepage = 'https://github.com/SwifterSwift/SwifterSwift'
6+
s.license = { type: 'MIT', file: 'LICENSE' }
7+
s.documentation_url = 'http://swifterswift.com/docs'
8+
s.authors = { 'SwifterSwift Contributors' => 'https://github.com/SwifterSwift/SwifterSwift/graphs/contributors' }
9+
10+
s.ios.deployment_target = '10.0'
11+
s.osx.deployment_target = '10.10'
12+
s.tvos.deployment_target = '9.0'
13+
s.watchos.deployment_target = '2.0'
14+
15+
s.swift_versions = ['5.6']
16+
s.source = { git: 'https://github.com/SwifterSwift/SwifterSwift.git', tag: s.version.to_s }
17+
s.source_files = 'Sources/**/*.swift'
18+
19+
# SwiftStdlib Extensions
20+
s.subspec 'SwiftStdlib' do |sp|
21+
sp.source_files = 'Sources/Stdlib/*.swift'
22+
end
23+
24+
# Foundation Extensions
25+
s.subspec 'Foundation' do |sp|
26+
sp.source_files = 'Sources/Foundation/*.swift'
27+
end
28+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@testable import SwifterFoundation
2+
import XCTest
3+
4+
#if canImport(Foundation)
5+
import Foundation
6+
7+
final class CalendarExtensionTests: XCTestCase {
8+
func testNumberOfDaysInAMonth() {
9+
let calendar = Calendar(identifier: .gregorian)
10+
let longMonths = [1, 3, 5, 7, 8, 10, 12]
11+
let shortMonths = [4, 6, 9, 11]
12+
let febDateComponent = DateComponents(year: 2015, month: 2)
13+
let febDate = calendar.date(from: febDateComponent)!
14+
let leapYearDateComponent = DateComponents(year: 2020, month: 2)
15+
let leapYearDate = calendar.date(from: leapYearDateComponent)!
16+
let longMonthsDateComponents = longMonths.map { DateComponents(year: 2015, month: $0) }
17+
let shortMonthsDateComponents = shortMonths.map { DateComponents(year: 2015, month: $0) }
18+
let longMonthDates = longMonthsDateComponents.compactMap { calendar.date(from: $0) }
19+
let shortMonthDates = shortMonthsDateComponents.compactMap { calendar.date(from: $0) }
20+
longMonthDates.forEach { XCTAssertEqual(calendar.numberOfDaysInMonth(for: $0), 31) }
21+
shortMonthDates.forEach { XCTAssertEqual(calendar.numberOfDaysInMonth(for: $0), 30) }
22+
XCTAssertEqual(calendar.numberOfDaysInMonth(for: febDate), 28)
23+
XCTAssertEqual(calendar.numberOfDaysInMonth(for: leapYearDate), 29)
24+
}
25+
}
26+
#endif
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@testable import SwifterStdlib
2+
import XCTest
3+
4+
final class BoolExtensionsTests: XCTestCase {
5+
func testInt() {
6+
XCTAssertEqual(true.int, 1)
7+
XCTAssertEqual(false.int, 0)
8+
}
9+
10+
func testString() {
11+
XCTAssertEqual(true.string, "true")
12+
XCTAssertEqual(false.string, "false")
13+
}
14+
}

0 commit comments

Comments
 (0)