Updated for Swift 2.0

This commit is contained in:
Robert Payne 2015-06-17 23:09:54 +12:00
parent 6f0584f855
commit dce953eba6
10 changed files with 40 additions and 48 deletions

View File

@ -279,7 +279,8 @@
DDC9FD8D1981B4DD009612C7 /* Project object */ = { DDC9FD8D1981B4DD009612C7 /* Project object */ = {
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
LastUpgradeCheck = 0600; LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = "SnapKit Team"; ORGANIZATIONNAME = "SnapKit Team";
TargetAttributes = { TargetAttributes = {
EEBCC9D719CC627D0083B827 = { EEBCC9D719CC627D0083B827 = {
@ -433,6 +434,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99; GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO; GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0; GCC_OPTIMIZATION_LEVEL = 0;
@ -506,6 +508,7 @@
INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 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";
PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = SnapKit; PRODUCT_NAME = SnapKit;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
@ -526,6 +529,7 @@
INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 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";
PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = SnapKit; PRODUCT_NAME = SnapKit;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
@ -537,12 +541,10 @@
EEBCC9EC19CC627E0083B827 /* Debug */ = { EEBCC9EC19CC627E0083B827 /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = "$(inherited)";
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist";
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 = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
}; };
name = Debug; name = Debug;
@ -550,12 +552,10 @@
EEBCC9ED19CC627E0083B827 /* Release */ = { EEBCC9ED19CC627E0083B827 /* Release */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = "$(inherited)";
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist";
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 = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
}; };
name = Release; name = Release;
@ -578,6 +578,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 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";
MACOSX_DEPLOYMENT_TARGET = 10.10; MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = SnapKit; PRODUCT_NAME = SnapKit;
SDKROOT = macosx; SDKROOT = macosx;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
@ -602,6 +603,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 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";
MACOSX_DEPLOYMENT_TARGET = 10.10; MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = SnapKit; PRODUCT_NAME = SnapKit;
SDKROOT = macosx; SDKROOT = macosx;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
@ -615,13 +617,11 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = "$(inherited)";
"$(DEVELOPER_FRAMEWORKS_DIR)",
"$(inherited)",
);
INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10; MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx; SDKROOT = macosx;
}; };
@ -633,13 +633,11 @@
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
FRAMEWORK_SEARCH_PATHS = ( FRAMEWORK_SEARCH_PATHS = "$(inherited)";
"$(DEVELOPER_FRAMEWORKS_DIR)",
"$(inherited)",
);
INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist"; INFOPLIST_FILE = "$(SRCROOT)/Tests/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10; MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = "io.snapkit.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx; SDKROOT = macosx;
}; };

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0620" LastUpgradeVersion = "0700"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
@ -62,6 +62,8 @@
ReferencedContainer = "container:SnapKit.xcodeproj"> ReferencedContainer = "container:SnapKit.xcodeproj">
</BuildableReference> </BuildableReference>
</MacroExpansion> </MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
@ -71,6 +73,7 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES" debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"> allowLocationSimulation = "YES">
<MacroExpansion> <MacroExpansion>
<BuildableReference <BuildableReference

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "0620" LastUpgradeVersion = "0700"
version = "1.3"> version = "1.3">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
@ -62,6 +62,8 @@
ReferencedContainer = "container:SnapKit.xcodeproj"> ReferencedContainer = "container:SnapKit.xcodeproj">
</BuildableReference> </BuildableReference>
</MacroExpansion> </MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
@ -71,6 +73,7 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES" debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"> allowLocationSimulation = "YES">
<MacroExpansion> <MacroExpansion>
<BuildableReference <BuildableReference

View File

