Skip to content

Commit

Permalink
Drop support for Swift earlier than 4.0
Browse files Browse the repository at this point in the history
...
  • Loading branch information
helje5 committed Dec 23, 2023
1 parent 77afa40 commit f742326
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 64 deletions.
11 changes: 3 additions & 8 deletions Sources/UXKit/AppKit/NSTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// UXKit
//
// Copyright © 2016-2019 ZeeZide GmbH. All rights reserved.
// Copyright © 2016-2023 ZeeZide GmbH. All rights reserved.
//
#if os(macOS)
import Cocoa
Expand Down Expand Up @@ -43,13 +43,8 @@
let padding : CGFloat = 8.0
let labelPadding : CGFloat = 4.0

#if swift(>=4.0)
let labelSize = UXFont.systemFontSize + 4.0
let detailLabelSize = UXFont.smallSystemFontSize
#else
let labelSize = UXFont.systemFontSize() + 4.0
let detailLabelSize = UXFont.smallSystemFontSize()
#endif
let labelSize = UXFont.systemFontSize + 4.0
let detailLabelSize = UXFont.smallSystemFontSize

//let detailColor = UXColor.secondaryLabelColor // 10.10
let detailColor = UXColor.darkGray
Expand Down
8 changes: 2 additions & 6 deletions Sources/UXKit/AppKit/UXGraphics-AppKit.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// UXKit
//
// Copyright © 2016-2022 ZeeZide GmbH. All rights reserved.
// Copyright © 2016-2023 ZeeZide GmbH. All rights reserved.
//
#if os(macOS)
import Cocoa
Expand All @@ -18,11 +18,7 @@

public typealias UXImage = NSImage

#if swift(>=4.0)
public typealias UXEdgeInsets = NSEdgeInsets
#else
public typealias UXEdgeInsets = EdgeInsets
#endif
public typealias UXEdgeInsets = NSEdgeInsets

public extension UXColor {

Expand Down
23 changes: 4 additions & 19 deletions Sources/UXKit/AppKit/UXLayout-AppKit.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// UXKit
//
// Copyright © 2016-2021 ZeeZide GmbH. All rights reserved.
// Copyright © 2016-2023 ZeeZide GmbH. All rights reserved.
//
#if os(macOS)
import Cocoa
Expand All @@ -11,25 +11,10 @@
@available(OSX 10.11, *)
public typealias UXLayoutGuide = NSLayoutGuide

#if swift(>=4.0)
public extension NSStackView {
typealias Alignment = NSLayoutConstraint.Attribute
typealias UXAlignment = NSLayoutConstraint.Attribute
typealias Axis = NSUserInterfaceLayoutOrientation
typealias Alignment = NSLayoutConstraint.Attribute
typealias UXAlignment = NSLayoutConstraint.Attribute
typealias Axis = NSUserInterfaceLayoutOrientation
}
#else // Swift 3.2
public extension NSLayoutConstraint {
public typealias Attribute = NSLayoutAttribute
public typealias Relation = NSLayoutRelation
#if false // crashes 3.2 in Xcode 9 9A235 - Because it exists? in 3.2? But not in 3.1?
public typealias Priority = NSLayoutPriority
#endif
}
public extension NSStackView {
public typealias Distribution = NSStackViewDistribution
public typealias Alignment = NSLayoutAttribute
public typealias UXAlignment = NSLayoutAttribute
}
#endif
public typealias UXStackViewAxis = NSUserInterfaceLayoutOrientation
#endif
26 changes: 7 additions & 19 deletions Sources/UXKit/AppKit/UXView-AppKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@

// MARK: - UXUserInterfaceItemIdentification

#if os(macOS) && swift(>=4.0)
public typealias UXUserInterfaceItemIdentifier =
NSUserInterfaceItemIdentifier
#else
public typealias UXUserInterfaceItemIdentifier = String
#endif
public typealias UXUserInterfaceItemIdentifier =
NSUserInterfaceItemIdentifier

public typealias UXUserInterfaceItemIdentification =
NSUserInterfaceItemIdentification
Expand Down Expand Up @@ -90,19 +86,11 @@
/// Add UISwitch `isOn` property. The AppKit variant has 3 states.
public extension NSButton {

#if swift(>=4.0)
/// Use this instead of `state` for UIKit compatibility.
var isOn: Bool {
set { state = newValue ? .on : .off }
get { return state == .on }
}
#else // Swift 3
/// Use this instead of `state` for UIKit compatibility.
public var isOn: Bool {
set { state = newValue ? NSOnState : NSOffState }
get { return state == NSOnState }
}
#endif
/// Use this instead of `state` for UIKit compatibility.
var isOn: Bool {
set { state = newValue ? .on : .off }
get { return state == .on }
}
}

public extension NSTextField {
Expand Down
24 changes: 12 additions & 12 deletions Sources/UXKit/Common/UXIndexPath.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
//
// UXKit
//
// Copyright © 2016-2017 ZeeZide GmbH. All rights reserved.
// Copyright © 2016-2023 ZeeZide GmbH. All rights reserved.
//
import Foundation

#if os(macOS)
#if swift(>=4.0)
// Hm. It does seem to have it (produces ambiguities). But maybe not.
import AppKit
#else
public extension IndexPath {

public init(row: Int, section: Int) {
self.init(indexes: [ section, row ])
}
public var section : Int { return self[0] }
public var row : Int { return self[1] }
import AppKit

// Hm. It does seem to have it (produces ambiguities). But maybe not.
#if false
public extension IndexPath {

public init(row: Int, section: Int) {
self.init(indexes: [ section, row ])
}
public var section : Int { return self[0] }
public var row : Int { return self[1] }
}
#endif
#endif

Expand Down

0 comments on commit f742326

Please sign in to comment.