Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
language: objective-c
osx_image: xcode7.1
osx_image: xcode8
19 changes: 18 additions & 1 deletion ManualLayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Baris Sencan";
TargetAttributes = {
5F91347C1AC9E1630001DBF8 = {
Expand All @@ -367,9 +367,11 @@
};
5FB4CBE81A9BBE7500C2FB4F = {
CreatedOnToolsVersion = 6.1.1;
LastSwiftMigration = 0800;
};
5FB4CBF31A9BBE7500C2FB4F = {
CreatedOnToolsVersion = 6.1.1;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -605,8 +607,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -616,6 +620,7 @@
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand Down Expand Up @@ -652,8 +657,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
Expand All @@ -662,6 +669,7 @@
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand All @@ -671,6 +679,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -682,6 +691,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -694,13 +704,15 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
5FB4CC011A9BBE7500C2FB4F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -712,6 +724,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.bsencan.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -730,6 +743,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.bsencan.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -744,6 +758,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.bsencan.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -752,6 +767,7 @@
buildSettings = {
BITCODE_GENERATION_MODE = bitcode;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -775,6 +791,7 @@
buildSettings = {
BITCODE_GENERATION_MODE = bitcode;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
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 = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "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 = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
50 changes: 25 additions & 25 deletions ManualLayout/HelperFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,94 +9,94 @@
import UIKit

internal func snapToPixel(pointCoordinate coordinate: CGFloat) -> CGFloat {
let screenScale = UIScreen.mainScreen().scale
let screenScale = UIScreen.main.scale
return round(coordinate * screenScale) / screenScale
}

//MARK: - Insetting

public func inset(view: UIView, amount: CGFloat) -> CGRect {
public func inset(_ view: UIView, amount: CGFloat) -> CGRect {
return inset(view.frame, amount: amount)
}

public func inset(layer: CALayer, amount: CGFloat) -> CGRect {
public func inset(_ layer: CALayer, amount: CGFloat) -> CGRect {
return inset(layer.frame, amount: amount)
}

public func inset(rect: CGRect, amount: CGFloat) -> CGRect {
return CGRectInset(rect, amount, amount)
public func inset(_ rect: CGRect, amount: CGFloat) -> CGRect {
return rect.insetBy(dx: amount, dy: amount)
}

public func inset(view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect {
public func inset(_ view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect {
return inset(view.frame, dx: dx, dy: dy)
}

public func inset(layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect {
public func inset(_ layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect {
return inset(layer.frame, dx: dx, dy: dy)
}

public func inset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect {
return CGRectInset(rect, dx, dy)
public func inset(_ rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect {
return rect.insetBy(dx: dx, dy: dy)
}

public func inset(view: UIView, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect {
public func inset(_ view: UIView, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect {
return inset(view.frame, top: top, left: left, bottom: bottom, right: right)
}

public func inset(layer: CALayer, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect {
public func inset(_ layer: CALayer, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect {
return inset(layer.frame, top: top, left: left, bottom: bottom, right: right)
}

public func inset(rect: CGRect, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect {
public func inset(_ rect: CGRect, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGRect {
return CGRect(
origin: offset(rect.origin, dx: left, dy: top),
size: inset(rect.size, top: top, left: left, bottom: bottom, right: right))
}

public func inset(size: CGSize, amount: CGFloat) -> CGSize {
public func inset(_ size: CGSize, amount: CGFloat) -> CGSize {
return inset(size, dx: amount, dy: amount)
}

public func inset(size: CGSize, dx: CGFloat, dy: CGFloat) -> CGSize {
public func inset(_ size: CGSize, dx: CGFloat, dy: CGFloat) -> CGSize {
return inset(size, top: dy, left: dx, bottom: dy, right: dx)
}

public func inset(size: CGSize, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGSize {
public func inset(_ size: CGSize, top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) -> CGSize {
return CGSize(
width: size.width - left - right,
height: size.height - top - bottom)
}

// MARK: - Offsetting

public func offset(view: UIView, amount: CGFloat) -> CGRect {
public func offset(_ view: UIView, amount: CGFloat) -> CGRect {
return offset(view.frame, amount: amount)
}

public func offset(layer: CALayer, amount: CGFloat) -> CGRect {
public func offset(_ layer: CALayer, amount: CGFloat) -> CGRect {
return offset(layer.frame, amount: amount)
}

public func offset(rect: CGRect, amount: CGFloat) -> CGRect {
return CGRectOffset(rect, amount, amount)
public func offset(_ rect: CGRect, amount: CGFloat) -> CGRect {
return rect.offsetBy(dx: amount, dy: amount)
}

public func offset(view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect {
public func offset(_ view: UIView, dx: CGFloat, dy: CGFloat) -> CGRect {
return offset(view.frame, dx: dx, dy: dy)
}

public func offset(layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect {
public func offset(_ layer: CALayer, dx: CGFloat, dy: CGFloat) -> CGRect {
return offset(layer.frame, dx: dx, dy: dy)
}

public func offset(rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect {
return CGRectOffset(rect, dx, dy)
public func offset(_ rect: CGRect, dx: CGFloat, dy: CGFloat) -> CGRect {
return rect.offsetBy(dx: dx, dy: dy)
}

public func offset(point: CGPoint, amount: CGFloat) -> CGPoint {
public func offset(_ point: CGPoint, amount: CGFloat) -> CGPoint {
return offset(point, dx: amount, dy: amount)
}

public func offset(point: CGPoint, dx: CGFloat, dy: CGFloat) -> CGPoint {
public func offset(_ point: CGPoint, dx: CGFloat, dy: CGFloat) -> CGPoint {
return CGPoint(x: point.x + dx, y: point.y + dy)
}
15 changes: 11 additions & 4 deletions ManualLayout/SmartAssign.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@

import UIKit

infix operator =~ { associativity right precedence 150 }
precedencegroup SmartAssignment {
assignment: true
}

infix operator =~ : SmartAssignment

public func =~ (inout point: CGPoint, pointTuple: (CGFloat, CGFloat)) -> CGPoint {
@discardableResult
public func =~ (point: inout CGPoint, pointTuple: (CGFloat, CGFloat)) -> CGPoint {
point = CGPoint(x: pointTuple.0, y: pointTuple.1)
return point
}

public func =~ (inout size: CGSize, sizeTuple: (CGFloat, CGFloat)) -> CGSize {
@discardableResult
public func =~ (size: inout CGSize, sizeTuple: (CGFloat, CGFloat)) -> CGSize {
size = CGSize(width: sizeTuple.0, height: sizeTuple.1)
return size
}

public func =~ (inout rect: CGRect, rectTuple: (CGFloat, CGFloat, CGFloat, CGFloat)) -> CGRect {
@discardableResult
public func =~ (rect: inout CGRect, rectTuple: (CGFloat, CGFloat, CGFloat, CGFloat)) -> CGRect {
rect = CGRect(x: rectTuple.0, y: rectTuple.1, width: rectTuple.2, height: rectTuple.3)
return rect
}
6 changes: 4 additions & 2 deletions ManualLayout/UIView+ManualLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,13 @@ public extension UIView {

// MARK: - Automatic Sizing

public func sizeToFit(width: CGFloat, _ height: CGFloat) -> CGSize {
@discardableResult
public func sizeToFit(_ width: CGFloat, _ height: CGFloat) -> CGSize {
return sizeToFit(CGSize(width: width, height: height))
}

public func sizeToFit(constrainedSize: CGSize) -> CGSize {
@discardableResult
public func sizeToFit(_ constrainedSize: CGSize) -> CGSize {
var newSize = sizeThatFits(constrainedSize)
newSize.width = min(newSize.width, constrainedSize.width)
newSize.height = min(newSize.height, constrainedSize.height)
Expand Down
2 changes: 1 addition & 1 deletion ManualLayoutTests/HelperFunctionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import XCTest
import ManualLayout

class HelperFunctionTests: XCTestCase {
var view = UIView(frame: CGRectZero)
var view = UIView(frame: .zero)
let defaultFrame = CGRect(x: 1, y: 3, width: 6, height: 8)

override func setUp() {
Expand Down
4 changes: 2 additions & 2 deletions ManualLayoutTests/SmartAssignTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import XCTest
import ManualLayout

class SmartAssignTests: XCTestCase {
var view = UIView(frame: CGRectZero)
var view = UIView(frame: .zero)

override func setUp() {
view.frame = CGRectZero
view.frame = .zero
}

func testPointAssignment() {
Expand Down
8 changes: 4 additions & 4 deletions ManualLayoutTests/UIViewManualLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import XCTest
import ManualLayout

class UIViewManualLayoutTests: XCTestCase {
let view = UIView(frame: CGRectZero)
let view = UIView(frame: .zero)
let defaultFrame = CGRect(x: 1, y: 3, width: 6, height: 8)

override func setUp() {
Expand Down Expand Up @@ -92,14 +92,14 @@ class UIViewManualLayoutTests: XCTestCase {
}

func testSize() {
view.size = CGSizeZero
view.size = .zero
XCTAssertEqual(
view.frame.origin,
defaultFrame.origin,
"size changes should not modify frame origin")
XCTAssertEqual(
view.frame.size,
CGSizeZero,
.zero,
"size changes should modify frame size")
}

Expand Down Expand Up @@ -229,7 +229,7 @@ class UIViewManualLayoutTests: XCTestCase {

func testSizeToFit() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 200))
let label = UILabel(frame: CGRectZero)
let label = UILabel(frame: .zero)
label.text = "lorem ipsum dolor sit amet"
label.numberOfLines = 5
containerView.addSubview(label)
Expand Down
6 changes: 3 additions & 3 deletions SimpleExample/ExampleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import UIKit
import ManualLayout

internal final class ExampleViewController: UIViewController {
let titleLabel = UILabel(frame: CGRectZero)
let subtitleLabel = UILabel(frame: CGRectZero)
let yinView = UIView(frame: CGRectZero)
let titleLabel = UILabel(frame: .zero)
let subtitleLabel = UILabel(frame: .zero)
let yinView = UIView(frame: .zero)

init() {
super.init(nibName: nil, bundle: nil)
Expand Down