From afb20a778f3ae8e3904ffe7cab1fe9eaa62f6f46 Mon Sep 17 00:00:00 2001 From: Jonas Budelmann Date: Fri, 6 Jun 2014 15:42:44 +1200 Subject: [PATCH] initial operator overload experiment --- ExpressiveLayout.xcodeproj/project.pbxproj | 423 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + ExpressiveLayout/AppDelegate.swift | 28 ++ ExpressiveLayout/CompositeConstraint.swift | 10 + ExpressiveLayout/Constraint.swift | 14 + .../AppIcon.appiconset/Contents.json | 53 +++ .../LaunchImage.launchimage/Contents.json | 51 +++ ExpressiveLayout/Info.plist | 30 ++ ExpressiveLayout/Operators.swift | 52 +++ ExpressiveLayout/RootViewController.swift | 74 +++ ExpressiveLayout/SingleConstraint.swift | 44 ++ .../ExpressiveLayoutTests.swift | 35 ++ ExpressiveLayoutTests/Info.plist | 24 + 13 files changed, 845 insertions(+) create mode 100644 ExpressiveLayout.xcodeproj/project.pbxproj create mode 100644 ExpressiveLayout.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 ExpressiveLayout/AppDelegate.swift create mode 100644 ExpressiveLayout/CompositeConstraint.swift create mode 100644 ExpressiveLayout/Constraint.swift create mode 100644 ExpressiveLayout/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 ExpressiveLayout/Images.xcassets/LaunchImage.launchimage/Contents.json create mode 100644 ExpressiveLayout/Info.plist create mode 100644 ExpressiveLayout/Operators.swift create mode 100644 ExpressiveLayout/RootViewController.swift create mode 100644 ExpressiveLayout/SingleConstraint.swift create mode 100644 ExpressiveLayoutTests/ExpressiveLayoutTests.swift create mode 100644 ExpressiveLayoutTests/Info.plist diff --git a/ExpressiveLayout.xcodeproj/project.pbxproj b/ExpressiveLayout.xcodeproj/project.pbxproj new file mode 100644 index 0000000..9a5214e --- /dev/null +++ b/ExpressiveLayout.xcodeproj/project.pbxproj @@ -0,0 +1,423 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + DDCE87541940224E0015932A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCE87531940224E0015932A /* AppDelegate.swift */; }; + DDCE87561940224E0015932A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DDCE87551940224E0015932A /* Images.xcassets */; }; + DDCE87621940224E0015932A /* ExpressiveLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCE87611940224E0015932A /* ExpressiveLayoutTests.swift */; }; + DDCE876C194022820015932A /* RootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCE876B194022820015932A /* RootViewController.swift */; }; + DDCE876F194025400015932A /* SingleConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCE876E194025400015932A /* SingleConstraint.swift */; }; + DDCE8771194025C40015932A /* CompositeConstraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCE8770194025C40015932A /* CompositeConstraint.swift */; }; + DDCE8773194026370015932A /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCE8772194026370015932A /* Operators.swift */; }; + DDCE87751940290A0015932A /* Constraint.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCE87741940290A0015932A /* Constraint.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + DDCE875C1940224E0015932A /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = DDCE87461940224E0015932A /* Project object */; + proxyType = 1; + remoteGlobalIDString = DDCE874D1940224E0015932A; + remoteInfo = ExpressiveLayout; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + DDCE874E1940224E0015932A /* ExpressiveLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ExpressiveLayout.app; sourceTree = BUILT_PRODUCTS_DIR; }; + DDCE87521940224E0015932A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + DDCE87531940224E0015932A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + DDCE87551940224E0015932A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + DDCE875B1940224E0015932A /* ExpressiveLayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ExpressiveLayoutTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + DDCE87601940224E0015932A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + DDCE87611940224E0015932A /* ExpressiveLayoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExpressiveLayoutTests.swift; sourceTree = ""; }; + DDCE876B194022820015932A /* RootViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RootViewController.swift; sourceTree = ""; }; + DDCE876E194025400015932A /* SingleConstraint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleConstraint.swift; sourceTree = ""; }; + DDCE8770194025C40015932A /* CompositeConstraint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompositeConstraint.swift; sourceTree = ""; }; + DDCE8772194026370015932A /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = ""; }; + DDCE87741940290A0015932A /* Constraint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constraint.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + DDCE874B1940224E0015932A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + DDCE87581940224E0015932A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + DDCE87451940224E0015932A = { + isa = PBXGroup; + children = ( + DDCE876D1940228D0015932A /* ExpressiveLayout */, + DDCE87501940224E0015932A /* Examples */, + DDCE875E1940224E0015932A /* ExpressiveLayoutTests */, + DDCE874F1940224E0015932A /* Products */, + ); + sourceTree = ""; + }; + DDCE874F1940224E0015932A /* Products */ = { + isa = PBXGroup; + children = ( + DDCE874E1940224E0015932A /* ExpressiveLayout.app */, + DDCE875B1940224E0015932A /* ExpressiveLayoutTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + DDCE87501940224E0015932A /* Examples */ = { + isa = PBXGroup; + children = ( + DDCE87531940224E0015932A /* AppDelegate.swift */, + DDCE876B194022820015932A /* RootViewController.swift */, + DDCE87551940224E0015932A /* Images.xcassets */, + DDCE87511940224E0015932A /* Supporting Files */, + ); + name = Examples; + path = ExpressiveLayout; + sourceTree = ""; + }; + DDCE87511940224E0015932A /* Supporting Files */ = { + isa = PBXGroup; + children = ( + DDCE87521940224E0015932A /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + DDCE875E1940224E0015932A /* ExpressiveLayoutTests */ = { + isa = PBXGroup; + children = ( + DDCE87611940224E0015932A /* ExpressiveLayoutTests.swift */, + DDCE875F1940224E0015932A /* Supporting Files */, + ); + path = ExpressiveLayoutTests; + sourceTree = ""; + }; + DDCE875F1940224E0015932A /* Supporting Files */ = { + isa = PBXGroup; + children = ( + DDCE87601940224E0015932A /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + DDCE876D1940228D0015932A /* ExpressiveLayout */ = { + isa = PBXGroup; + children = ( + DDCE87741940290A0015932A /* Constraint.swift */, + DDCE876E194025400015932A /* SingleConstraint.swift */, + DDCE8770194025C40015932A /* CompositeConstraint.swift */, + DDCE8772194026370015932A /* Operators.swift */, + ); + path = ExpressiveLayout; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + DDCE874D1940224E0015932A /* ExpressiveLayout */ = { + isa = PBXNativeTarget; + buildConfigurationList = DDCE87651940224E0015932A /* Build configuration list for PBXNativeTarget "ExpressiveLayout" */; + buildPhases = ( + DDCE874A1940224E0015932A /* Sources */, + DDCE874B1940224E0015932A /* Frameworks */, + DDCE874C1940224E0015932A /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ExpressiveLayout; + productName = ExpressiveLayout; + productReference = DDCE874E1940224E0015932A /* ExpressiveLayout.app */; + productType = "com.apple.product-type.application"; + }; + DDCE875A1940224E0015932A /* ExpressiveLayoutTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = DDCE87681940224E0015932A /* Build configuration list for PBXNativeTarget "ExpressiveLayoutTests" */; + buildPhases = ( + DDCE87571940224E0015932A /* Sources */, + DDCE87581940224E0015932A /* Frameworks */, + DDCE87591940224E0015932A /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + DDCE875D1940224E0015932A /* PBXTargetDependency */, + ); + name = ExpressiveLayoutTests; + productName = ExpressiveLayoutTests; + productReference = DDCE875B1940224E0015932A /* ExpressiveLayoutTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + DDCE87461940224E0015932A /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0600; + ORGANIZATIONNAME = "Jonas Budelmann"; + TargetAttributes = { + DDCE874D1940224E0015932A = { + CreatedOnToolsVersion = 6.0; + }; + DDCE875A1940224E0015932A = { + CreatedOnToolsVersion = 6.0; + TestTargetID = DDCE874D1940224E0015932A; + }; + }; + }; + buildConfigurationList = DDCE87491940224E0015932A /* Build configuration list for PBXProject "ExpressiveLayout" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = DDCE87451940224E0015932A; + productRefGroup = DDCE874F1940224E0015932A /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + DDCE874D1940224E0015932A /* ExpressiveLayout */, + DDCE875A1940224E0015932A /* ExpressiveLayoutTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + DDCE874C1940224E0015932A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DDCE87561940224E0015932A /* Images.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + DDCE87591940224E0015932A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + DDCE874A1940224E0015932A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DDCE87751940290A0015932A /* Constraint.swift in Sources */, + DDCE8771194025C40015932A /* CompositeConstraint.swift in Sources */, + DDCE8773194026370015932A /* Operators.swift in Sources */, + DDCE876F194025400015932A /* SingleConstraint.swift in Sources */, + DDCE876C194022820015932A /* RootViewController.swift in Sources */, + DDCE87541940224E0015932A /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + DDCE87571940224E0015932A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DDCE87621940224E0015932A /* ExpressiveLayoutTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + DDCE875D1940224E0015932A /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = DDCE874D1940224E0015932A /* ExpressiveLayout */; + targetProxy = DDCE875C1940224E0015932A /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + DDCE87631940224E0015932A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + METAL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + DDCE87641940224E0015932A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + METAL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + DDCE87661940224E0015932A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + INFOPLIST_FILE = ExpressiveLayout/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + DDCE87671940224E0015932A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + INFOPLIST_FILE = ExpressiveLayout/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + DDCE87691940224E0015932A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/ExpressiveLayout.app/ExpressiveLayout"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + ); + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = ExpressiveLayoutTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + METAL_ENABLE_DEBUG_INFO = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUNDLE_LOADER)"; + }; + name = Debug; + }; + DDCE876A1940224E0015932A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/ExpressiveLayout.app/ExpressiveLayout"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + ); + INFOPLIST_FILE = ExpressiveLayoutTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + METAL_ENABLE_DEBUG_INFO = NO; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUNDLE_LOADER)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + DDCE87491940224E0015932A /* Build configuration list for PBXProject "ExpressiveLayout" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DDCE87631940224E0015932A /* Debug */, + DDCE87641940224E0015932A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + DDCE87651940224E0015932A /* Build configuration list for PBXNativeTarget "ExpressiveLayout" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DDCE87661940224E0015932A /* Debug */, + DDCE87671940224E0015932A /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; + DDCE87681940224E0015932A /* Build configuration list for PBXNativeTarget "ExpressiveLayoutTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DDCE87691940224E0015932A /* Debug */, + DDCE876A1940224E0015932A /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = DDCE87461940224E0015932A /* Project object */; +} diff --git a/ExpressiveLayout.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ExpressiveLayout.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..ee788a9 --- /dev/null +++ b/ExpressiveLayout.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/ExpressiveLayout/AppDelegate.swift b/ExpressiveLayout/AppDelegate.swift new file mode 100644 index 0000000..3a8c54b --- /dev/null +++ b/ExpressiveLayout/AppDelegate.swift @@ -0,0 +1,28 @@ +// +// AppDelegate.swift +// ExpressiveLayout +// +// Created by Jonas Budelmann on 5/06/14. +// Copyright (c) 2014 Jonas Budelmann. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { + self.window = UIWindow(frame: UIScreen.mainScreen().bounds) + // Override point for customization after application launch. + + let navigationController = UINavigationController(rootViewController: RootViewController()) + self.window!.rootViewController = navigationController + + self.window!.backgroundColor = UIColor.whiteColor() + self.window!.makeKeyAndVisible() + return true + } +} + diff --git a/ExpressiveLayout/CompositeConstraint.swift b/ExpressiveLayout/CompositeConstraint.swift new file mode 100644 index 0000000..48688b4 --- /dev/null +++ b/ExpressiveLayout/CompositeConstraint.swift @@ -0,0 +1,10 @@ +// +// CompositeConstraint.swift +// ExpressiveLayout +// +// Created by Jonas Budelmann on 5/06/14. +// Copyright (c) 2014 Jonas Budelmann. All rights reserved. +// + +import Foundation + diff --git a/ExpressiveLayout/Constraint.swift b/ExpressiveLayout/Constraint.swift new file mode 100644 index 0000000..899415c --- /dev/null +++ b/ExpressiveLayout/Constraint.swift @@ -0,0 +1,14 @@ +// +// Constraint.swift +// ExpressiveLayout +// +// Created by Jonas Budelmann on 5/06/14. +// Copyright (c) 2014 Jonas Budelmann. All rights reserved. +// + +import Foundation + +protocol Constraint { + func add(other: Any) -> Constraint + func equalTo(other: Any) -> Constraint +} \ No newline at end of file diff --git a/ExpressiveLayout/Images.xcassets/AppIcon.appiconset/Contents.json b/ExpressiveLayout/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..91bf9c1 --- /dev/null +++ b/ExpressiveLayout/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,53 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ExpressiveLayout/Images.xcassets/LaunchImage.launchimage/Contents.json b/ExpressiveLayout/Images.xcassets/LaunchImage.launchimage/Contents.json new file mode 100644 index 0000000..6f870a4 --- /dev/null +++ b/ExpressiveLayout/Images.xcassets/LaunchImage.launchimage/Contents.json @@ -0,0 +1,51 @@ +{ + "images" : [ + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "iphone", + "subtype" : "retina4", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "1x" + }, + { + "orientation" : "landscape", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "1x" + }, + { + "orientation" : "portrait", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + }, + { + "orientation" : "landscape", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ExpressiveLayout/Info.plist b/ExpressiveLayout/Info.plist new file mode 100644 index 0000000..15748c3 --- /dev/null +++ b/ExpressiveLayout/Info.plist @@ -0,0 +1,30 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + com.cloudling.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIRequiredDeviceCapabilities + + armv7 + + + diff --git a/ExpressiveLayout/Operators.swift b/ExpressiveLayout/Operators.swift new file mode 100644 index 0000000..af68f3f --- /dev/null +++ b/ExpressiveLayout/Operators.swift @@ -0,0 +1,52 @@ +// +// Operators.swift +// ExpressiveLayout +// +// Created by Jonas Budelmann on 5/06/14. +// Copyright (c) 2014 Jonas Budelmann. All rights reserved. +// + +import UIKit + +//TODO spilt into different files + +enum ViewLayoutAttribute { + case CenterX + case CenterY + case Left + case Right + case Top + case Bottom + case Width + case Height +} + +class ViewAttribute { + weak var view: UIView? + let attribute: ViewLayoutAttribute + + init(view: UIView, attribute: ViewLayoutAttribute) { + self.view = view + self.attribute = attribute + } +} + +@infix func + (left: Constraint, right: Any) -> Constraint { + return left.add(right); +} + +@infix func == (left: Constraint, right: Any) -> Constraint { + return left.equalTo(right); +} + +func installConstraints(constraints: Array) { + // find common superview + // create NSLayoutConstraint +} + +extension UIView { + var left: Constraint { return SingleConstraint(view: self, attribute: .Left) } + var right: Constraint { return SingleConstraint(view: self, attribute: .Right) } + var top: Constraint { return SingleConstraint(view: self, attribute: .Top) } + var bottom: Constraint { return SingleConstraint(view: self, attribute: .Bottom) } +} diff --git a/ExpressiveLayout/RootViewController.swift b/ExpressiveLayout/RootViewController.swift new file mode 100644 index 0000000..bc85992 --- /dev/null +++ b/ExpressiveLayout/RootViewController.swift @@ -0,0 +1,74 @@ +// +// RootViewController.swift +// ExpressiveLayout +// +// Created by Jonas Budelmann on 5/06/14. +// Copyright (c) 2014 Jonas Budelmann. All rights reserved. +// + +import UIKit + +class RootViewController : UIViewController { + + override func viewDidLoad() { + self.view.backgroundColor = UIColor.whiteColor() + + let superview = self.view + + let view1 = UIView() + view1.backgroundColor = UIColor.greenColor() + view1.layer.borderColor = UIColor.blackColor().CGColor + view1.layer.borderWidth = 2 + superview.addSubview(view1) + + let view2 = UIView() + view2.backgroundColor = UIColor.redColor() + view2.layer.borderColor = UIColor.blackColor().CGColor + view2.layer.borderWidth = 2 + superview.addSubview(view2) + + let view3 = UIView() + view3.backgroundColor = UIColor.blueColor() + view3.layer.borderColor = UIColor.blackColor().CGColor + view3.layer.borderWidth = 2 + superview.addSubview(view3) + + var padding = 10; + + installConstraints([ + view1.left == superview.left + padding + ]) + +// //if you want to use Masonry without the mas_ prefix +// //define MAS_SHORTHAND before importing Masonry.h see Masonry iOS Examples-Prefix.pch +// [view1 makeConstraints:^(MASConstraintMaker *make) { +// make.top.greaterThanOrEqualTo(superview.top).offset(padding); +// make.left.equalTo(superview.left).offset(padding); +// make.bottom.equalTo(view3.top).offset(-padding); +// make.right.equalTo(view2.left).offset(-padding); +// make.width.equalTo(view2.width); +// +// make.height.equalTo(view2.height); +// make.height.equalTo(view3.height); +// }]; +// +// //with is semantic and option +// [view2 mas_makeConstraints:^(MASConstraintMaker *make) { +// make.top.equalTo(superview.mas_top).with.offset(padding); //with with +// make.left.equalTo(view1.mas_right).offset(padding); //without with +// make.bottom.equalTo(view3.mas_top).offset(-padding); +// make.right.equalTo(superview.mas_right).offset(-padding); +// make.width.equalTo(view1.mas_width); +// +// make.height.equalTo(@[view1, view3]); //can pass array of views +// }]; +// +// [view3 mas_makeConstraints:^(MASConstraintMaker *make) { +// make.top.equalTo(view1.mas_bottom).offset(padding); +// make.left.equalTo(superview.mas_left).offset(padding); +// make.bottom.equalTo(superview.mas_bottom).offset(-padding); +// make.right.equalTo(superview.mas_right).offset(-padding); +// make.height.equalTo(@[view1.mas_height, view2.mas_height]); //can pass array of attributes +// }]; + } +} diff --git a/ExpressiveLayout/SingleConstraint.swift b/ExpressiveLayout/SingleConstraint.swift new file mode 100644 index 0000000..f7bc23d --- /dev/null +++ b/ExpressiveLayout/SingleConstraint.swift @@ -0,0 +1,44 @@ +// +// ViewConstraint.swift +// ExpressiveLayout +// +// Created by Jonas Budelmann on 5/06/14. +// Copyright (c) 2014 Jonas Budelmann. All rights reserved. +// + +import UIKit + +class SingleConstraint : Constraint { + + var firstViewAttribute: ViewAttribute + var secondViewAttribute: ViewAttribute? + var layoutConstant: Double = 0 + + init(view: UIView, attribute: ViewLayoutAttribute) { + firstViewAttribute = ViewAttribute(view: view, attribute: attribute) + } + + func add(other: Any) -> Constraint { + switch other { + case let offset as Double: + layoutConstant += offset; + case let constraint as SingleConstraint: + println("TODO add to \(constraint)") + default: + println("unsupported value: \(other)") + } + return self; + } + + func equalTo(other: Any) -> Constraint { + switch other { + case let offset as Double: + layoutConstant = offset; + case let constraint as SingleConstraint: + self.secondViewAttribute = constraint.firstViewAttribute; + default: + println("unsupported value: \(other)") + } + return self; + } +} diff --git a/ExpressiveLayoutTests/ExpressiveLayoutTests.swift b/ExpressiveLayoutTests/ExpressiveLayoutTests.swift new file mode 100644 index 0000000..85b67fa --- /dev/null +++ b/ExpressiveLayoutTests/ExpressiveLayoutTests.swift @@ -0,0 +1,35 @@ +// +// ExpressiveLayoutTests.swift +// ExpressiveLayoutTests +// +// Created by Jonas Budelmann on 5/06/14. +// Copyright (c) 2014 Jonas Budelmann. All rights reserved. +// + +import XCTest + +class ExpressiveLayoutTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + // This is an example of a functional test case. + XCTAssert(true, "Pass") + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measureBlock() { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/ExpressiveLayoutTests/Info.plist b/ExpressiveLayoutTests/Info.plist new file mode 100644 index 0000000..e35c34a --- /dev/null +++ b/ExpressiveLayoutTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + com.cloudling.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + +