Skip to content

Commit

Permalink
feat: add swift format (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzxha authored Feb 4, 2024
1 parent 0a5f022 commit 7157113
Show file tree
Hide file tree
Showing 63 changed files with 891 additions and 896 deletions.
24 changes: 24 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# file options

--symlinks ignore
--swiftversion 5.7

# format options

--patternlet inline
--decimalgrouping 3,5
--operatorfunc spaced
--nospaceoperators ..<, ...
--someAny false
--extensionacl on-declarations
--ifdef outdent
--commas inline
--stripunusedargs closure-only
--elseposition same-line
--guardelse same-line
--indentstrings false
--anonymousforeach ignore

# rules
--enable isEmpty
--disable sortImports,wrapMultilineStatementBraces,wrapArguments,enumNamespaces,indent,trailingSpace,conditionalAssignment
1 change: 0 additions & 1 deletion Demo/Demo/Demo-MacOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ class AppDelegate: NSObject, NSApplicationDelegate {
Aliyunpan.setLogLevel(.info)
}
}

14 changes: 6 additions & 8 deletions Demo/Demo/Demo-MacOS/ExamplesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Cocoa
import AliyunpanSDK

class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate {
@IBOutlet weak var tableView: NSTableView!
@IBOutlet var tableView: NSTableView!

let examples = Example.allCases

Expand All @@ -25,7 +25,7 @@ class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableVi
}

func numberOfRows(in tableView: NSTableView) -> Int {
return examples.count
examples.count
}

func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
Expand Down Expand Up @@ -108,9 +108,8 @@ class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableVi

@MainActor
private func showFileDetailViewController(files: [AliyunpanFile]) {
guard let splitViewController = self.parent as? NSSplitViewController,
let viewController = self.storyboard?.instantiateController(withIdentifier: "DetailViewController") as? DetailViewController
else { return }
guard let splitViewController = parent as? NSSplitViewController,
let viewController = storyboard?.instantiateController(withIdentifier: "DetailViewController") as? DetailViewController else { return }

viewController.files = files
let item = NSSplitViewItem(viewController: viewController)
Expand Down Expand Up @@ -141,7 +140,7 @@ class DetailViewController: NSViewController, NSTableViewDataSource, NSTableView

var parentDetailViewController: DetailViewController?

@IBOutlet weak var tableView: NSTableView!
@IBOutlet var tableView: NSTableView!

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -151,7 +150,7 @@ class DetailViewController: NSViewController, NSTableViewDataSource, NSTableView
}

func numberOfRows(in tableView: NSTableView) -> Int {
return files.count
files.count
}

func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
Expand Down Expand Up @@ -190,6 +189,5 @@ class DetailViewController: NSViewController, NSTableViewDataSource, NSTableView
class MainSplitViewController: NSSplitViewController {
override func viewDidLoad() {
super.viewDidLoad()

}
}
3 changes: 2 additions & 1 deletion Demo/Demo/Demo-MacOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()

(NSApplication.shared.delegate as! AppDelegate).client = self.client
(NSApplication.shared.delegate as! AppDelegate).client = client

authorizeButton.title = "Authorize"
authorizeButton.bezelStyle = .roundRect
Expand Down Expand Up @@ -73,6 +73,7 @@ class ViewController: NSViewController {
view.window?.contentViewController = splitViewController
}
}

extension ViewController: AliyunpanQRCodeContainer {
func authorizeQRCodeStatusUpdated(_ status: AliyunpanSDK.AliyunpanAuthorizeQRCodeStatus) {
print(status.rawValue)
Expand Down
7 changes: 1 addition & 6 deletions Demo/Demo/Demo-TVOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
true
}

func applicationWillResignActive(_ application: UIApplication) {
Expand All @@ -34,7 +32,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


}

4 changes: 0 additions & 4 deletions Demo/Demo/Demo-TVOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}


}

