Skip to content

Commit

Permalink
Swift 6 code preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Dec 2, 2024
1 parent 1ae5281 commit 5f90917
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 50 deletions.
30 changes: 30 additions & 0 deletions iTorrent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,16 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = minimal;
SWIFT_UPCOMING_FEATURE_CONCISE_MAGIC_FILE = YES;
SWIFT_UPCOMING_FEATURE_DEPRECATE_APPLICATION_MAIN = YES;
SWIFT_UPCOMING_FEATURE_DISABLE_OUTWARD_ACTOR_ISOLATION = YES;
SWIFT_UPCOMING_FEATURE_FORWARD_TRAILING_CLOSURES = YES;
SWIFT_UPCOMING_FEATURE_GLOBAL_CONCURRENCY = YES;
SWIFT_UPCOMING_FEATURE_IMPLICIT_OPEN_EXISTENTIALS = YES;
SWIFT_UPCOMING_FEATURE_IMPORT_OBJC_FORWARD_DECLS = YES;
SWIFT_UPCOMING_FEATURE_INFER_SENDABLE_FROM_CAPTURES = YES;
SWIFT_UPCOMING_FEATURE_ISOLATED_DEFAULT_VALUES = YES;
SWIFT_UPCOMING_FEATURE_REGION_BASED_ISOLATION = NO;
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
};
Expand Down Expand Up @@ -2001,6 +2011,16 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_STRICT_CONCURRENCY = minimal;
SWIFT_UPCOMING_FEATURE_CONCISE_MAGIC_FILE = YES;
SWIFT_UPCOMING_FEATURE_DEPRECATE_APPLICATION_MAIN = YES;
SWIFT_UPCOMING_FEATURE_DISABLE_OUTWARD_ACTOR_ISOLATION = YES;
SWIFT_UPCOMING_FEATURE_FORWARD_TRAILING_CLOSURES = YES;
SWIFT_UPCOMING_FEATURE_GLOBAL_CONCURRENCY = YES;
SWIFT_UPCOMING_FEATURE_IMPLICIT_OPEN_EXISTENTIALS = YES;
SWIFT_UPCOMING_FEATURE_IMPORT_OBJC_FORWARD_DECLS = YES;
SWIFT_UPCOMING_FEATURE_INFER_SENDABLE_FROM_CAPTURES = YES;
SWIFT_UPCOMING_FEATURE_ISOLATED_DEFAULT_VALUES = YES;
SWIFT_UPCOMING_FEATURE_REGION_BASED_ISOLATION = NO;
SWIFT_VERSION = 5.0;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand Down Expand Up @@ -2150,6 +2170,16 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = minimal;
SWIFT_UPCOMING_FEATURE_CONCISE_MAGIC_FILE = YES;
SWIFT_UPCOMING_FEATURE_DEPRECATE_APPLICATION_MAIN = YES;
SWIFT_UPCOMING_FEATURE_DISABLE_OUTWARD_ACTOR_ISOLATION = YES;
SWIFT_UPCOMING_FEATURE_FORWARD_TRAILING_CLOSURES = YES;
SWIFT_UPCOMING_FEATURE_GLOBAL_CONCURRENCY = YES;
SWIFT_UPCOMING_FEATURE_IMPLICIT_OPEN_EXISTENTIALS = YES;
SWIFT_UPCOMING_FEATURE_IMPORT_OBJC_FORWARD_DECLS = YES;
SWIFT_UPCOMING_FEATURE_INFER_SENDABLE_FROM_CAPTURES = YES;
SWIFT_UPCOMING_FEATURE_ISOLATED_DEFAULT_VALUES = YES;
SWIFT_UPCOMING_FEATURE_REGION_BASED_ISOLATION = NO;
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
};
Expand Down
9 changes: 9 additions & 0 deletions iTorrent/Base/BaseNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
import UIKit

