Skip to content

Commit

Permalink
Update for Swift 6
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Sep 13, 2024
1 parent a2ffb1b commit 495ff8c
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 84 deletions.
43 changes: 31 additions & 12 deletions Align.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -207,8 +207,9 @@
0CE3610F1C86077B00EA70CF /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 0800;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1600;
ORGANIZATIONNAME = "Alexander Grebenyuk";
TargetAttributes = {
0CC3A0661D7476A700754E59 = {
Expand Down Expand Up @@ -305,7 +306,11 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_WARN_SUSPICIOUS_MOVES = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.github.kean.Align-iOS-Tests";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
Expand All @@ -316,7 +321,11 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_WARN_SUSPICIOUS_MOVES = YES;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.github.kean.Align-iOS-Tests";
PRODUCT_NAME = "$(TARGET_NAME)";
};
Expand All @@ -335,13 +344,14 @@
"$(inherited)",
);
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 10.13;
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
MACOSX_DEPLOYMENT_TARGET = 11.5;
ONLY_ACTIVE_ARCH = YES;
SUPPORTED_PLATFORMS = "iphoneos appletvos iphonesimulator appletvsimulator macosx";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
TVOS_DEPLOYMENT_TARGET = 15.6;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand All @@ -355,12 +365,13 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 10.13;
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
MACOSX_DEPLOYMENT_TARGET = 11.5;
SUPPORTED_PLATFORMS = "iphoneos appletvos iphonesimulator appletvsimulator macosx";
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
TVOS_DEPLOYMENT_TARGET = 15.6;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -376,7 +387,11 @@
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 3.2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.github.kean.Align;
PRODUCT_NAME = Align;
Expand All @@ -393,7 +408,11 @@
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 3.2.0;
PRODUCT_BUNDLE_IDENTIFIER = com.github.kean.Align;
PRODUCT_NAME = Align;
Expand Down
2 changes: 1 addition & 1 deletion Align.xcodeproj/xcshareddata/xcschemes/Align.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1600"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import PackageDescription
let package = Package(
name: "Align",
platforms: [
.iOS(.v13),
.tvOS(.v13),
.macOS(.v10_15),
.iOS(.v14),
.tvOS(.v14),
.macOS(.v10_16),
],
products: [
.library(name: "Align", targets: ["Align"]),
Expand Down
47 changes: 23 additions & 24 deletions Sources/Align.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import AppKit
#endif

/// A type that has layout anchors: either a view or a layout guide.
public protocol LayoutItem {
@MainActor public protocol LayoutItem {
#if os(iOS) || os(tvOS)
var superview: UIView? { get }
#else
Expand Down Expand Up @@ -37,7 +37,7 @@ extension LayoutItem { // Align methods are available via `LayoutAnchors`
// MARK: - LayoutAnchors

/// Provides access to the layout anchors and anchor collections.
public struct LayoutAnchors<T: LayoutItem> {
@MainActor public struct LayoutAnchors<T: LayoutItem> {
/// The underlying item.
public let item: T

Expand Down Expand Up @@ -104,7 +104,7 @@ public enum AnchorType {
///
/// - tip: `UIView` does not provide anchor properties for the layout margin attributes.
/// Instead, call `view.layoutMarginsGuide.anchors`.
public struct Anchor<Type, Axis> { // type and axis are phantom types
@MainActor public struct Anchor<Type, Axis> { // type and axis are phantom types
let item: LayoutItem
let attribute: NSLayoutConstraint.Attribute
let offset: CGFloat
Expand All @@ -130,23 +130,23 @@ public struct Anchor<Type, Axis> { // type and axis are phantom types
}

/// Returns a new anchor offset by a given amount.
public func + <Type, Axis>(anchor: Anchor<Type, Axis>, offset: CGFloat) -> Anchor<Type, Axis> {
@MainActor public func + <Type, Axis>(anchor: Anchor<Type, Axis>, offset: CGFloat) -> Anchor<Type, Axis> {
anchor.offsetting(by: offset)
}

/// Returns a new anchor offset by a given amount.
public func - <Type, Axis>(anchor: Anchor<Type, Axis>, offset: CGFloat) -> Anchor<Type, Axis> {
@MainActor public func - <Type, Axis>(anchor: Anchor<Type, Axis>, offset: CGFloat) -> Anchor<Type, Axis> {
anchor.offsetting(by: -offset)
}

/// Returns a new anchor with an constant multiplied by the given amount.
public func * <Type, Axis>(anchor: Anchor<Type, Axis>, multiplier: CGFloat) -> Anchor<Type, Axis> {
@MainActor public func * <Type, Axis>(anchor: Anchor<Type, Axis>, multiplier: CGFloat) -> Anchor<Type, Axis> {
anchor.multiplied(by: multiplier)
}

// MARK: - Anchors (AnchorType.Alignment)

public extension Anchor where Type: AnchorType.Alignment {
@MainActor public extension Anchor where Type: AnchorType.Alignment {
@discardableResult func equal<OtherType: AnchorType.Alignment>(_ anchor: Anchor<OtherType, Axis>, constant: CGFloat = 0) -> NSLayoutConstraint {
Constraints.add(self, anchor, constant: constant, relation: .equal)
}
Expand All @@ -162,7 +162,7 @@ public extension Anchor where Type: AnchorType.Alignment {

// MARK: - Anchors (AnchorType.Dimension)

public extension Anchor where Type: AnchorType.Dimension {
@MainActor public extension Anchor where Type: AnchorType.Dimension {
@discardableResult func equal<OtherType: AnchorType.Dimension, OtherAxis>(_ anchor: Anchor<OtherType, OtherAxis>, constant: CGFloat = 0) -> NSLayoutConstraint {
Constraints.add(self, anchor, constant: constant, relation: .equal)
}
Expand All @@ -178,7 +178,7 @@ public extension Anchor where Type: AnchorType.Dimension {

// MARK: - Anchors (AnchorType.Dimension)

public extension Anchor where Type: AnchorType.Dimension {
@MainActor public extension Anchor where Type: AnchorType.Dimension {
@discardableResult func equal(_ constant: CGFloat) -> NSLayoutConstraint {
Constraints.add(item: item, attribute: attribute, relatedBy: .equal, constant: constant)
}
Expand All @@ -199,7 +199,7 @@ public extension Anchor where Type: AnchorType.Dimension {

// MARK: - Anchors (AnchorType.Edge)

public extension Anchor where Type: AnchorType.Edge {
@MainActor public extension Anchor where Type: AnchorType.Edge {
/// Pins the edge to the respected edges of the given container.
@discardableResult func pin(to container: LayoutItem? = nil, inset: CGFloat = 0) -> NSLayoutConstraint {
let isInverted = [.trailing, .right, .bottom].contains(attribute)
Expand All @@ -217,7 +217,7 @@ public extension Anchor where Type: AnchorType.Edge {

// MARK: - Anchors (AnchorType.Center)

public extension Anchor where Type: AnchorType.Center {
@MainActor public extension Anchor where Type: AnchorType.Center {
/// Aligns the axis with a superview axis.
@discardableResult func align(offset: CGFloat = 0) -> NSLayoutConstraint {
Constraints.add(self, toItem: item.superview!, attribute: attribute, constant: offset)
Expand All @@ -227,7 +227,7 @@ public extension Anchor where Type: AnchorType.Center {
// MARK: - AnchorCollectionEdges

/// Create multiple constraints at once by operating more than one edge at once.
public struct AnchorCollectionEdges {
@MainActor public struct AnchorCollectionEdges {
let item: LayoutItem
var isAbsolute = false

Expand Down Expand Up @@ -317,10 +317,10 @@ public struct AnchorCollectionEdges {
return constraints
}

public struct Alignment {
public struct Alignment: Sendable {

/// The alignment along the horizontal axis.
public enum Horizontal {
public enum Horizontal: Sendable {
/// Pin both leading and trailing edges to the superview.
case fill
/// Center the view in the container along the vertical axis.
Expand All @@ -336,7 +336,7 @@ public struct AnchorCollectionEdges {
}

/// The alignment along the vertical axis.
public enum Vertical {
public enum Vertical: Sendable {
/// Pin both top and bottom edges to the superview.
case fill
/// Center the view in the container along the vertical axis.
Expand Down Expand Up @@ -404,7 +404,7 @@ public struct AnchorCollectionEdges {
// MARK: - AnchorCollectionCenter

/// Create multiple constraints at once by using both `centerX` and `centerY` anchors.
public struct AnchorCollectionCenter {
@MainActor public struct AnchorCollectionCenter {
let x: Anchor<AnchorType.Center, AnchorAxis.Horizontal>
let y: Anchor<AnchorType.Center, AnchorAxis.Vertical>

Expand Down Expand Up @@ -438,7 +438,7 @@ public struct AnchorCollectionCenter {
// MARK: - AnchorCollectionSize

/// Create multiple constraints at once by using both `width` and `height` anchors.
public struct AnchorCollectionSize {
@MainActor public struct AnchorCollectionSize {
let width: Anchor<AnchorType.Dimension, AnchorAxis.Horizontal>
let height: Anchor<AnchorType.Dimension, AnchorAxis.Vertical>

Expand Down Expand Up @@ -504,16 +504,16 @@ public struct AnchorCollectionSize {
/// // Create your constraints here
/// }
/// ```
public final class Constraints: Collection {
@MainActor public final class Constraints: Collection {
public typealias Element = NSLayoutConstraint
public typealias Index = Int

public subscript(position: Int) -> NSLayoutConstraint {
get { constraints[position] }
public nonisolated subscript(position: Int) -> NSLayoutConstraint {
get { MainActor.assumeIsolated { constraints[position] } }
}
public var startIndex: Int { constraints.startIndex }
public var endIndex: Int { constraints.endIndex }
public func index(after i: Int) -> Int { i + 1 }
public nonisolated var startIndex: Int { MainActor.assumeIsolated { constraints.startIndex } }
public nonisolated var endIndex: Int { MainActor.assumeIsolated { constraints.endIndex } }
public nonisolated func index(after i: Int) -> Int { i + 1 }

/// Returns all of the created constraints.
public private(set) var constraints = [NSLayoutConstraint]()
Expand Down Expand Up @@ -548,7 +548,6 @@ public final class Constraints: Collection {

/// Creates and automatically installs a constraint.
static func add(item item1: Any, attribute attr1: NSLayoutConstraint.Attribute, relatedBy relation: NSLayoutConstraint.Relation = .equal, toItem item2: Any? = nil, attribute attr2: NSLayoutConstraint.Attribute? = nil, multiplier: CGFloat = 1, constant: CGFloat = 0) -> NSLayoutConstraint {
precondition(Thread.isMainThread, "Align APIs can only be used from the main thread")
#if os(iOS) || os(tvOS)
(item1 as? UIView)?.translatesAutoresizingMaskIntoConstraints = false
#elseif os(macOS)
Expand Down
6 changes: 3 additions & 3 deletions Tests/AnchorAPIsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import Foundation
import XCTest
import Align

@MainActor
class AnchorAPITests: XCTestCase {
let view = View()
let container = View()

override func setUp() {
super.setUp()

@MainActor
override func setUp() async throws {
container.addSubview(view)
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/AnchorAlignmentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import XCTest
import Align

/// Everything that applies for both edges and center
@MainActor
class AnchorAlignmentTests: XCTestCase {
let container = View()
let view = View()
let a = View()
let b = View()

override func setUp() {
super.setUp()

@MainActor
override func setUp() async throws {
container.addSubview(view)
container.addSubview(a)
container.addSubview(b)
Expand Down
6 changes: 3 additions & 3 deletions Tests/AnchorCenterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import XCTest
import Align

@MainActor
class AnchorCenterTests: XCTestCase {
let container = View()
let view = View()

override func setUp() {
super.setUp()

@MainActor
override func setUp() async throws {
container.addSubview(view)
}

Expand Down
7 changes: 3 additions & 4 deletions Tests/AnchorCollectionCenterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import XCTest
import Align


@MainActor
class AnchorCollectionCenterTests: XCTestCase {
let container = View()
let view = View()

override func setUp() {
super.setUp()

@MainActor
override func setUp() async throws {
container.addSubview(view)
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/AnchorCollectionEdgesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import XCTest
import Align

@MainActor
class AnchorCollectionEdgesTests: XCTestCase {
let container = View()
let view = View()

override func setUp() {
super.setUp()

@MainActor
override func setUp() async throws {
container.addSubview(view)
}

Expand Down
Loading

0 comments on commit 495ff8c

Please sign in to comment.