2 changes: 1 addition & 1 deletion Demo/Demo/Demo-iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return Aliyunpan.handleOpenURL(url)
Aliyunpan.handleOpenURL(url)
}
}
1 change: 0 additions & 1 deletion Demo/Demo/Demo-iOS/FileCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,3 @@ class FileCell: UICollectionViewListCell {
}
}
}

12 changes: 6 additions & 6 deletions Demo/Demo/Demo-iOS/FileListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FileListViewController: UIViewController {
}()

private lazy var dataSource: UICollectionViewDiffableDataSource<Int, DisplayItem> = {
let cellRegistration = UICollectionView.CellRegistration<FileCell, DisplayItem> { [weak self] cell, indexPath, item in
let cellRegistration = UICollectionView.CellRegistration<FileCell, DisplayItem> { [weak self] cell, _, item in
guard let self else {
return
}
Expand All @@ -43,20 +43,20 @@ class FileListViewController: UIViewController {
}

return UICollectionViewDiffableDataSource(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in
return collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier)
collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier)
}
}()

private lazy var collectionView: UICollectionView = {
let layout = UICollectionViewCompositionalLayout.list(using: UICollectionLayoutListConfiguration.init(appearance: .grouped))
let layout = UICollectionViewCompositionalLayout.list(using: UICollectionLayoutListConfiguration(appearance: .grouped))
let collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout)
collectionView.delegate = self
return collectionView
}()

