From 989f3e74b4dd57f752b859712011e2f30a525de4 Mon Sep 17 00:00:00 2001 From: David Tchepak Date: Fri, 20 Feb 2015 23:05:24 +1100 Subject: [PATCH] Setting up initial Parser types and first exercise --- .gitignore | 35 ++ ParserExercise.xcodeproj/project.pbxproj | 422 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + ParserExercise/AppDelegate.swift | 46 ++ ParserExercise/Base.lproj/LaunchScreen.xib | 41 ++ ParserExercise/Base.lproj/Main.storyboard | 25 ++ .../AppIcon.appiconset/Contents.json | 68 +++ ParserExercise/Info.plist | 47 ++ ParserExercise/ViewController.swift | 25 ++ ParserExerciseTests/Info.plist | 24 + ParserExerciseTests/ParserExerciseTests.swift | 112 +++++ 11 files changed, 852 insertions(+) create mode 100644 .gitignore create mode 100644 ParserExercise.xcodeproj/project.pbxproj create mode 100644 ParserExercise.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 ParserExercise/AppDelegate.swift create mode 100644 ParserExercise/Base.lproj/LaunchScreen.xib create mode 100644 ParserExercise/Base.lproj/Main.storyboard create mode 100644 ParserExercise/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 ParserExercise/Info.plist create mode 100644 ParserExercise/ViewController.swift create mode 100644 ParserExerciseTests/Info.plist create mode 100644 ParserExerciseTests/ParserExerciseTests.swift diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9ccfce1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# https://github.com/github/gitignore/blob/master/Swift.gitignore + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control +# +# Pods/ + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build diff --git a/ParserExercise.xcodeproj/project.pbxproj b/ParserExercise.xcodeproj/project.pbxproj new file mode 100644 index 0000000..d3c73ea --- /dev/null +++ b/ParserExercise.xcodeproj/project.pbxproj @@ -0,0 +1,422 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + E4CE414A1A974CA2009CD9BF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4CE41491A974CA2009CD9BF /* AppDelegate.swift */; }; + E4CE414C1A974CA2009CD9BF /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4CE414B1A974CA2009CD9BF /* ViewController.swift */; }; + E4CE414F1A974CA2009CD9BF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E4CE414D1A974CA2009CD9BF /* Main.storyboard */; }; + E4CE41511A974CA2009CD9BF /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E4CE41501A974CA2009CD9BF /* Images.xcassets */; }; + E4CE41541A974CA2009CD9BF /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = E4CE41521A974CA2009CD9BF /* LaunchScreen.xib */; }; + E4CE41601A974CA2009CD9BF /* ParserExerciseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4CE415F1A974CA2009CD9BF /* ParserExerciseTests.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + E4CE415A1A974CA2009CD9BF /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = E4CE413C1A974CA2009CD9BF /* Project object */; + proxyType = 1; + remoteGlobalIDString = E4CE41431A974CA2009CD9BF; + remoteInfo = ParserExercise; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + E4CE41441A974CA2009CD9BF /* ParserExercise.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ParserExercise.app; sourceTree = BUILT_PRODUCTS_DIR; }; + E4CE41481A974CA2009CD9BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + E4CE41491A974CA2009CD9BF /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + E4CE414B1A974CA2009CD9BF /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + E4CE414E1A974CA2009CD9BF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + E4CE41501A974CA2009CD9BF /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + E4CE41531A974CA2009CD9BF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; + E4CE41591A974CA2009CD9BF /* ParserExerciseTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ParserExerciseTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + E4CE415E1A974CA2009CD9BF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + E4CE415F1A974CA2009CD9BF /* ParserExerciseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParserExerciseTests.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + E4CE41411A974CA2009CD9BF /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + E4CE41561A974CA2009CD9BF /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + E4CE413B1A974CA2009CD9BF = { + isa = PBXGroup; + children = ( + E4CE41461A974CA2009CD9BF /* ParserExercise */, + E4CE415C1A974CA2009CD9BF /* ParserExerciseTests */, + E4CE41451A974CA2009CD9BF /* Products */, + ); + sourceTree = ""; + }; + E4CE41451A974CA2009CD9BF /* Products */ = { + isa = PBXGroup; + children = ( + E4CE41441A974CA2009CD9BF /* ParserExercise.app */, + E4CE41591A974CA2009CD9BF /* ParserExerciseTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + E4CE41461A974CA2009CD9BF /* ParserExercise */ = { + isa = PBXGroup; + children = ( + E4CE41491A974CA2009CD9BF /* AppDelegate.swift */, + E4CE414B1A974CA2009CD9BF /* ViewController.swift */, + E4CE414D1A974CA2009CD9BF /* Main.storyboard */, + E4CE41501A974CA2009CD9BF /* Images.xcassets */, + E4CE41521A974CA2009CD9BF /* LaunchScreen.xib */, + E4CE41471A974CA2009CD9BF /* Supporting Files */, + ); + path = ParserExercise; + sourceTree = ""; + }; + E4CE41471A974CA2009CD9BF /* Supporting Files */ = { + isa = PBXGroup; + children = ( + E4CE41481A974CA2009CD9BF /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + E4CE415C1A974CA2009CD9BF /* ParserExerciseTests */ = { + isa = PBXGroup; + children = ( + E4CE415F1A974CA2009CD9BF /* ParserExerciseTests.swift */, + E4CE415D1A974CA2009CD9BF /* Supporting Files */, + ); + path = ParserExerciseTests; + sourceTree = ""; + }; + E4CE415D1A974CA2009CD9BF /* Supporting Files */ = { + isa = PBXGroup; + children = ( + E4CE415E1A974CA2009CD9BF /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + E4CE41431A974CA2009CD9BF /* ParserExercise */ = { + isa = PBXNativeTarget; + buildConfigurationList = E4CE41631A974CA2009CD9BF /* Build configuration list for PBXNativeTarget "ParserExercise" */; + buildPhases = ( + E4CE41401A974CA2009CD9BF /* Sources */, + E4CE41411A974CA2009CD9BF /* Frameworks */, + E4CE41421A974CA2009CD9BF /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ParserExercise; + productName = ParserExercise; + productReference = E4CE41441A974CA2009CD9BF /* ParserExercise.app */; + productType = "com.apple.product-type.application"; + }; + E4CE41581A974CA2009CD9BF /* ParserExerciseTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = E4CE41661A974CA2009CD9BF /* Build configuration list for PBXNativeTarget "ParserExerciseTests" */; + buildPhases = ( + E4CE41551A974CA2009CD9BF /* Sources */, + E4CE41561A974CA2009CD9BF /* Frameworks */, + E4CE41571A974CA2009CD9BF /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + E4CE415B1A974CA2009CD9BF /* PBXTargetDependency */, + ); + name = ParserExerciseTests; + productName = ParserExerciseTests; + productReference = E4CE41591A974CA2009CD9BF /* ParserExerciseTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + E4CE413C1A974CA2009CD9BF /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0610; + ORGANIZATIONNAME = "David Tchepak"; + TargetAttributes = { + E4CE41431A974CA2009CD9BF = { + CreatedOnToolsVersion = 6.1.1; + }; + E4CE41581A974CA2009CD9BF = { + CreatedOnToolsVersion = 6.1.1; + TestTargetID = E4CE41431A974CA2009CD9BF; + }; + }; + }; + buildConfigurationList = E4CE413F1A974CA2009CD9BF /* Build configuration list for PBXProject "ParserExercise" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = E4CE413B1A974CA2009CD9BF; + productRefGroup = E4CE41451A974CA2009CD9BF /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + E4CE41431A974CA2009CD9BF /* ParserExercise */, + E4CE41581A974CA2009CD9BF /* ParserExerciseTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + E4CE41421A974CA2009CD9BF /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E4CE414F1A974CA2009CD9BF /* Main.storyboard in Resources */, + E4CE41541A974CA2009CD9BF /* LaunchScreen.xib in Resources */, + E4CE41511A974CA2009CD9BF /* Images.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + E4CE41571A974CA2009CD9BF /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + E4CE41401A974CA2009CD9BF /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E4CE414C1A974CA2009CD9BF /* ViewController.swift in Sources */, + E4CE414A1A974CA2009CD9BF /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + E4CE41551A974CA2009CD9BF /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E4CE41601A974CA2009CD9BF /* ParserExerciseTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + E4CE415B1A974CA2009CD9BF /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = E4CE41431A974CA2009CD9BF /* ParserExercise */; + targetProxy = E4CE415A1A974CA2009CD9BF /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + E4CE414D1A974CA2009CD9BF /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + E4CE414E1A974CA2009CD9BF /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + E4CE41521A974CA2009CD9BF /* LaunchScreen.xib */ = { + isa = PBXVariantGroup; + children = ( + E4CE41531A974CA2009CD9BF /* Base */, + ); + name = LaunchScreen.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + E4CE41611A974CA2009CD9BF /* 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.1; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + E4CE41621A974CA2009CD9BF /* 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.1; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + E4CE41641A974CA2009CD9BF /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = ParserExercise/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + E4CE41651A974CA2009CD9BF /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + INFOPLIST_FILE = ParserExercise/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + E4CE41671A974CA2009CD9BF /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + ); + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = ParserExerciseTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ParserExercise.app/ParserExercise"; + }; + name = Debug; + }; + E4CE41681A974CA2009CD9BF /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + FRAMEWORK_SEARCH_PATHS = ( + "$(SDKROOT)/Developer/Library/Frameworks", + "$(inherited)", + ); + INFOPLIST_FILE = ParserExerciseTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ParserExercise.app/ParserExercise"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + E4CE413F1A974CA2009CD9BF /* Build configuration list for PBXProject "ParserExercise" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E4CE41611A974CA2009CD9BF /* Debug */, + E4CE41621A974CA2009CD9BF /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + E4CE41631A974CA2009CD9BF /* Build configuration list for PBXNativeTarget "ParserExercise" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E4CE41641A974CA2009CD9BF /* Debug */, + E4CE41651A974CA2009CD9BF /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; + E4CE41661A974CA2009CD9BF /* Build configuration list for PBXNativeTarget "ParserExerciseTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E4CE41671A974CA2009CD9BF /* Debug */, + E4CE41681A974CA2009CD9BF /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; +/* End XCConfigurationList section */ + }; + rootObject = E4CE413C1A974CA2009CD9BF /* Project object */; +} diff --git a/ParserExercise.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ParserExercise.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..60ccaa5 --- /dev/null +++ b/ParserExercise.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/ParserExercise/AppDelegate.swift b/ParserExercise/AppDelegate.swift new file mode 100644 index 0000000..12b8154 --- /dev/null +++ b/ParserExercise/AppDelegate.swift @@ -0,0 +1,46 @@ +// +// AppDelegate.swift +// ParserExercise +// +// Created by David Tchepak on 20/02/2015. +// Copyright (c) 2015 David Tchepak. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + + func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + // Override point for customization after application launch. + return true + } + + func applicationWillResignActive(application: UIApplication) { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(application: UIApplication) { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + } + + func applicationWillEnterForeground(application: UIApplication) { + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(application: UIApplication) { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + func applicationWillTerminate(application: UIApplication) { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } + + +} + diff --git a/ParserExercise/Base.lproj/LaunchScreen.xib b/ParserExercise/Base.lproj/LaunchScreen.xib new file mode 100644 index 0000000..7ae78e9 --- /dev/null +++ b/ParserExercise/Base.lproj/LaunchScreen.xib @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ParserExercise/Base.lproj/Main.storyboard b/ParserExercise/Base.lproj/Main.storyboard new file mode 100644 index 0000000..3a2a49b --- /dev/null +++ b/ParserExercise/Base.lproj/Main.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ParserExercise/Images.xcassets/AppIcon.appiconset/Contents.json b/ParserExercise/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..36d2c80 --- /dev/null +++ b/ParserExercise/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "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/ParserExercise/Info.plist b/ParserExercise/Info.plist new file mode 100644 index 0000000..ee9a5fe --- /dev/null +++ b/ParserExercise/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + net.davesquared.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/ParserExercise/ViewController.swift b/ParserExercise/ViewController.swift new file mode 100644 index 0000000..21767f3 --- /dev/null +++ b/ParserExercise/ViewController.swift @@ -0,0 +1,25 @@ +// +// ViewController.swift +// ParserExercise +// +// Created by David Tchepak on 20/02/2015. +// Copyright (c) 2015 David Tchepak. All rights reserved. +// + +import UIKit + +class ViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + // Do any additional setup after loading the view, typically from a nib. + } + + override func didReceiveMemoryWarning() { + super.didReceiveMemoryWarning() + // Dispose of any resources that can be recreated. + } + + +} + diff --git a/ParserExerciseTests/Info.plist b/ParserExerciseTests/Info.plist new file mode 100644 index 0000000..0633808 --- /dev/null +++ b/ParserExerciseTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + net.davesquared.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/ParserExerciseTests/ParserExerciseTests.swift b/ParserExerciseTests/ParserExerciseTests.swift new file mode 100644 index 0000000..53db330 --- /dev/null +++ b/ParserExerciseTests/ParserExerciseTests.swift @@ -0,0 +1,112 @@ +// Parser exercises, based on those written by Tony Morris et al., published under NICTA repo +// https://github.com/NICTA/course/blob/af3e945d5eadcaf0a11a462e2ef7f5378b71d7f7/src/Course/Parser.hs + +import UIKit +import XCTest + + +public typealias Input = String + +public enum ParseError : Printable, Equatable { + case UnexpectedEof + case ExpectedEof(Input) + case UnexpectedChar(Character) + case Failed(String) + public var description : String { + switch self { + case .UnexpectedChar(let c): return "Unexpected character: \(c)" + case .UnexpectedEof : return "Unexpected end of stream" + case .ExpectedEof(let c): return "Expected end of stream, but got >\(c)<" + case .Failed(let s): return s + } + } +} + +public func ==(lhs: ParseError, rhs: ParseError) -> Bool { + let p = (lhs, rhs) + switch p { + case (.UnexpectedEof, .UnexpectedEof): return true + case (.ExpectedEof(let i1), .ExpectedEof(let i2)): return i1 == i2 + case (.UnexpectedChar(let c1), .UnexpectedChar(let c2)): return c1 == c2 + case (.Failed(let s1), .Failed(let s2)): return s1 == s2 + default: return false + } +} + +public enum ParseResult : Printable { + case ErrorResult(ParseError) + case Result(Input,Box) + public var description : String { + switch self { + case .ErrorResult(let p) : return p.description + case .Result(let i, let a): return "Result >\(i)<, \(a.value)" + } + } + public func isError() -> Bool { + switch self { + case ErrorResult(_) : return true + case Result(_): return false + } + } +} + +public func ==(lhs: ParseResult, rhs: ParseResult) -> Bool { + switch (lhs, rhs) { + case (.ErrorResult(let e1), .ErrorResult(let e2)): return e1 == e2 + case (.Result(let i1, let a1), .Result(let i2, let a2)): return i1 == i2 && a1.value == a2.value + default: return false + } +} + + +public func succeed(remainingInput : Input, value : A) -> ParseResult { return .Result(remainingInput, Box(value)) } +public func failWithUnexpectedEof() -> ParseResult { return .ErrorResult(.UnexpectedEof) } +public func failWithExpectedEof(i : Input) -> ParseResult { return .ErrorResult(.ExpectedEof(i)) } +public func failWithUnexpectedChar(c : Character) -> ParseResult { return .ErrorResult(.UnexpectedChar(c)) } +public func failParse() -> ParseResult{ return .ErrorResult(.Failed("Parse failed")) } + + +// A Parser wraps a function that takes some input and returns either: +// * a value of type A, and the remaining input left to parse +// * a parse error +public struct Parser { + let p : Input -> ParseResult + init(p : Input -> ParseResult) { self.p = p } + + public func parse(i : Input) -> ParseResult { return self.p(i) } +} +public func TODO() -> Parser { return Parser({ i in .ErrorResult(.Failed("*** TODO ***"))}) } + +// Produces a parser that always fails with UnexpectedChar given the specified character +public func unexpectedCharParser(c : Character) -> Parser { + return Parser({ i in failWithUnexpectedChar(c) }) +} + +// Return a parser that always succeeds with the given value and consumes no input +public func valueParser(a : A) -> Parser { + return TODO() +} + +class ValueParserTests : XCTestCase { + func testValueParser() { + let result = valueParser(2).parse("hello") + XCTAssert(result == succeed("hello", 2), result.description) + } +} + + + + + +// From: https://github.com/typelift/Swiftx/blob/e0997a4b43fab5fb0f3d76506f7c2124b718920e/Swiftx/Box.swift +/// An immutable reference type holding a singular value. +/// +/// Boxes are often used when the Swift compiler cannot infer the size of a struct or enum because +/// one of its generic types is being used as a member. +public final class Box { + private let val : @autoclosure () -> T + public var value: T { return val() } + public init(_ value : T) { + self.val = value + } +} \ No newline at end of file