@ -127,7 +127,7 @@ internal class ConcreteConstraint: Constraint {
} }
internal override func install() -> [LayoutConstraint] { internal override func install() -> [LayoutConstraint] {
return self.installOnView(updateExisting: false) return self.installOnViewUpdatingExisting(false)
} }
internal override func uninstall() -> Void { internal override func uninstall() -> Void {
@ -191,10 +191,10 @@ internal class ConcreteConstraint: Constraint {
self.priority = priority self.priority = priority
} }
internal func installOnView(updateExisting: Bool = false) -> [LayoutConstraint] { internal func installOnViewUpdatingExisting(updateExisting: Bool = false) -> [LayoutConstraint] {
var installOnView: View? = nil var installOnView: View? = nil
if self.toItem.view != nil { if self.toItem.view != nil {
installOnView = closestCommonSuperviewBetween(self.fromItem.view, self.toItem.view) installOnView = closestCommonSuperviewFromView(self.fromItem.view, toView: self.toItem.view)
if installOnView == nil { if installOnView == nil {
NSException(name: "Cannot Install Constraint", reason: "No common superview between views", userInfo: nil).raise() NSException(name: "Cannot Install Constraint", reason: "No common superview between views", userInfo: nil).raise()
return [] return []
@ -236,7 +236,7 @@ internal class ConcreteConstraint: Constraint {
let layoutToAttribute = (layoutToAttributes.count > 0) ? layoutToAttributes[0] : layoutFromAttribute let layoutToAttribute = (layoutToAttributes.count > 0) ? layoutToAttributes[0] : layoutFromAttribute
// get layout constant // get layout constant
var layoutConstant: CGFloat = layoutToAttribute.snp_constantForValue(self.constant) let layoutConstant: CGFloat = layoutToAttribute.snp_constantForValue(self.constant)
// get layout to // get layout to
var layoutTo: View? = self.toItem.view var layoutTo: View? = self.toItem.view
@ -266,7 +266,7 @@ internal class ConcreteConstraint: Constraint {
// special logic for updating // special logic for updating
if updateExisting { if updateExisting {
// get existing constraints for this view // get existing constraints for this view
let existingLayoutConstraints = reverse(layoutFrom!.snp_installedLayoutConstraints) let existingLayoutConstraints = layoutFrom!.snp_installedLayoutConstraints.reverse()
// array that will contain only new layout constraints to keep // array that will contain only new layout constraints to keep
var newLayoutConstraintsToKeep = [LayoutConstraint]() var newLayoutConstraintsToKeep = [LayoutConstraint]()
@ -330,7 +330,7 @@ internal class ConcreteConstraint: Constraint {
// remove the constraints from the from item view // remove the constraints from the from item view
if let fromView = self.fromItem.view { if let fromView = self.fromItem.view {
fromView.snp_installedLayoutConstraints = fromView.snp_installedLayoutConstraints.filter { fromView.snp_installedLayoutConstraints = fromView.snp_installedLayoutConstraints.filter {
return !contains(installedLayoutConstraints, $0) return !installedLayoutConstraints.contains($0)
} }
} }
} }
@ -432,11 +432,11 @@ private extension NSLayoutAttribute {
} }
} }
private func closestCommonSuperviewBetween(fromView: View?, toView: View?) -> View? { private func closestCommonSuperviewFromView(fromView: View?, toView: View?) -> View? {
var views = Set<View>() var views = Set<View>()
var fromView = fromView var fromView = fromView
var toView = toView var toView = toView
do { repeat {
if let view = toView { if let view = toView {
if views.contains(view) { if views.contains(view) {
return view return view

View File

@ -137,48 +137,36 @@ public class ConstraintMaker {
} }
internal class func makeConstraints(view: View, @noescape closure: (make: ConstraintMaker) -> Void) { internal class func makeConstraints(view: View, @noescape closure: (make: ConstraintMaker) -> Void) {
#if os(iOS)
view.setTranslatesAutoresizingMaskIntoConstraints(false)
#else
view.translatesAutoresizingMaskIntoConstraints = false view.translatesAutoresizingMaskIntoConstraints = false
#endif
let maker = ConstraintMaker(view: view) let maker = ConstraintMaker(view: view)
closure(make: maker) closure(make: maker)
let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint } let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint }
for constraint in constraints { for constraint in constraints {
constraint.installOnView(updateExisting: false) constraint.installOnViewUpdatingExisting(false)
} }
} }
internal class func remakeConstraints(view: View, @noescape closure: (make: ConstraintMaker) -> Void) { internal class func remakeConstraints(view: View, @noescape closure: (make: ConstraintMaker) -> Void) {
#if os(iOS)
view.setTranslatesAutoresizingMaskIntoConstraints(false)
#else
view.translatesAutoresizingMaskIntoConstraints = false view.translatesAutoresizingMaskIntoConstraints = false
#endif
let maker = ConstraintMaker(view: view) let maker = ConstraintMaker(view: view)
closure(make: maker) closure(make: maker)
self.removeConstraints(view) self.removeConstraints(view)
let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint } let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint }
for constraint in constraints { for constraint in constraints {
constraint.installOnView(updateExisting: false) constraint.installOnViewUpdatingExisting(false)
} }
} }
internal class func updateConstraints(view: View, @noescape closure: (make: ConstraintMaker) -> Void) { internal class func updateConstraints(view: View, @noescape closure: (make: ConstraintMaker) -> Void) {
#if os(iOS)
view.setTranslatesAutoresizingMaskIntoConstraints(false)
#else
view.translatesAutoresizingMaskIntoConstraints = false view.translatesAutoresizingMaskIntoConstraints = false
#endif
let maker = ConstraintMaker(view: view) let maker = ConstraintMaker(view: view)
closure(make: maker) closure(make: maker)
let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint} let constraints = maker.constraintDescriptions.map { $0.constraint as! ConcreteConstraint}
for constraint in constraints { for constraint in constraints {
constraint.installOnView(updateExisting: true) constraint.installOnViewUpdatingExisting(true)
} }
} }

View File

@ -37,7 +37,7 @@ public extension View {
return objc_getAssociatedObject(self, &labelKey) as? String return objc_getAssociatedObject(self, &labelKey) as? String
} }
set { set {
objc_setAssociatedObject(self, &labelKey, newValue, objc_AssociationPolicy(OBJC_ASSOCIATION_COPY_NONATOMIC)) objc_setAssociatedObject(self, &labelKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_COPY_NONATOMIC)
} }
} }
@ -53,7 +53,7 @@ public extension LayoutConstraint {
return objc_getAssociatedObject(self, &labelKey) as? String return objc_getAssociatedObject(self, &labelKey) as? String
} }
set { set {
objc_setAssociatedObject(self, &labelKey, newValue, objc_AssociationPolicy(OBJC_ASSOCIATION_COPY_NONATOMIC)) objc_setAssociatedObject(self, &labelKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_COPY_NONATOMIC)
} }
} }

View File

@ -7,7 +7,7 @@
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string> <string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>io.snapkit.$(PRODUCT_NAME:rfc1034identifier)</string> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key> <key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string> <string>6.0</string>
<key>CFBundleName</key> <key>CFBundleName</key>

View File

@ -172,7 +172,7 @@ public extension View {
return [] return []
} }
set { set {
objc_setAssociatedObject(self, &installedLayoutConstraintsKey, newValue, UInt(OBJC_ASSOCIATION_RETAIN_NONATOMIC)) objc_setAssociatedObject(self, &installedLayoutConstraintsKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
} }
} }
} }

View File

@ -7,7 +7,7 @@
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string> <string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key> <key>CFBundleIdentifier</key>
<string>io.snapkit.$(PRODUCT_NAME:rfc1034identifier)</string> <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key> <key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string> <string>6.0</string>
<key>CFBundleName</key> <key>CFBundleName</key>

View File

@ -2,7 +2,7 @@
import UIKit import UIKit
typealias View = UIView typealias View = UIView
extension View { extension View {
var snp_constraints: [AnyObject] { return self.constraints() } var snp_constraints: [AnyObject] { return self.constraints }
} }
#else #else
import AppKit import AppKit