Skip to content

Commit c694280

Browse files
committed
Improve code style
1 parent 7ae9278 commit c694280

15 files changed

+315
-221
lines changed

Example/Source/AppDelegate.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313

1414
var window: UIWindow?
1515

16-
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
16+
func application(
17+
_ application: UIApplication,
18+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
19+
) -> Bool {
1720
let vc = ViewController()
1821
let navVc = UINavigationController(rootViewController: vc)
1922
self.window = UIWindow(frame: UIScreen.main.bounds)

Example/Source/ViewController.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// Copyright © 2020 DIGITAL RETAIL TECHNOLOGIES, S.L. All rights reserved.
77
//
88

9-
import UIKit
109
import Fastis
10+
import UIKit
1111

1212
class ViewController: UIViewController {
1313

@@ -98,7 +98,8 @@ class ViewController: UIViewController {
9898

9999
// MARK: - Actions
100100

101-
@objc private func chooseRange() {
101+
@objc
102+
private func chooseRange() {
102103
let fastisController = FastisController(mode: .range)
103104
fastisController.title = "Choose range"
104105
fastisController.initialValue = self.currentValue as? FastisRange
@@ -112,7 +113,8 @@ class ViewController: UIViewController {
112113
fastisController.present(above: self)
113114
}
114115

115-
@objc private func chooseSingleDate() {
116+
@objc
117+
private func chooseSingleDate() {
116118
let fastisController = FastisController(mode: .single)
117119
fastisController.title = "Choose date"
118120
fastisController.initialValue = self.currentValue as? Date

Sources/Extensions/Calendar+LastWeekday.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//
22
// File.swift
3-
//
3+
//
44
//
55
// Created by Ilya Kharlamov on 9/12/22.
66
//
77

88
import Foundation
99

10-
internal extension Calendar {
10+
extension Calendar {
1111
var lastWeekday: Int {
1212
let numDays = self.weekdaySymbols.count
1313
let res = (self.firstWeekday + numDays - 1) % numDays

Sources/Extensions/Date+Utilities.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@
88

99
import Foundation
1010

11-
internal extension Date {
11+
extension Date {
1212

1313
func startOfMonth(in calendar: Calendar = .current) -> Date {
14-
return calendar.date(from: calendar.dateComponents([.year, .month], from: calendar.startOfDay(for: self)))!.startOfDay(in: calendar)
14+
calendar.date(from: calendar.dateComponents([.year, .month], from: calendar.startOfDay(for: self)))!.startOfDay(in: calendar)
1515
}
1616

1717
func endOfMonth(in calendar: Calendar = .current) -> Date {
18-
return calendar.date(byAdding: DateComponents(month: 1, day: -1), to: self.startOfMonth(in: calendar))!.endOfDay(in: calendar)
18+
calendar.date(byAdding: DateComponents(month: 1, day: -1), to: self.startOfMonth(in: calendar))!.endOfDay(in: calendar)
1919
}
2020

2121
func isInSameDay(in calendar: Calendar = .current, date: Date) -> Bool {
22-
return calendar.isDate(self, equalTo: date, toGranularity: .day)
22+
calendar.isDate(self, equalTo: date, toGranularity: .day)
2323
}
2424

2525
func isInSameMonth(in calendar: Calendar = .current, date: Date) -> Bool {
26-
return calendar.component(.month, from: self) == calendar.component(.month, from: date)
26+
calendar.component(.month, from: self) == calendar.component(.month, from: date)
2727
}
2828

2929
func startOfDay(in calendar: Calendar = .current) -> Date {
30-
return calendar.date(bySettingHour: 0, minute: 0, second: 0, of: self)!
30+
calendar.date(bySettingHour: 0, minute: 0, second: 0, of: self)!
3131
}
3232

3333
func endOfDay(in calendar: Calendar = .current) -> Date {
34-
return calendar.date(bySettingHour: 23, minute: 59, second: 59, of: self)!
34+
calendar.date(bySettingHour: 23, minute: 59, second: 59, of: self)!
3535
}
3636

3737
}

Sources/Extensions/String+CapitalizeFirstLetter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
import Foundation
1010

11-
internal extension String {
11+
extension String {
1212

1313
func capitalizingFirstLetter() -> String {
14-
return prefix(1).capitalized + dropFirst()
14+
prefix(1).capitalized + dropFirst()
1515
}
1616

1717
mutating func capitalizeFirstLetter() {

Sources/Models/Config.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ public struct FastisConfig {
1313

1414
/**
1515
The default configuration.
16-
16+
1717
Fastis can be customized global or local.
18-
18+
1919
Modify this variable to customize all Fastis controllers in your app:
2020
```swift
2121
FastisConfig.default.monthHeader.labelColor = .red
2222
```
23-
23+
2424
Or you can copy and modify this config for some special controller:
2525
```swift
2626
let config: FastisConfig = .default
@@ -30,11 +30,11 @@ public struct FastisConfig {
3030
*/
3131
public static var `default` = FastisConfig()
3232

33-
private init() {}
33+
private init() { }
3434

3535
/**
3636
Base calendar used to build a view
37-
37+
3838
Default value — `.current`
3939
*/
4040
public var calendar: Calendar = .current

Sources/Models/Shortcut.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import Foundation
2929
*/
3030
public struct FastisShortcut<Value: FastisValue>: Hashable {
3131

32-
private var id: UUID = UUID()
32+
private var id = UUID()
3333

3434
/// Display name of shortcut
3535
public var name: String
@@ -51,7 +51,7 @@ public struct FastisShortcut<Value: FastisValue>: Hashable {
5151
}
5252

5353
public static func == (lhs: FastisShortcut<Value>, rhs: FastisShortcut<Value>) -> Bool {
54-
return lhs.id == rhs.id
54+
lhs.id == rhs.id
5555
}
5656

5757
internal func isEqual(to value: Value) -> Bool {
@@ -65,28 +65,28 @@ public struct FastisShortcut<Value: FastisValue>: Hashable {
6565

6666
}
6767

68-
extension FastisShortcut where Value == FastisRange {
68+
public extension FastisShortcut where Value == FastisRange {
6969

7070
/// Range: from **`now.startOfDay`** to **`now.endOfDay`**
71-
public static var today: FastisShortcut {
72-
return FastisShortcut(name: "Today") {
71+
static var today: FastisShortcut {
72+
FastisShortcut(name: "Today") {
7373
let now = Date()
7474
return FastisRange(from: now.startOfDay(), to: now.endOfDay())
7575
}
7676
}
7777

7878
/// Range: from **`now.startOfDay - 7 days`** to **`now.endOfDay`**
79-
public static var lastWeek: FastisShortcut {
80-
return FastisShortcut(name: "Last week") {
79+
static var lastWeek: FastisShortcut {
80+
FastisShortcut(name: "Last week") {
8181
let now = Date()
8282
let weekAgo = Calendar.current.date(byAdding: .day, value: -7, to: now)!
8383
return FastisRange(from: weekAgo.startOfDay(), to: now.endOfDay())
8484
}
8585
}
8686

8787
/// Range: from **`now.startOfDay - 1 month`** to **`now.endOfDay`**
88-
public static var lastMonth: FastisShortcut {
89-
return FastisShortcut(name: "Last month") {
88+
static var lastMonth: FastisShortcut {
89+
FastisShortcut(name: "Last month") {
9090
let now = Date()
9191
let monthAgo = Calendar.current.date(byAdding: .month, value: -1, to: now)!
9292
return FastisRange(from: monthAgo.startOfDay(), to: now.endOfDay())
@@ -95,26 +95,26 @@ extension FastisShortcut where Value == FastisRange {
9595

9696
}
9797

98-
extension FastisShortcut where Value == Date {
98+
public extension FastisShortcut where Value == Date {
9999

100100
/// Date value: **`now`**
101-
public static var today: FastisShortcut {
102-
return FastisShortcut(name: "Today") {
103-
return Date()
101+
static var today: FastisShortcut {
102+
FastisShortcut(name: "Today") {
103+
Date()
104104
}
105105
}
106106

107107
/// Date value: **`now - .day(1)`**
108-
public static var yesterday: FastisShortcut {
109-
return FastisShortcut(name: "Yesterday") {
110-
return Calendar.current.date(byAdding: .day, value: -1, to: Date())!
108+
static var yesterday: FastisShortcut {
109+
FastisShortcut(name: "Yesterday") {
110+
Calendar.current.date(byAdding: .day, value: -1, to: Date())!
111111
}
112112
}
113113

114114
/// Date value: **`now + .day(1)`**
115-
public static var tomorrow: FastisShortcut {
116-
return FastisShortcut(name: "Tomorrow") {
117-
return Calendar.current.date(byAdding: .day, value: 1, to: Date())!
115+
static var tomorrow: FastisShortcut {
116+
FastisShortcut(name: "Tomorrow") {
117+
Calendar.current.date(byAdding: .day, value: 1, to: Date())!
118118
}
119119
}
120120

Sources/Models/Value.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ public struct FastisRange: FastisValue, Hashable {
4646
}
4747

4848
public static func from(_ fromDate: Date, to toDate: Date) -> FastisRange {
49-
return FastisRange(from: fromDate, to: toDate)
49+
FastisRange(from: fromDate, to: toDate)
5050
}
5151

5252
public var onSameDay: Bool {
53-
return self.fromDate.isInSameDay(date: self.toDate)
53+
self.fromDate.isInSameDay(date: self.toDate)
5454
}
5555

5656
public func outOfRange(minDate: Date?, maxDate: Date?) -> Bool {
57-
return self.fromDate < minDate ?? self.fromDate || self.toDate > maxDate ?? self.toDate
57+
self.fromDate < minDate ?? self.fromDate || self.toDate > maxDate ?? self.toDate
5858
}
5959

6060
}
@@ -73,7 +73,7 @@ extension Date: FastisValue {
7373
public static var mode: FastisMode = .single
7474

7575
public func outOfRange(minDate: Date?, maxDate: Date?) -> Bool {
76-
return self < minDate ?? self || self > maxDate ?? self
76+
self < minDate ?? self || self > maxDate ?? self
7777
}
7878

7979
}

0 commit comments

Comments
 (0)