var files: [AliyunpanFile] {
get {
displayItems.map { $0.file }
displayItems.map(\.file)
}
set {
displayItems = newValue.map { DisplayItem($0) }
Expand Down Expand Up @@ -135,7 +135,7 @@ extension FileListViewController: UICollectionViewDelegate {
/// 获取画质最高的已转码播放链接
let playURL = playInfo.video_preview_play_info.live_transcoding_task_list
.filter { $0.status == .finished }
.compactMap { $0.url }
.compactMap(\.url)
.last

if let playURL {
Expand Down Expand Up @@ -212,7 +212,7 @@ extension FileListViewController: FileCellDelegate {

extension FileListViewController: UIDocumentInteractionControllerDelegate {
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
self
}
}

Expand Down
6 changes: 3 additions & 3 deletions Demo/Demo/Demo-iOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import AliyunpanSDK

class ViewController: UIViewController {
private var client: AliyunpanClient {
return (UIApplication.shared.delegate as! AppDelegate).client
(UIApplication.shared.delegate as! AppDelegate).client
}

private let activityIndicatorView: UIActivityIndicatorView = {
Expand All @@ -28,12 +28,12 @@ class ViewController: UIViewController {
}

return UICollectionViewDiffableDataSource(collectionView: collectionView) { collectionView, indexPath, itemIdentifier in
return collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier)
collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: itemIdentifier)
}
}()

private lazy var collectionView: UICollectionView = {
var config = UICollectionLayoutListConfiguration.init(appearance: .grouped)
var config = UICollectionLayoutListConfiguration(appearance: .grouped)
let layout = UICollectionViewCompositionalLayout.list(using: config)
let collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout)
collectionView.delegate = self
Expand Down
2 changes: 1 addition & 1 deletion Sources/AliyunpanSDK/AliyunpanClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class AliyunpanClient {
self.config = config

if let tokenData = UserDefaults.standard.data(forKey: tokenStorageKey) {
self.token = try? JSONParameterDecoder().decode(AliyunpanToken.self, from: tokenData)
token = try? JSONParameterDecoder().decode(AliyunpanToken.self, from: tokenData)
}
}

Expand Down
14 changes: 7 additions & 7 deletions Sources/AliyunpanSDK/AliyunpanCredentials/AliyunpanMessage.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// File.swift
// AliyunpanMessage.swift
//
//
// Created by zhaixian on 2023/11/27.
Expand All @@ -17,9 +17,9 @@ class AliyunpanMessage {
throw AliyunpanError.AuthorizeError.invalidAuthorizeURL
}
let queryItems = url.queryItems
self.originalURL = url
self.action = url.host ?? ""
self.state = queryItems.first(where: { $0.name == "state" })?.value ?? "Unknown"
originalURL = url
action = url.host ?? ""
state = queryItems.first(where: { $0.name == "state" })?.value ?? "Unknown"
}

var id: String {
Expand All @@ -34,9 +34,9 @@ class AliyunpanAuthorizeMessage: AliyunpanMessage {

override init(_ url: URL) throws {
let queryItems = url.queryItems
self.authCode = queryItems.first(where: { $0.name == "code" })?.value
self.error = queryItems.first(where: { $0.name == "error" })?.value
self.errorMsg = queryItems.first(where: { $0.name == "errorMsg" })?.value
authCode = queryItems.first(where: { $0.name == "code" })?.value
error = queryItems.first(where: { $0.name == "error" })?.value
errorMsg = queryItems.first(where: { $0.name == "errorMsg" })?.value
try super.init(url)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AliyunpanQRCodeCredentials: AliyunpanCredentialsProtocol {
}

private func pollingWaitAuthorize(sid: String, timeout: TimeInterval) -> AsyncThrowingStream<(status: AliyunpanAuthorizeQRCodeStatus, authCode: String?), Error> {
return AsyncThrowingStream { continuation in
AsyncThrowingStream { continuation in
Task {
do {
try await withTimeout(seconds: timeout) {
Expand Down Expand Up @@ -63,7 +63,6 @@ class AliyunpanQRCodeCredentials: AliyunpanCredentialsProtocol {
}
}
}

}

func authorize(appId: String, scope: String) async throws -> AliyunpanToken {
Expand Down
4 changes: 2 additions & 2 deletions Sources/AliyunpanSDK/AliyunpanSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class Aliyunpan {

private(set) static var logLevel: AliyunpanLogLevel = .warn
public static func setLogLevel(_ level: AliyunpanLogLevel) {
self.logLevel = level
logLevel = level
}

public private(set) static var env: Environment = .product
Expand All @@ -74,7 +74,7 @@ public class Aliyunpan {

@discardableResult
public static func handleOpenURL(_ url: URL) -> Bool {
return AliyunpanAppJumper.handle(url: url)
AliyunpanAppJumper.handle(url: url)
}
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/AliyunpanSDK/AliyunpanScope/AliyunpanCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public protocol AliyunpanCommand {
var requestData: Data? { get }
}

public extension AliyunpanCommand where Request == Void {
var request: Request? { nil }
var requestData: Data? { nil }
extension AliyunpanCommand where Request == Void {
public var request: Request? { nil }
public var requestData: Data? { nil }
}

public extension AliyunpanCommand where Request: Encodable {
var requestData: Data? {
extension AliyunpanCommand where Request: Encodable {
public var requestData: Data? {
if let request {
return try? JSONParameterEncoder().encode(request)
} else {
Expand Down
41 changes: 21 additions & 20 deletions Sources/AliyunpanSDK/AliyunpanScope/File/BatchGet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,38 @@
import Foundation

extension AliyunpanFileScope {
/// 批量获取文件详情
public class BatchGet: AliyunpanCommand {
public var httpMethod: HTTPMethod { .post }
public var uri: String {
"/adrive/v1.0/openFile/batch/get"
}

public struct Request: Codable {
/// 批量获取文件详情
public class BatchGet: AliyunpanCommand {
public var httpMethod: HTTPMethod { .post }
public var uri: String {
"/adrive/v1.0/openFile/batch/get"
}

public struct Request: Codable {
public struct Item: Codable {
public let drive_id: String
public let file_id: String

public init(drive_id: String, file_id: String) {
self.drive_id = drive_id
self.file_id = file_id
}
}
public let file_list: [Item]


public let file_list: [Item]

public init(file_list: [Item]) {
self.file_list = file_list
}
}
}

public struct Response: Codable {
public let items: [AliyunpanFile]
}
public struct Response: Codable {
public let items: [AliyunpanFile]
}

public let request: Request?
public init(_ request: Request) {
self.request = request
}
}
public let request: Request?
public init(_ request: Request) {
self.request = request
}
}
}
Loading

0 comments on commit 7157113

Please sign in to comment.