Skip to content

Commit

Permalink
Merge pull request #12 from pedrommcarrasco/swiftMigration4.2
Browse files Browse the repository at this point in the history
Migration to Swift 4.2
  • Loading branch information
anafpf authored Sep 21, 2018
2 parents 473b9d8 + 4d104e2 commit 6dd0c54
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: swift
osx_image: xcode9.3
osx_image: xcode10

install: true

Expand Down
5 changes: 3 additions & 2 deletions Constrictor.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.swift_version = "4.1"
s.swift_version = "4.2"
s.name = "Constrictor"
s.version = "2.0.0"
s.version = "3.0.0"
s.summary = "🐍 AutoLayout's µFramework"

s.description = "(Boe) Constrictor's AutoLayout µFramework with the goal of simplying your constraints by reducing the amount of code you have to write."
Expand All @@ -16,4 +16,5 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/pedrommcarrasco/Constrictor.git", :tag => s.version.to_s }

s.source_files = "Constrictor/Constrictor/**/*"
s.exclude_files = "Constrictor/Constrictor/*.plist"
end
18 changes: 10 additions & 8 deletions Constrictor/Constrictor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0930;
LastUpgradeCheck = 0930;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = "Pedro Carrasco";
TargetAttributes = {
53CDE3BD20B3201E007E4AE0 = {
Expand Down Expand Up @@ -453,10 +453,11 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = NO;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -514,6 +515,7 @@
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 4.2;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -525,7 +527,7 @@
buildSettings = {
CLANG_ENABLE_CODE_COVERAGE = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
Expand All @@ -545,7 +547,7 @@
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -555,7 +557,7 @@
buildSettings = {
CLANG_ENABLE_CODE_COVERAGE = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
Expand All @@ -574,7 +576,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand All @@ -595,7 +597,7 @@
PRODUCT_BUNDLE_IDENTIFIER = pedrommcarrasco.ConstrictorTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -615,7 +617,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = pedrommcarrasco.ConstrictorTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0930"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public extension Constrictable {
*/

@discardableResult
func constrictToController(_ viewController: UIViewController, as relation: NSLayoutRelation = .equal,
func constrictToController(_ viewController: UIViewController, as relation: NSLayoutConstraint.Relation = .equal,
to attributes: ConstrictorAttribute ..., with constant: Constant = .zero,
multiplyBy multiplier: CGFloat = 1.0, prioritizeAs priority: UILayoutPriority = .required) -> Self {

Expand Down Expand Up @@ -56,7 +56,7 @@ public extension Constrictable {
*/

@discardableResult
func constrict(as relation: NSLayoutRelation = .equal, to item: Constrictable? = nil,
func constrict(as relation: NSLayoutConstraint.Relation = .equal, to item: Constrictable? = nil,
attributes: ConstrictorAttribute ..., with constant: Constant = .zero,
multiplyBy multiplier: CGFloat = 1.0, prioritizeAs priority: UILayoutPriority = .required) -> Self {

Expand Down Expand Up @@ -88,7 +88,7 @@ public extension Constrictable {
*/

@discardableResult
func constrict(_ selfAttribute: ConstrictorAttribute, as relation: NSLayoutRelation = .equal,
func constrict(_ selfAttribute: ConstrictorAttribute, as relation: NSLayoutConstraint.Relation = .equal,
to item: Constrictable? = nil, attribute: ConstrictorAttribute = .none,
with constant: CGFloat = 0.0, multiplyBy multiplier: CGFloat = 1.0,
prioritizeAs priority: UILayoutPriority = .required) -> Self {
Expand Down Expand Up @@ -126,7 +126,7 @@ public extension Constrictable where Self: UIView {
*/

@discardableResult
func constrictToParent(as relation: NSLayoutRelation = .equal,
func constrictToParent(as relation: NSLayoutConstraint.Relation = .equal,
attributes: ConstrictorAttribute ...,
with constant: Constant = .zero,
multiplyBy multiplier: CGFloat = 1.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public extension Constrictable {

@discardableResult
func constrictCenterInController(_ viewController: UIViewController,
as relation: NSLayoutRelation = .equal,
as relation: NSLayoutConstraint.Relation = .equal,
with constant: Constant = .zero,
multiplyBy multiplier: CGFloat = 1.0,
prioritizeAs priority: UILayoutPriority = .required,
Expand Down Expand Up @@ -56,7 +56,7 @@ public extension Constrictable {
*/

@discardableResult
func constrictCenter(as relation: NSLayoutRelation = .equal,
func constrictCenter(as relation: NSLayoutConstraint.Relation = .equal,
to item: Constrictable,
with constant: Constant = .zero,
multiplyBy multiplier: CGFloat = 1.0,
Expand Down Expand Up @@ -95,7 +95,7 @@ public extension Constrictable where Self: UIView {
*/

@discardableResult
func constrictCenterInParent(as relation: NSLayoutRelation = .equal,
func constrictCenterInParent(as relation: NSLayoutConstraint.Relation = .equal,
with constant: Constant = .zero,
multiplyBy multiplier: CGFloat = 1.0,
prioritizeAs priority: UILayoutPriority = .required,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ extension Constrictable {
- priority: Constraint's priority

This method's responsible for abstracting and invoking methods responsible of converting ConstrictorAttribute to
NSLayoutAttribute and normalizing the constant based on the selfAttribute
NSLayoutConstraint.Attribute and normalizing the constant based on the selfAttribute
*/

func constrict(_ selfAttribute: ConstrictorAttribute, relation: NSLayoutRelation = .equal,
func constrict(_ selfAttribute: ConstrictorAttribute, relation: NSLayoutConstraint.Relation = .equal,
to item: Constrictable, attribute: ConstrictorAttribute, constant: Constant,
multiplier: CGFloat = 1.0, priority: UILayoutPriority = .required) {

Expand Down Expand Up @@ -61,10 +61,10 @@ extension Constrictable {
- priority: Constraint's priority

This method's responsible for abstracting and invoking methods responsible of converting ConstrictorAttribute to
NSLayoutAttribute and normalizing the constant based on the selfAttribute
NSLayoutConstraint.Attribute and normalizing the constant based on the selfAttribute
*/

func constrict(_ selfAttribute: ConstrictorAttribute, relation: NSLayoutRelation = .equal,
func constrict(_ selfAttribute: ConstrictorAttribute, relation: NSLayoutConstraint.Relation = .equal,
constant: Constant, multiplier: CGFloat = 1.0, priority: UILayoutPriority = .required) {

let layoutAttributes = ItemLayoutAttributesDecoder.itemLayoutAttribute(for: self, with: selfAttribute, and: constant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public extension Constrictable {

@discardableResult
func constrictEdgesToController(_ viewController: UIViewController,
as relation: NSLayoutRelation = .equal,
as relation: NSLayoutConstraint.Relation = .equal,
with constant: Constant = .zero,
multipiedBy multiplier: CGFloat = 1.0,
prioritizeAs priority: UILayoutPriority = .required,
Expand Down Expand Up @@ -56,7 +56,7 @@ public extension Constrictable {
*/

@discardableResult
func constrictEdges(as relation: NSLayoutRelation = .equal,
func constrictEdges(as relation: NSLayoutConstraint.Relation = .equal,
to item: Constrictable,
with constant: Constant = .zero,
multiplyBy multiplier: CGFloat = 1.0,
Expand Down Expand Up @@ -95,7 +95,7 @@ public extension Constrictable where Self: UIView {
*/

@discardableResult
func constrictEdgesToParent(as relation: NSLayoutRelation = .equal,
func constrictEdgesToParent(as relation: NSLayoutConstraint.Relation = .equal,
with constant: Constant = .zero,
multiplyBy multiplier: CGFloat = 1.0,
prioritizeAs priority: UILayoutPriority = .required,
Expand Down
32 changes: 16 additions & 16 deletions Constrictor/Constrictor/Handlers/ItemLayoutAttributesDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ struct ItemLayoutAttributesDecoder {
// MARK: Internal Functions

/**
Converts ConstrictorAttribute to NSLayoutAttribute based on an optional Constrictable
Converts ConstrictorAttribute to NSLayoutConstraint.Attribute based on an optional Constrictable

- parameters:
- item: Optional Constrictable's to extract NSLayoutAttribute from.
- item: Optional Constrictable's to extract NSLayoutConstraint.Attribute from.

- returns:
Tuple containing the item to apply a constraint and its attribute.
*/

static func itemLayoutAttribute(for item: Constrictable?,
with attribute: ConstrictorAttribute,
and constant: Constant) -> (item: Any?, layoutAttribute: NSLayoutAttribute, constant: CGFloat) {
and constant: Constant) -> (item: Any?, layoutAttribute: NSLayoutConstraint.Attribute, constant: CGFloat) {

var itemLayoutAttributeTuple: (item: Any?, layoutAttribute: NSLayoutAttribute, constant: CGFloat) = (nil, .notAnAttribute, 0.0)
var itemLayoutAttributeTuple: (item: Any?, layoutAttribute: NSLayoutConstraint.Attribute, constant: CGFloat) = (nil, .notAnAttribute, 0.0)

if let view = item as? UIView {
itemLayoutAttributeTuple = itemLayoutAttribute(view: view, with: attribute, and: constant)
Expand All @@ -48,37 +48,37 @@ struct ItemLayoutAttributesDecoder {
private extension ItemLayoutAttributesDecoder {

/**
Converts ConstrictorAttribute to NSLayoutAttribute based on an UILayoutGuite
Converts ConstrictorAttribute to NSLayoutConstraint.Attribute based on an UILayoutGuite

- parameters:
- layoutGuide: UILayoutGuide to extract NSLayoutAttribute from.
- layoutGuide: UILayoutGuide to extract NSLayoutConstraint.Attribute from.

- returns:
Tuple containing the item to apply a constraint and its attribute.
*/

static func itemLayoutAttribute(layoutGuide: UILayoutGuide,
with attribute: ConstrictorAttribute,
and constantStruct: Constant) -> (item: Any?, layoutAttribute: NSLayoutAttribute, constant: CGFloat) {
and constantStruct: Constant) -> (item: Any?, layoutAttribute: NSLayoutConstraint.Attribute, constant: CGFloat) {

let attributeAndConstantTuple = defaultLayoutAttributeAndConstant(for: attribute, with: constantStruct)

return (layoutGuide, attributeAndConstantTuple.attribute, attributeAndConstantTuple.constant)
}

/**
Converts ConstrictorAttribute to NSLayoutAttribute based on an UIView
Converts ConstrictorAttribute to NSLayoutConstraint.Attribute based on an UIView

- parameters:
- view: UIView to extract NSLayoutAttribute from.
- view: UIView to extract NSLayoutConstraint.Attribute from.

- returns:
Tuple containing the item to apply a constraint and its attribute.
*/

static func itemLayoutAttribute(view: UIView,
with attribute: ConstrictorAttribute,
and constantStruct: Constant) -> (item: Any?, layoutAttribute: NSLayoutAttribute, constant: CGFloat) {
and constantStruct: Constant) -> (item: Any?, layoutAttribute: NSLayoutConstraint.Attribute, constant: CGFloat) {

let safeArea: Any

Expand All @@ -94,21 +94,21 @@ private extension ItemLayoutAttributesDecoder {
}

/**
Converts ConstrictorAttribute to NSLayoutAttribute based on an UIViewController
Converts ConstrictorAttribute to NSLayoutConstraint.Attribute based on an UIViewController

- parameters:
- viewController: UIViewController to extract NSLayoutAttribute from.
- viewController: UIViewController to extract NSLayoutConstraint.Attribute from.

- returns:
Tuple containing the item to apply a constraint and its attribute.
*/

static func itemLayoutAttribute(viewController: UIViewController,
with constrictorAttribute: ConstrictorAttribute,
and constantStruct: Constant) -> (item: Any?, layoutAttribute: NSLayoutAttribute, constant: CGFloat) {
and constantStruct: Constant) -> (item: Any?, layoutAttribute: NSLayoutConstraint.Attribute, constant: CGFloat) {

var safeArea: Any
let attribute: NSLayoutAttribute
let attribute: NSLayoutConstraint.Attribute
let isIOS11: Bool
let constant: CGFloat

Expand Down Expand Up @@ -194,9 +194,9 @@ private extension ItemLayoutAttributesDecoder {
private extension ItemLayoutAttributesDecoder {

static func defaultLayoutAttributeAndConstant(for constrictorAttribute: ConstrictorAttribute,
with constantStruct: Constant) -> (attribute: NSLayoutAttribute, constant: CGFloat) {
with constantStruct: Constant) -> (attribute: NSLayoutConstraint.Attribute, constant: CGFloat) {

let attribute: NSLayoutAttribute
let attribute: NSLayoutConstraint.Attribute
let constant: CGFloat

switch constrictorAttribute {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// NSLayoutAttribute+Finder.swift
// NSLayoutConstraint.Attribute+Finder.swift
// ConstrictorTests
//
// Created by Pedro Carrasco on 23/05/2018.
Expand All @@ -10,15 +10,15 @@ import UIKit

extension NSLayoutConstraint {

func isFrom(_ attribute: NSLayoutAttribute, relatedTo view: UIView?, at index: ConstraintIndex) -> Bool {
func isFrom(_ attribute: NSLayoutConstraint.Attribute, relatedTo view: UIView?, at index: ConstraintIndex) -> Bool {

return isItem(at: view, from: index, anAttributeFrom: attribute)
}
}

private extension NSLayoutConstraint {

func isItem(at view: UIView?, from index: ConstraintIndex, anAttributeFrom attribute: NSLayoutAttribute) -> Bool {
func isItem(at view: UIView?, from index: ConstraintIndex, anAttributeFrom attribute: NSLayoutConstraint.Attribute) -> Bool {

return index.item(from: self) == view && firstAttribute == attribute
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

extension UIView {

func findConstraints(for attribute: NSLayoutAttribute,
func findConstraints(for attribute: NSLayoutConstraint.Attribute,
relatedTo view: UIView? = nil,
at index: ConstraintIndex = .firstItem) -> [NSLayoutConstraint] {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension ConstraintTestable where Self: XCTestCase {
func testConstraint(_ constraint: NSLayoutConstraint,
constant: CGFloat = 0.0,
multiplier: CGFloat = 1.0,
relation: NSLayoutRelation = .equal,
relation: NSLayoutConstraint.Relation = .equal,
priority: UILayoutPriority = .required,
isActive: Bool = true) {

Expand Down
Loading

0 comments on commit 6dd0c54

Please sign in to comment.