class BaseNavigationController: SANavigationController {
init() {
super.init(rootViewController: UIViewController())
}

@available(*, unavailable)
@MainActor required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
navigationBar.prefersLargeTitles = true
Expand Down
2 changes: 1 addition & 1 deletion iTorrent/Core/AppDelegate/AppDelegate+RemoteConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import UIKit
#if canImport(FirebaseCore)
import FirebaseRemoteConfig
var remoteConfig = RemoteConfig.remoteConfig()
let remoteConfig = RemoteConfig.remoteConfig()
#endif

extension AppDelegate {
Expand Down
2 changes: 1 addition & 1 deletion iTorrent/Core/SceneDelegate/SceneDelegate+AVPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extension SceneDelegate {
}

private enum Keys {
static var avPlayerDeledates: Void?
nonisolated(unsafe) static var avPlayerDeledates: Void?
}

private var avPlayerDeledates: AVPlayerDelegates {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private extension RssDetailsViewController {
else { return .allow }

guard let url = navigationAction.request.url,
await UIApplication.shared.canOpenURL(url)
UIApplication.shared.canOpenURL(url)
else { return .allow }

Task { @MainActor in
Expand Down
69 changes: 48 additions & 21 deletions iTorrent/Screens/TorrentList/TorrentListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,56 @@ class TorrentListViewController<VM: TorrentListViewModel>: BaseViewController<VM
toolbarItems = getToolBarItems

collectionView.contextMenuConfigurationForItemsAt = { [unowned self] indexPaths, _ in
guard let indexPath = indexPaths.first,
let torrentHandle = (viewModel.sections[indexPath.section].items[indexPath.item] as? TorrentListItemViewModel)?.torrentHandle
else { return nil }

return UIContextMenuConfiguration {
TorrentDetailsViewModel.resolveVC(with: torrentHandle)
} actionProvider: { _ in
let start = UIAction(title: %"details.start", image: .init(systemName: "play.fill"), attributes: torrentHandle.snapshot.canResume ? [] : .hidden, handler: { _ in
torrentHandle.resume()
})
let pause = UIAction(title: %"details.pause", image: .init(systemName: "pause.fill"), attributes: torrentHandle.snapshot.canPause ? [] : .hidden, handler: { _ in
torrentHandle.pause()
})
let delete = UIAction(title: %"common.delete", image: UIImage(systemName: "trash.fill"), attributes: .destructive) { [unowned self] _ in
viewModel.removeTorrent(torrentHandle)
guard indexPaths.count > 0 else { return nil }

if indexPaths.count == 1 {
guard let indexPath = indexPaths.first,
let torrentHandle = (viewModel.sections[indexPath.section].items[indexPath.item] as? TorrentListItemViewModel)?.torrentHandle
else { return nil }

return UIContextMenuConfiguration {
TorrentDetailsViewModel.resolveVC(with: torrentHandle)
} actionProvider: { _ in
let start = UIAction(title: %"details.start", image: .init(systemName: "play.fill"), attributes: torrentHandle.snapshot.canResume ? [] : .hidden, handler: { _ in
torrentHandle.resume()
})
let pause = UIAction(title: %"details.pause", image: .init(systemName: "pause.fill"), attributes: torrentHandle.snapshot.canPause ? [] : .hidden, handler: { _ in
torrentHandle.pause()
})
let delete = UIAction(title: %"common.delete", image: UIImage(systemName: "trash.fill"), attributes: .destructive) { [unowned self] _ in
viewModel.removeTorrent(torrentHandle)
}

return UIMenu(title: torrentHandle.snapshot.name, children: [
start,
pause,
UIMenu(options: .displayInline,
children: [delete])
])
}
} else {
let handles = indexPaths.compactMap { indexPath in (viewModel.sections[indexPath.section].items[indexPath.item] as? TorrentListItemViewModel)?.torrentHandle }
return UIContextMenuConfiguration {
nil
} actionProvider: { _ in
let start = UIAction(title: %"details.start", image: .init(systemName: "play.fill"), handler: { _ in
handles.forEach { $0.resume() }
})
let pause = UIAction(title: %"details.pause", image: .init(systemName: "pause.fill"), handler: { _ in
handles.forEach { $0.pause() }
})
// let delete = UIAction(title: %"common.delete", image: UIImage(systemName: "trash.fill"), attributes: .destructive) { [unowned self] _ in
// viewModel.removeTorrent(torrentHandle)
// }

return UIMenu(children: [
start,
pause,
// UIMenu(options: .displayInline,
// children: [delete])
])
}

return UIMenu(title: torrentHandle.snapshot.name, children: [
start,
pause,
UIMenu(options: .displayInline,
children: [delete])
])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension NSNotification.Name {
}

struct PauseTorrentIntent: LiveActivityIntent {
static var title: LocalizedStringResource = "intent.pauseTorrent.title"
static let title: LocalizedStringResource = "intent.pauseTorrent.title"

@Parameter(title: "intent.pauseTorrent.hash.title", description: "intent.pauseTorrent.hash.description")
var torrentHash: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,38 @@ import Combine
import LibTorrent
import MvvmFoundation

private var TorrentHandleUnthrottledUpdatePublisherKey: UInt8 = 0
private var TorrentHandleUpdatePublisherKey: UInt8 = 0
private var TorrentHandleRemovePublisherKey: UInt8 = 0
private var TorrentHandleDisposeBagKey: UInt8 = 0

extension TorrentHandle {
private enum Keys {
nonisolated(unsafe) static var TorrentHandleUnthrottledUpdatePublisherKey: Void?
nonisolated(unsafe) static var TorrentHandleUpdatePublisherKey: Void?
nonisolated(unsafe) static var TorrentHandleRemovePublisherKey: Void?
nonisolated(unsafe) static var TorrentHandleDisposeBagKey: Void?
}

var disposeBag: DisposeBag {
guard let obj = objc_getAssociatedObject(self, &TorrentHandleDisposeBagKey) as? DisposeBag
guard let obj = objc_getAssociatedObject(self, &Keys.TorrentHandleDisposeBagKey) as? DisposeBag
else {
objc_setAssociatedObject(self, &TorrentHandleDisposeBagKey, DisposeBag(), objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
return objc_getAssociatedObject(self, &TorrentHandleDisposeBagKey) as! DisposeBag
objc_setAssociatedObject(self, &Keys.TorrentHandleDisposeBagKey, DisposeBag(), objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
return objc_getAssociatedObject(self, &Keys.TorrentHandleDisposeBagKey) as! DisposeBag
}
return obj
}

var __unthrottledUpdatePublisher: PassthroughSubject<Void, Never> {
guard let obj = objc_getAssociatedObject(self, &TorrentHandleUnthrottledUpdatePublisherKey) as? PassthroughSubject<Void, Never>
guard let obj = objc_getAssociatedObject(self, &Keys.TorrentHandleUnthrottledUpdatePublisherKey) as? PassthroughSubject<Void, Never>
else {
objc_setAssociatedObject(self, &TorrentHandleUnthrottledUpdatePublisherKey, PassthroughSubject<Void, Never>(), objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
return objc_getAssociatedObject(self, &TorrentHandleUnthrottledUpdatePublisherKey) as! PassthroughSubject<Void, Never>
objc_setAssociatedObject(self, &Keys.TorrentHandleUnthrottledUpdatePublisherKey, PassthroughSubject<Void, Never>(), objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
return objc_getAssociatedObject(self, &Keys.TorrentHandleUnthrottledUpdatePublisherKey) as! PassthroughSubject<Void, Never>
}
return obj
}

var __updatePublisher: PassthroughSubject<TorrentService.TorrentUpdateModel, Never> {
guard let obj = objc_getAssociatedObject(self, &TorrentHandleUpdatePublisherKey) as? PassthroughSubject<TorrentService.TorrentUpdateModel, Never>
guard let obj = objc_getAssociatedObject(self, &Keys.TorrentHandleUpdatePublisherKey) as? PassthroughSubject<TorrentService.TorrentUpdateModel, Never>
else {
objc_setAssociatedObject(self, &TorrentHandleUpdatePublisherKey, PassthroughSubject<TorrentService.TorrentUpdateModel, Never>(), objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
return objc_getAssociatedObject(self, &TorrentHandleUpdatePublisherKey) as! PassthroughSubject<TorrentService.TorrentUpdateModel, Never>
objc_setAssociatedObject(self, &Keys.TorrentHandleUpdatePublisherKey, PassthroughSubject<TorrentService.TorrentUpdateModel, Never>(), objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
return objc_getAssociatedObject(self, &Keys.TorrentHandleUpdatePublisherKey) as! PassthroughSubject<TorrentService.TorrentUpdateModel, Never>
}
return obj
}
Expand All @@ -55,10 +58,10 @@ extension TorrentHandle {
}

var removePublisher: PassthroughSubject<TorrentHandle, Never> {
guard let obj = objc_getAssociatedObject(self, &TorrentHandleRemovePublisherKey) as? PassthroughSubject<TorrentHandle, Never>
guard let obj = objc_getAssociatedObject(self, &Keys.TorrentHandleRemovePublisherKey) as? PassthroughSubject<TorrentHandle, Never>
else {
objc_setAssociatedObject(self, &TorrentHandleRemovePublisherKey, PassthroughSubject<TorrentHandle, Never>(), objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
return objc_getAssociatedObject(self, &TorrentHandleRemovePublisherKey) as! PassthroughSubject<TorrentHandle, Never>
objc_setAssociatedObject(self, &Keys.TorrentHandleRemovePublisherKey, PassthroughSubject<TorrentHandle, Never>(), objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
return objc_getAssociatedObject(self, &Keys.TorrentHandleRemovePublisherKey) as! PassthroughSubject<TorrentHandle, Never>
}
return obj
}
Expand Down Expand Up @@ -165,12 +168,12 @@ extension TorrentHandle {

// MARK: - Metadata cache
private extension TorrentHandle {
private enum Keys {
static var metadataKey: Void?
private enum MetaKeys {
nonisolated(unsafe) static var metadataKey: Void?
}

var _metadata: Metadata? {
get { objc_getAssociatedObject(self, &Keys.metadataKey) as? Metadata }
set { objc_setAssociatedObject(self, &Keys.metadataKey, newValue, .OBJC_ASSOCIATION_RETAIN) }
get { objc_getAssociatedObject(self, &MetaKeys.metadataKey) as? Metadata }
set { objc_setAssociatedObject(self, &MetaKeys.metadataKey, newValue, .OBJC_ASSOCIATION_RETAIN) }
}
}
4 changes: 2 additions & 2 deletions iTorrent/Utils/Extensions/Combine/Published+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ fileprivate enum CodingKeys: String, CodingKey {
case value
}

extension Published: Decodable where Value: Decodable {
extension Published: @retroactive Decodable where Value: Decodable {
public init(from decoder: Decoder) throws {
self.init(wrappedValue: try .init(from: decoder))
}
}

extension Published: Encodable where Value: Encodable {
extension Published: @retroactive Encodable where Value: Encodable {
public func encode(to encoder: Encoder) throws {
try unofficialValue.encode(to: encoder)
}
Expand Down
4 changes: 2 additions & 2 deletions iTorrent/Utils/Extensions/UIKit/UIView+LayerColors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import UIKit

public extension UIView {
private enum Keys {
static var borderColorAssociateKey: Void?
static var shadowColorAssociateKey: Void?
nonisolated(unsafe) static var borderColorAssociateKey: Void?
nonisolated(unsafe) static var shadowColorAssociateKey: Void?
}

var borderColor: UIColor? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public extension UIViewController {
func applyBottomSheetDetents(with scrollView: UIScrollView? = nil) -> AnyCancellable? {
#if !os(visionOS)
guard let sheet = sheetPresentationController else { return nil }
sheet.prefersGrabberVisible = true
sheet.prefersGrabberVisible = false

/// If UIScrollView is not presented,
/// or iOS 16 is not available, than set default detents
Expand Down

0 comments on commit 5f90917

Please sign in to comment.