From 9d9d8947b99ad785102f2d7be05d1b8b47bcc869 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sat, 5 Nov 2022 16:30:00 +0100 Subject: [PATCH] Remove warnings and bump deployment target to 10.15 --- Commons/Sources/Commons/AppKitCommons.swift | 11 +++-- .../Sources/Commons/FoundationCommons.swift | 5 --- .../CommonsSupport.xcodeproj/project.pbxproj | 4 +- .../NvimViewSupport.xcodeproj/project.pbxproj | 4 +- VimR/VimR.xcodeproj/project.pbxproj | 3 +- VimR/VimR/ShortcutsPref.swift | 42 ++++++++++++------- VimR/VimR/ShortcutsTableSubviews.swift | 2 +- 7 files changed, 41 insertions(+), 30 deletions(-) diff --git a/Commons/Sources/Commons/AppKitCommons.swift b/Commons/Sources/Commons/AppKitCommons.swift index d62b6435e..3abddf0c6 100644 --- a/Commons/Sources/Commons/AppKitCommons.swift +++ b/Commons/Sources/Commons/AppKitCommons.swift @@ -63,8 +63,10 @@ public extension NSColor { } convenience init?(hex: String) { - var result: UInt32 = 0 - guard hex.count == 6, Scanner(string: hex).scanHexInt32(&result) else { return nil } + guard hex.count == 6, + let uint64 = Scanner(string: hex).scanUInt64(representation: .hexadecimal) + else { return nil } + let result = UInt32(uint64) let r = (result & 0xFF0000) >> 16 let g = (result & 0x00FF00) >> 8 @@ -126,7 +128,7 @@ public extension NSView { /// - Warning: Call only in drawRect() func rectsBeingDrawn() -> [CGRect] { var rectsPtr: UnsafePointer? - var count: Int = 0 + var count = 0 self.getRectsBeingDrawn(&rectsPtr, count: &count) return Array(UnsafeBufferPointer(start: rectsPtr, count: count)) @@ -134,7 +136,8 @@ public extension NSView { } public extension NSEvent.ModifierFlags { - // Values are from https://github.com/SFML/SFML/blob/master/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm + // Values are from + // https://github.com/SFML/SFML/blob/master/src/SFML/Window/OSX/SFKeyboardModifiersHelper.mm static let rightShift = NSEvent.ModifierFlags(rawValue: 0x020004) static let leftShift = NSEvent.ModifierFlags(rawValue: 0x020002) static let rightCommand = NSEvent.ModifierFlags(rawValue: 0x100010) diff --git a/Commons/Sources/Commons/FoundationCommons.swift b/Commons/Sources/Commons/FoundationCommons.swift index 41fdd8703..5c8c3b9eb 100644 --- a/Commons/Sources/Commons/FoundationCommons.swift +++ b/Commons/Sources/Commons/FoundationCommons.swift @@ -134,9 +134,4 @@ public extension URL { var isPackage: Bool { (try? self.resourceValues(forKeys: [.isPackageKey]))?.isPackage ?? false } } -public extension ValueTransformer { - static var keyedUnarchiveFromDataTransformer - = ValueTransformer(forName: .keyedUnarchiveFromDataTransformerName)! -} - private let log = OSLog(subsystem: "com.qvacua.vimr.commons", category: "general") diff --git a/Commons/Support/CommonsSupport.xcodeproj/project.pbxproj b/Commons/Support/CommonsSupport.xcodeproj/project.pbxproj index 03244bdb7..85e16a900 100644 --- a/Commons/Support/CommonsSupport.xcodeproj/project.pbxproj +++ b/Commons/Support/CommonsSupport.xcodeproj/project.pbxproj @@ -202,7 +202,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; + MACOSX_DEPLOYMENT_TARGET = 10.15; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -257,7 +257,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; + MACOSX_DEPLOYMENT_TARGET = 10.15; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SWIFT_COMPILATION_MODE = wholemodule; diff --git a/NvimView/Support/NvimViewSupport.xcodeproj/project.pbxproj b/NvimView/Support/NvimViewSupport.xcodeproj/project.pbxproj index 260851caa..99767cda1 100644 --- a/NvimView/Support/NvimViewSupport.xcodeproj/project.pbxproj +++ b/NvimView/Support/NvimViewSupport.xcodeproj/project.pbxproj @@ -564,7 +564,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; + MACOSX_DEPLOYMENT_TARGET = 10.15; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; @@ -623,7 +623,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.13; + MACOSX_DEPLOYMENT_TARGET = 10.15; MTL_ENABLE_DEBUG_INFO = NO; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_DISABLE_SAFETY_CHECKS = YES; diff --git a/VimR/VimR.xcodeproj/project.pbxproj b/VimR/VimR.xcodeproj/project.pbxproj index b7348e88d..cbf9c9ede 100644 --- a/VimR/VimR.xcodeproj/project.pbxproj +++ b/VimR/VimR.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 52; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -933,6 +933,7 @@ /* Begin PBXShellScriptBuildPhase section */ 4B19BEFF1E110208007E823C /* ShellScript */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); diff --git a/VimR/VimR/ShortcutsPref.swift b/VimR/VimR/ShortcutsPref.swift index 0c1abd924..e34245535 100644 --- a/VimR/VimR/ShortcutsPref.swift +++ b/VimR/VimR/ShortcutsPref.swift @@ -8,6 +8,24 @@ import PureLayout import RxSwift import ShortcutRecorder +final class ShortcutValueTransformer: ValueTransformer { + static let shared = ShortcutValueTransformer() + + override class func allowsReverseTransformation() -> Bool { true } + + /// Data to Shortcut + override func transformedValue(_ value: Any?) -> Any? { + guard let value, let data = value as? Data else { return nil } + return try? NSKeyedUnarchiver.unarchivedObject(ofClass: Shortcut.self, from: data) + } + + /// Shortcut to Data + override func reverseTransformedValue(_ value: Any?) -> Any? { + guard let value, let shortcut = value as? Shortcut else { return nil } + return try? NSKeyedArchiver.archivedData(withRootObject: shortcut, requiringSecureCoding: true) + } +} + final class ShortcutsPref: PrefPane, UiComponent, NSOutlineViewDelegate, @@ -93,9 +111,7 @@ final class ShortcutsPref: PrefPane, shortcut = defaultShortcuts[id] ?? nil } - let data = ValueTransformer - .keyedUnarchiveFromDataTransformer - .reverseTransformedValue(shortcut) as? NSData + let data = ShortcutValueTransformer.shared.reverseTransformedValue(shortcut) as? NSData self.shortcutsUserDefaults?.set(data, forKey: id) } @@ -103,7 +119,7 @@ final class ShortcutsPref: PrefPane, } private func initShortcutUserDefaults() { - let transformer = ValueTransformer.keyedUnarchiveFromDataTransformer + let transformer = ShortcutValueTransformer.shared defaultShortcuts.forEach { id, shortcut in if self.shortcutsUserDefaults?.value(forKey: id) == nil { let shortcutData = transformer.reverseTransformedValue(shortcut) as? NSData @@ -206,7 +222,7 @@ final class ShortcutsPref: PrefPane, } private func updateShortcutService() { - let transformer = ValueTransformer.keyedUnarchiveFromDataTransformer + let transformer = ShortcutValueTransformer.shared let shortcuts = defaultShortcuts.compactMap { id, shortcut -> Shortcut? in if self.shortcutsUserDefaults?.value(forKey: id) == nil { return shortcut } @@ -269,9 +285,7 @@ extension ShortcutsPref { guard response == .alertSecondButtonReturn else { return } self.traverseMenuItems { identifier, _ in let shortcut = defaultShortcuts[identifier] ?? Shortcut(keyEquivalent: "") - let valueToWrite = ValueTransformer - .keyedUnarchiveFromDataTransformer - .reverseTransformedValue(shortcut) + let valueToWrite = ShortcutValueTransformer.shared.reverseTransformedValue(shortcut) self.shortcutsDefaultsController.setValue(valueToWrite, forKeyPath: "values.\(identifier)") @@ -329,8 +343,7 @@ extension ShortcutsPref { forKeyPath: "values.\(identifier)" ) as? NSData else { return true } - guard let shortcutFromDefaults = ValueTransformer - .keyedUnarchiveFromDataTransformer + guard let shortcutFromDefaults = ShortcutValueTransformer.shared .transformedValue(dataFromDefaults) as? Shortcut else { return true } let defaultShortcut = defaultShortcuts[identifier] ?? nil @@ -353,9 +366,9 @@ private let defaultsVersion = 337 private class DataToKeyEquivalentTransformer: ValueTransformer { override func transformedValue(_ value: Any?) -> Any? { - guard let shortcut = ValueTransformer - .keyedUnarchiveFromDataTransformer - .transformedValue(value) as? Shortcut else { return "" } + guard let shortcut = ShortcutValueTransformer.shared.transformedValue(value) as? Shortcut else { + return "" + } return KeyEquivalentTransformer.shared.transformedValue(shortcut) } @@ -363,8 +376,7 @@ private class DataToKeyEquivalentTransformer: ValueTransformer { private class DataToKeyEquivalentModifierMaskTransformer: ValueTransformer { override func transformedValue(_ value: Any?) -> Any? { - guard let shortcut = ValueTransformer - .keyedUnarchiveFromDataTransformer + guard let shortcut = ShortcutValueTransformer.shared .transformedValue(value) as? Shortcut else { return NSNumber(value: 0) } return KeyEquivalentModifierMaskTransformer.shared.transformedValue(shortcut) diff --git a/VimR/VimR/ShortcutsTableSubviews.swift b/VimR/VimR/ShortcutsTableSubviews.swift index 56a89b0f3..b0b05e76e 100644 --- a/VimR/VimR/ShortcutsTableSubviews.swift +++ b/VimR/VimR/ShortcutsTableSubviews.swift @@ -40,7 +40,7 @@ final class ShortcutTableCell: NSTableCellView { .value, to: content, withKeyPath: keypath, - options: [.valueTransformer: ValueTransformer.keyedUnarchiveFromDataTransformer] + options: [.valueTransformer: ShortcutValueTransformer.shared] ) }