Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict Concurrency #109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// swift-tools-version:5.0
// swift-tools-version:5.9
import PackageDescription

let package = Package(
name: "TinyConstraints",
platforms: [
.macOS(.v10_11), .iOS(.v9), .tvOS(.v9)
.macOS(.v10_15), .iOS(.v15), .tvOS(.v15)
],
products: [
.library(name: "TinyConstraints", targets: ["TinyConstraints"])
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<img src="Art/header.png" width="890" alt="TinyConstraints"/>
</p>

Version 5.x is made for projects using Swift oncurrency checking set to Complete.
Version 4.x is for older projects.

## Features

- [X] Pure Swift 5 sweetness.
Expand Down
8 changes: 4 additions & 4 deletions TinyConstraints.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'TinyConstraints'
s.version = '4.0.2'
s.version = '5.0.0'
s.swift_versions = [5.0]
s.summary = 'TinyConstraints is the syntactic sugar that makes Auto Layout sweeter for human use.'
s.description = <<-DESC
Expand All @@ -11,8 +11,8 @@ TinyConstraints is the syntactic sugar library that makes Auto Layout sweeter fo
s.author = { 'Robert-Hein Hooijmans' => '[email protected]' }
s.source = { :git => 'https://github.com/roberthein/TinyConstraints.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/roberthein'
s.ios.deployment_target = '9.0'
s.tvos.deployment_target = '9.0'
s.osx.deployment_target = '10.11'
s.ios.deployment_target = '15.0'
s.tvos.deployment_target = '15.0'
s.osx.deployment_target = '10.15'
s.source_files = 'TinyConstraints/Classes/**/*.{swift}'
end
54 changes: 43 additions & 11 deletions TinyConstraints.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 All @@ -30,6 +30,9 @@
A932CB741F78081B00401861 /* TinyConstraints+superview.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TinyConstraints+superview.swift"; sourceTree = "<group>"; };
A97552CD2128478300C1EC7E /* TinyEdgeInsets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TinyEdgeInsets.swift; sourceTree = "<group>"; };
A9D467D01E6777CA00C331FA /* Abstraction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Abstraction.swift; sourceTree = "<group>"; };
D0814C6E2BCEC92E00430BF8 /* TinyConstraints.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = TinyConstraints.podspec; sourceTree = "<group>"; };
D0814C6F2BCEC92E00430BF8 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
D0814C702BCEC92E00430BF8 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -46,6 +49,9 @@
2DD986F11E4DB973002F80D6 = {
isa = PBXGroup;
children = (
D0814C702BCEC92E00430BF8 /* Package.swift */,
D0814C6F2BCEC92E00430BF8 /* README.md */,
D0814C6E2BCEC92E00430BF8 /* TinyConstraints.podspec */,
2DD986FD1E4DB973002F80D6 /* TinyConstraints */,
2DD986FC1E4DB973002F80D6 /* Products */,
);
Expand Down Expand Up @@ -131,7 +137,8 @@
2DD986F21E4DB973002F80D6 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1020;
BuildIndependentTargetsInParallel = YES;
LastUpgradeCheck = 1530;
ORGANIZATIONNAME = "Robert-Hein Hooijmans";
TargetAttributes = {
2DD986FA1E4DB973002F80D6 = {
Expand Down Expand Up @@ -213,6 +220,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -221,9 +229,11 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand All @@ -238,15 +248,16 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MACOSX_DEPLOYMENT_TARGET = 10.11;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 10.0;
TVOS_DEPLOYMENT_TARGET = 15.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -278,6 +289,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -286,9 +298,11 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
Expand All @@ -297,13 +311,15 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MACOSX_DEPLOYMENT_TARGET = 10.11;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
MTL_ENABLE_DEBUG_INFO = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TVOS_DEPLOYMENT_TARGET = 10.0;
TVOS_DEPLOYMENT_TARGET = 15.0;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -317,14 +333,22 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_CODE_COVERAGE = NO;
CODE_SIGN_IDENTITY = "";
DEAD_CODE_STRIPPING = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_BITCODE = NO;
ENABLE_MODULE_VERIFIER = YES;
INFOPLIST_FILE = TinyConstraints/Info.plist;
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",
);
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu99 gnu++11";
PRODUCT_BUNDLE_IDENTIFIER = com.roberthein.TinyConstraints;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -339,14 +363,22 @@
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_CODE_COVERAGE = NO;
CODE_SIGN_IDENTITY = "";
DEAD_CODE_STRIPPING = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_BITCODE = NO;
ENABLE_MODULE_VERIFIER = YES;
INFOPLIST_FILE = TinyConstraints/Info.plist;
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",
);
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu99 gnu++11";
PRODUCT_BUNDLE_IDENTIFIER = com.roberthein.TinyConstraints;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1530"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -29,8 +29,6 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -51,8 +49,6 @@
ReferencedContainer = "container:TinyConstraints.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
2 changes: 1 addition & 1 deletion TinyConstraints/Classes/Abstraction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Foundation
public typealias TinyEdgeInsets = NSEdgeInsets

public extension NSEdgeInsets {
static var zero = NSEdgeInsetsZero
static let zero = NSEdgeInsetsZero
}
#else
import UIKit
Expand Down
6 changes: 3 additions & 3 deletions TinyConstraints/Classes/Constrainable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import UIKit
#endif

extension TinyView: Constrainable {
@MainActor extension TinyView: Constrainable {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed as the compiler infers @MainActor isolation for all members declared on this extension since Constrainable is isolated to the @MainActor.

Suggested change
@MainActor extension TinyView: Constrainable {
extension LayoutGuide: Constrainable {


@discardableResult
public func prepareForLayout() -> Self {
Expand All @@ -36,12 +36,12 @@ extension TinyView: Constrainable {
}
}

extension LayoutGuide: Constrainable {
@MainActor extension LayoutGuide: Constrainable {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed as the compiler infers @MainActor isolation for all members declared on this extension since Constrainable is isolated to the @MainActor.

Suggested change
@MainActor extension LayoutGuide: Constrainable {
extension LayoutGuide: Constrainable {

@discardableResult
public func prepareForLayout() -> Self { return self }
}

public protocol Constrainable {
@MainActor public protocol Constrainable {
Copy link

@SomeRandomiOSDev SomeRandomiOSDev Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strongly recommend the following instead:

Suggested change
@MainActor public protocol Constrainable {
@preconcurrency @MainActor
public protocol Constrainable {

This makes it so that existing code that doesn't yet have strict concurrency enabled can use this library version without having to make changes to their code.

var topAnchor: NSLayoutYAxisAnchor { get }
var bottomAnchor: NSLayoutYAxisAnchor { get }
var leftAnchor: NSLayoutXAxisAnchor { get }
Expand Down
8 changes: 4 additions & 4 deletions TinyConstraints/Classes/Constraints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
public typealias Constraint = NSLayoutConstraint
public typealias Constraints = [Constraint]

public enum ConstraintRelation: Int {
public enum ConstraintRelation: Int, Sendable {
case equal = 0
case equalOrLess = -1
case equalOrGreater = 1
}

public extension Collection where Iterator.Element == Constraint {
@MainActor public extension Collection where Iterator.Element == Constraint {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strongly recommend the following instead:

Suggested change
@MainActor public extension Collection where Iterator.Element == Constraint {
@preconcurrency @MainActor
public extension Collection where Iterator.Element == Constraint {

This makes it so that existing code that doesn't yet have strict concurrency enabled can use this library version without having to make changes to their code.


func activate() {

Expand All @@ -55,7 +55,7 @@ public extension Collection where Iterator.Element == Constraint {
}

#if os(OSX)
public extension Constraint {
@MainActor public extension Constraint {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed since Constraint is already isolated to the @MainActor

Suggested change
@MainActor public extension Constraint {
public extension Constraint {

@objc
func with(_ p: Constraint.Priority) -> Self {
priority = p
Expand All @@ -68,7 +68,7 @@ public extension Constraint {
}
}
#else
public extension Constraint {
@MainActor public extension Constraint {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed since Constraint is already isolated to the @MainActor

Suggested change
@MainActor public extension Constraint {
public extension Constraint {

@objc
func with(_ p: LayoutPriority) -> Self {
priority = p
Expand Down
2 changes: 1 addition & 1 deletion TinyConstraints/Classes/Stack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import UIKit
#endif

public extension TinyView {
@MainActor public extension TinyView {
Copy link

@SomeRandomiOSDev SomeRandomiOSDev Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed since TinyView is already isolated to the @MainActor

Suggested change
@MainActor public extension TinyView {
public extension TinyView {


@discardableResult
func stack(_ views: [TinyView], axis: ConstraintAxis = .vertical, width: CGFloat? = nil, height: CGFloat? = nil, spacing: CGFloat = 0) -> Constraints {
Expand Down
8 changes: 4 additions & 4 deletions TinyConstraints/Classes/TinyConstraints+superview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#if os(OSX)
import AppKit

public extension TinyView {
@MainActor public extension TinyView {
Copy link

@SomeRandomiOSDev SomeRandomiOSDev Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed since TinyView is already isolated to the @MainActor

Suggested change
@MainActor public extension TinyView {
public extension TinyView {


@discardableResult
func edgesToSuperview(excluding excludedEdge: LayoutEdge = .none, insets: TinyEdgeInsets = .zero, usingSafeArea: Bool = false) -> Constraints {
Expand Down Expand Up @@ -53,7 +53,7 @@
#else
import UIKit

public extension TinyView {
@MainActor public extension TinyView {
Copy link

@SomeRandomiOSDev SomeRandomiOSDev Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed since TinyView is already isolated to the @MainActor

Suggested change
@MainActor public extension TinyView {
public extension TinyView {


@available(tvOS 10.0, *)
@available(iOS 10.0, *)
Expand Down Expand Up @@ -150,7 +150,7 @@
}
#endif

public struct LayoutEdge: OptionSet {
public struct LayoutEdge: OptionSet, Sendable {
public let rawValue: UInt8
public init(rawValue: UInt8) {
self.rawValue = rawValue
Expand All @@ -164,7 +164,7 @@ public struct LayoutEdge: OptionSet {
public static let none = LayoutEdge(rawValue: 1 << 6)
}

public extension TinyView {
@MainActor public extension TinyView {
Copy link

@SomeRandomiOSDev SomeRandomiOSDev Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed since TinyView is already isolated to the @MainActor

Suggested change
@MainActor public extension TinyView {
public extension TinyView {


private func safeConstrainable(for superview: TinyView?, usingSafeArea: Bool) -> Constrainable {
guard let superview = superview else {
Expand Down
4 changes: 2 additions & 2 deletions TinyConstraints/Classes/TinyConstraints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import UIKit
#endif

public extension Constrainable {
@MainActor public extension Constrainable {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed since Constrainable is already isolated to the @MainActor

Suggested change
@MainActor public extension Constrainable {
public extension Constrainable {


@discardableResult
func center(in view: Constrainable, offset: CGPoint = .zero, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraints {
Expand Down Expand Up @@ -339,7 +339,7 @@ public extension Constrainable {
}
}

public extension TinyView {
@MainActor public extension TinyView {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed since TinyView is already isolated to the @MainActor

Suggested change
@MainActor public extension TinyView {
public extension TinyView {


func setHugging(_ priority: LayoutPriority, for axis: ConstraintAxis) {
setContentHuggingPriority(priority, for: axis)
Expand Down
2 changes: 1 addition & 1 deletion TinyConstraints/Classes/TinyEdgeInsets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import UIKit
#endif

extension TinyEdgeInsets {
@MainActor extension TinyEdgeInsets {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably not recommended to add this since TinyEdgeInsets itself isn't isolated to the @MainActor and there's no code in any of these members that requires @MainActor isolation


public static func uniform(_ value: CGFloat) -> TinyEdgeInsets {
return TinyEdgeInsets(top: value, left: value, bottom: value, right: value)
Expand Down