Skip to content

Commit

Permalink
Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
HituziANDO committed Apr 16, 2024
1 parent 90cf4c5 commit 595e511
Show file tree
Hide file tree
Showing 23 changed files with 287 additions and 274 deletions.
46 changes: 23 additions & 23 deletions Framework/Sources/Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import UIKit

#if os(iOS)
extension UIApplication {

static var keyWindow: UIWindow? {
UIApplication.shared.windows.filter { $0.isKeyWindow }.first
UIApplication.shared.windows.filter(\.isKeyWindow).first
}
}

Expand All @@ -35,15 +34,15 @@ extension UIViewController {
#endif

class Alert {

/// The button click event handler.
public typealias ActionHandler = () -> ()
public typealias ActionHandler = () -> Void

/// Styles to apply to action buttons in an alert.
public enum ActionStyle {
/// Apply the default style to the action’s button.
case `default`
/// Apply a style that indicates the action cancels the operation and leaves things unchanged.
/// Apply a style that indicates the action cancels the operation and leaves things
/// unchanged.
case cancel
/// Apply a style that indicates the action might change or delete data.
case destructive
Expand Down Expand Up @@ -88,13 +87,13 @@ class Alert {
/// The esc key.
case esc = "\u{1b}"
/// The y key. Maybe it means "yes".
case y = "y"
case y
/// The n key. Maybe it means "no".
case n = "n"
case n
/// The o key. Maybe it means "ok".
case o = "o"
case o
/// The c key. Maybe it means "cancel".
case c = "c"
case c
}

#if os(OSX)
Expand Down Expand Up @@ -134,7 +133,8 @@ class Alert {
open func addAction(_ title: String,
style: ActionStyle? = .default,
shortcutKey: ShortcutKey? = nil,
handler: ActionHandler? = nil) -> Self {
handler: ActionHandler? = nil) -> Self
{
#if os(OSX)
if buttonIndex == 0 {
alert.addButton(withTitle: title)
Expand All @@ -143,30 +143,30 @@ class Alert {
alert.buttons[0].keyEquivalent = key.rawValue
}
buttonIndex += 1
}
else if buttonIndex == 1 {
} else if buttonIndex == 1 {
alert.addButton(withTitle: title)
secondButtonHandler = handler
if let key = shortcutKey {
alert.buttons[1].keyEquivalent = key.rawValue
}
buttonIndex += 1
}
else if buttonIndex == 2 {
} else if buttonIndex == 2 {
alert.addButton(withTitle: title)
thirdButtonHandler = handler
if let key = shortcutKey {
alert.buttons[2].keyEquivalent = key.rawValue
}
buttonIndex += 1
}
else {
} else {
fatalError("The alert can have up to 3 buttons.")
}
#elseif os(iOS)
alert.addAction(UIAlertAction(title: title, style: style?.uiAlertActionStyle ?? .default) { _ in
handler?()
})
alert
.addAction(UIAlertAction(title: title,
style: style?.uiAlertActionStyle ?? .default)
{ _ in
handler?()
})
#endif
return self
}
Expand All @@ -177,13 +177,13 @@ class Alert {
let response = alert.runModal()
switch response {
case .alertFirstButtonReturn:
firstButtonHandler?()
firstButtonHandler?()
case .alertSecondButtonReturn:
secondButtonHandler?()
secondButtonHandler?()
case .alertThirdButtonReturn:
thirdButtonHandler?()
thirdButtonHandler?()
default:
break
break
}
#elseif os(iOS)
UIApplication.keyWindow?
Expand Down
3 changes: 1 addition & 2 deletions Framework/Sources/DateUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ struct DateUtils {
let str = formatter.string(from: Date())
if let dateInt = Int(str) {
return dateInt
}
else {
} else {
// Unsupported locale.
// print(locale.identifier)
return currentDate()
Expand Down
107 changes: 52 additions & 55 deletions Framework/Sources/ITunesSearchAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ enum ITunesSearchAPIError: Error {
}

struct ITunesSearchAPI {

public static func lookUp(with config: SwiftyUpdateKitConfig,
completion: @escaping (Result<[LookUpResult], Error>) -> ()) {
completion: @escaping (Result<[LookUpResult], Error>) -> Void)
{
let url: URL
if let country = config.country, !country.isEmpty {
url = URL(string: "https://itunes.apple.com/lookup?id=\(config.iTunesID)&country=\(country)")!
}
else {
url =
URL(string: "https://itunes.apple.com/lookup?id=\(config.iTunesID)&country=\(country)")!
} else {
url = URL(string: "https://itunes.apple.com/lookup?id=\(config.iTunesID)")!
}

Expand All @@ -78,17 +78,17 @@ struct ITunesSearchAPI {
}

private extension ITunesSearchAPI {

static func resumeTask(_ url: URL,
tryCount: Int,
maxCount: Int,
delay: TimeInterval,
completion: @escaping (Result<[LookUpResult], Error>) -> ()) {
completion: @escaping (Result<[LookUpResult], Error>) -> Void)
{
fetch(url) { result in
switch result {
case .success(let results):
case let .success(results):
completion(.success(results))
case .failure(let error):
case let .failure(error):
if tryCount <= maxCount {
// Retry
DispatchQueue.global().asyncAfter(deadline: .now() + delay) {
Expand All @@ -98,23 +98,22 @@ private extension ITunesSearchAPI {
delay: delay,
completion: completion)
}
}
else {
} else {
// Failed
completion(.failure(error))
}
}
}
}

static func fetch(_ url: URL, completion: @escaping (Result<[LookUpResult], Error>) -> ()) {
static func fetch(_ url: URL, completion: @escaping (Result<[LookUpResult], Error>) -> Void) {
let task = URLSession.shared.dataTask(with: url) { data, response, error in
if let error = error {
if let error {
completion(.failure(error))
return
}

guard let data = data, let response = response as? HTTPURLResponse else {
guard let data, let response = response as? HTTPURLResponse else {
completion(.failure(ITunesSearchAPIError.invalidResponseData))
return
}
Expand All @@ -132,50 +131,48 @@ private extension ITunesSearchAPI {
}

let lookUpResults = results.map {
LookUpResult(
artistId: $0["artistId"] as? UInt,
artistName: $0["artistName"] as? String,
artistViewUrl: $0["artistViewUrl"] as? String,
artworkUrl100: $0["artworkUrl100"] as? String,
artworkUrl512: $0["artworkUrl512"] as? String,
artworkUrl60: $0["artworkUrl60"] as? String,
averageUserRating: $0["averageUserRating"] as? Int,
averageUserRatingForCurrentVersion: $0["averageUserRatingForCurrentVersion"] as? Int,
bundleId: $0["bundleId"] as? String,
contentAdvisoryRating: $0["contentAdvisoryRating"] as? String,
currency: $0["currency"] as? String,
currentVersionReleaseDate: $0["currentVersionReleaseDate"] as? String,
description: $0["description"] as? String,
fileSizeBytes: $0["fileSizeBytes"] as? UInt,
formattedPrice: $0["formattedPrice"] as? String,
genreIds: $0["genreIds"] as? [String],
genres: $0["genres"] as? [String],
isVppDeviceBasedLicensingEnabled: $0["isVppDeviceBasedLicensingEnabled"] as? Bool,
kind: $0["kind"] as? String,
languageCodesISO2A: $0["languageCodesISO2A"] as? [String],
minimumOsVersion: $0["minimumOsVersion"] as? String,
price: $0["price"] as? Int,
primaryGenreId: $0["primaryGenreId"] as? Int,
primaryGenreName: $0["primaryGenreName"] as? String,
releaseDate: $0["releaseDate"] as? String,
releaseNotes: $0["releaseNotes"] as? String,
screenshotUrls: $0["screenshotUrls"] as? [String],
sellerName: $0["sellerName"] as? String,
sellerUrl: $0["sellerUrl"] as? String,
trackCensoredName: $0["trackCensoredName"] as? String,
trackContentRating: $0["trackContentRating"] as? String,
trackId: $0["trackId"] as? UInt,
trackName: $0["trackName"] as? String,
trackViewUrl: $0["trackViewUrl"] as? String,
userRatingCount: $0["userRatingCount"] as? Int,
userRatingCountForCurrentVersion: $0["userRatingCountForCurrentVersion"] as? Int,
version: $0["version"] as? String,
wrapperType: $0["wrapperType"] as? String
)
LookUpResult(artistId: $0["artistId"] as? UInt,
artistName: $0["artistName"] as? String,
artistViewUrl: $0["artistViewUrl"] as? String,
artworkUrl100: $0["artworkUrl100"] as? String,
artworkUrl512: $0["artworkUrl512"] as? String,
artworkUrl60: $0["artworkUrl60"] as? String,
averageUserRating: $0["averageUserRating"] as? Int,
averageUserRatingForCurrentVersion: $0["averageUserRatingForCurrentVersion"] as? Int,
bundleId: $0["bundleId"] as? String,
contentAdvisoryRating: $0["contentAdvisoryRating"] as? String,
currency: $0["currency"] as? String,
currentVersionReleaseDate: $0["currentVersionReleaseDate"] as? String,
description: $0["description"] as? String,
fileSizeBytes: $0["fileSizeBytes"] as? UInt,
formattedPrice: $0["formattedPrice"] as? String,
genreIds: $0["genreIds"] as? [String],
genres: $0["genres"] as? [String],
isVppDeviceBasedLicensingEnabled: $0["isVppDeviceBasedLicensingEnabled"] as? Bool,
kind: $0["kind"] as? String,
languageCodesISO2A: $0["languageCodesISO2A"] as? [String],
minimumOsVersion: $0["minimumOsVersion"] as? String,
price: $0["price"] as? Int,
primaryGenreId: $0["primaryGenreId"] as? Int,
primaryGenreName: $0["primaryGenreName"] as? String,
releaseDate: $0["releaseDate"] as? String,
releaseNotes: $0["releaseNotes"] as? String,
screenshotUrls: $0["screenshotUrls"] as? [String],
sellerName: $0["sellerName"] as? String,
sellerUrl: $0["sellerUrl"] as? String,
trackCensoredName: $0["trackCensoredName"] as? String,
trackContentRating: $0["trackContentRating"] as? String,
trackId: $0["trackId"] as? UInt,
trackName: $0["trackName"] as? String,
trackViewUrl: $0["trackViewUrl"] as? String,
userRatingCount: $0["userRatingCount"] as? Int,
userRatingCountForCurrentVersion: $0["userRatingCountForCurrentVersion"] as? Int,
version: $0["version"] as? String,
wrapperType: $0["wrapperType"] as? String)
}
completion(.success(lookUpResults))
}

task.resume()
}
}
}
2 changes: 1 addition & 1 deletion Framework/Sources/Log.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Foundation
/// print(message)
/// }
/// ```
public typealias Log = (_ message: Any) -> ()
public typealias Log = (_ message: Any) -> Void

func logf(_ message: String, _ log: Log?) {
log?("[SwiftyUpdateKit] \(message)")
Expand Down
9 changes: 4 additions & 5 deletions Framework/Sources/ReleaseNotes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ struct ReleaseNotes: Codable {
let dict = dictionary()
if let releaseNotes = dict[userID] {
return releaseNotes
}
else {
} else {
return ReleaseNotes(latest: nil, userID: userID)
}
}
Expand All @@ -37,10 +36,10 @@ struct ReleaseNotes: Codable {
private static func dictionary() -> [String: ReleaseNotes] {
if let string = SUKUserDefaults.standard.string(forKey: SwiftyUpdateKitLatestAppVersionKey),
let data = Data(base64Encoded: string),
let dictionary = try? JSONDecoder().decode([String: ReleaseNotes].self, from: data) {
let dictionary = try? JSONDecoder().decode([String: ReleaseNotes].self, from: data)
{
return dictionary
}
else {
} else {
return [:]
}
}
Expand Down
Loading

0 comments on commit 595e511

Please sign in to comment.