From 28d75fc0262c53d2a36bfc803c89a78b010916d2 Mon Sep 17 00:00:00 2001 From: Julian Moorhouse Date: Mon, 5 Aug 2019 11:18:17 +0100 Subject: [PATCH] Project 7 GCD fix in Project 9. --- .../project.pbxproj | 353 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../P07 WhiteHousePetitions/AppDelegate.swift | 53 +++ .../AppIcon.appiconset/Contents.json | 98 +++++ .../Assets.xcassets/Contents.json | 6 + .../Base.lproj/LaunchScreen.storyboard | 25 ++ .../Base.lproj/Main.storyboard | 94 +++++ .../DetailViewController.swift | 40 ++ .../P07 WhiteHousePetitions/Info.plist | 45 +++ .../P07 WhiteHousePetitions/Petition.swift | 15 + .../P07 WhiteHousePetitions/Petitions.swift | 13 + .../ViewController.swift | 130 +++++++ README.md | 5 + 14 files changed, 892 insertions(+) create mode 100644 P09 WhiteHousePetitions/P07 WhiteHousePetitions.xcodeproj/project.pbxproj create mode 100644 P09 WhiteHousePetitions/P07 WhiteHousePetitions.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 P09 WhiteHousePetitions/P07 WhiteHousePetitions.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 P09 WhiteHousePetitions/P07 WhiteHousePetitions/AppDelegate.swift create mode 100644 P09 WhiteHousePetitions/P07 WhiteHousePetitions/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 P09 WhiteHousePetitions/P07 WhiteHousePetitions/Assets.xcassets/Contents.json create mode 100644 P09 WhiteHousePetitions/P07 WhiteHousePetitions/Base.lproj/LaunchScreen.storyboard create mode 100644 P09 WhiteHousePetitions/P07 WhiteHousePetitions/Base.lproj/Main.storyboard create mode 100644 P09 WhiteHousePetitions/P07 WhiteHousePetitions/DetailViewController.swift create mode 100644 P09 WhiteHousePetitions/P07 WhiteHousePetitions/Info.plist create mode 100644 P09 WhiteHousePetitions/P07 WhiteHousePetitions/Petition.swift create mode 100644 P09 WhiteHousePetitions/P07 WhiteHousePetitions/Petitions.swift create mode 100644 P09 WhiteHousePetitions/P07 WhiteHousePetitions/ViewController.swift diff --git a/P09 WhiteHousePetitions/P07 WhiteHousePetitions.xcodeproj/project.pbxproj b/P09 WhiteHousePetitions/P07 WhiteHousePetitions.xcodeproj/project.pbxproj new file mode 100644 index 0000000..1932071 --- /dev/null +++ b/P09 WhiteHousePetitions/P07 WhiteHousePetitions.xcodeproj/project.pbxproj @@ -0,0 +1,353 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 883C5AEB22F6DD850040F91B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 883C5AEA22F6DD850040F91B /* AppDelegate.swift */; }; + 883C5AED22F6DD850040F91B /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 883C5AEC22F6DD850040F91B /* ViewController.swift */; }; + 883C5AF022F6DD850040F91B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 883C5AEE22F6DD850040F91B /* Main.storyboard */; }; + 883C5AF222F6DD860040F91B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 883C5AF122F6DD860040F91B /* Assets.xcassets */; }; + 883C5AF522F6DD860040F91B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 883C5AF322F6DD860040F91B /* LaunchScreen.storyboard */; }; + 883C5AFD22F6E52F0040F91B /* Petition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 883C5AFC22F6E52F0040F91B /* Petition.swift */; }; + 883C5AFF22F6E5910040F91B /* Petitions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 883C5AFE22F6E5910040F91B /* Petitions.swift */; }; + 883C5B0122F6E9040040F91B /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 883C5B0022F6E9040040F91B /* DetailViewController.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 883C5AE722F6DD850040F91B /* P07 WhiteHousePetitions.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "P07 WhiteHousePetitions.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 883C5AEA22F6DD850040F91B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 883C5AEC22F6DD850040F91B /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 883C5AEF22F6DD850040F91B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 883C5AF122F6DD860040F91B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 883C5AF422F6DD860040F91B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 883C5AF622F6DD860040F91B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 883C5AFC22F6E52F0040F91B /* Petition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Petition.swift; sourceTree = ""; }; + 883C5AFE22F6E5910040F91B /* Petitions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Petitions.swift; sourceTree = ""; }; + 883C5B0022F6E9040040F91B /* DetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewController.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 883C5AE422F6DD850040F91B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 883C5ADE22F6DD840040F91B = { + isa = PBXGroup; + children = ( + 883C5AE922F6DD850040F91B /* P07 WhiteHousePetitions */, + 883C5AE822F6DD850040F91B /* Products */, + ); + sourceTree = ""; + }; + 883C5AE822F6DD850040F91B /* Products */ = { + isa = PBXGroup; + children = ( + 883C5AE722F6DD850040F91B /* P07 WhiteHousePetitions.app */, + ); + name = Products; + sourceTree = ""; + }; + 883C5AE922F6DD850040F91B /* P07 WhiteHousePetitions */ = { + isa = PBXGroup; + children = ( + 883C5AEA22F6DD850040F91B /* AppDelegate.swift */, + 883C5AEC22F6DD850040F91B /* ViewController.swift */, + 883C5B0022F6E9040040F91B /* DetailViewController.swift */, + 883C5AFC22F6E52F0040F91B /* Petition.swift */, + 883C5AFE22F6E5910040F91B /* Petitions.swift */, + 883C5AEE22F6DD850040F91B /* Main.storyboard */, + 883C5AF122F6DD860040F91B /* Assets.xcassets */, + 883C5AF322F6DD860040F91B /* LaunchScreen.storyboard */, + 883C5AF622F6DD860040F91B /* Info.plist */, + ); + path = "P07 WhiteHousePetitions"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 883C5AE622F6DD850040F91B /* P07 WhiteHousePetitions */ = { + isa = PBXNativeTarget; + buildConfigurationList = 883C5AF922F6DD860040F91B /* Build configuration list for PBXNativeTarget "P07 WhiteHousePetitions" */; + buildPhases = ( + 883C5AE322F6DD850040F91B /* Sources */, + 883C5AE422F6DD850040F91B /* Frameworks */, + 883C5AE522F6DD850040F91B /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "P07 WhiteHousePetitions"; + productName = "P07 WhiteHousePetitions"; + productReference = 883C5AE722F6DD850040F91B /* P07 WhiteHousePetitions.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 883C5ADF22F6DD840040F91B /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1020; + LastUpgradeCheck = 1020; + ORGANIZATIONNAME = "Mindwarp Consultancy Ltd"; + TargetAttributes = { + 883C5AE622F6DD850040F91B = { + CreatedOnToolsVersion = 10.2.1; + }; + }; + }; + buildConfigurationList = 883C5AE222F6DD840040F91B /* Build configuration list for PBXProject "P07 WhiteHousePetitions" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 883C5ADE22F6DD840040F91B; + productRefGroup = 883C5AE822F6DD850040F91B /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 883C5AE622F6DD850040F91B /* P07 WhiteHousePetitions */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 883C5AE522F6DD850040F91B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 883C5AF522F6DD860040F91B /* LaunchScreen.storyboard in Resources */, + 883C5AF222F6DD860040F91B /* Assets.xcassets in Resources */, + 883C5AF022F6DD850040F91B /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 883C5AE322F6DD850040F91B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 883C5AED22F6DD850040F91B /* ViewController.swift in Sources */, + 883C5AFF22F6E5910040F91B /* Petitions.swift in Sources */, + 883C5B0122F6E9040040F91B /* DetailViewController.swift in Sources */, + 883C5AEB22F6DD850040F91B /* AppDelegate.swift in Sources */, + 883C5AFD22F6E52F0040F91B /* Petition.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 883C5AEE22F6DD850040F91B /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 883C5AEF22F6DD850040F91B /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 883C5AF322F6DD860040F91B /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 883C5AF422F6DD860040F91B /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 883C5AF722F6DD860040F91B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + 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 = 12.2; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 883C5AF822F6DD860040F91B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + 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; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 12.2; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 883C5AFA22F6DD860040F91B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = M3R45325T7; + INFOPLIST_FILE = "P07 WhiteHousePetitions/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "com.mclapps.P07-WhiteHousePetitions"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 883C5AFB22F6DD860040F91B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = M3R45325T7; + INFOPLIST_FILE = "P07 WhiteHousePetitions/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "com.mclapps.P07-WhiteHousePetitions"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 883C5AE222F6DD840040F91B /* Build configuration list for PBXProject "P07 WhiteHousePetitions" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 883C5AF722F6DD860040F91B /* Debug */, + 883C5AF822F6DD860040F91B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 883C5AF922F6DD860040F91B /* Build configuration list for PBXNativeTarget "P07 WhiteHousePetitions" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 883C5AFA22F6DD860040F91B /* Debug */, + 883C5AFB22F6DD860040F91B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 883C5ADF22F6DD840040F91B /* Project object */; +} diff --git a/P09 WhiteHousePetitions/P07 WhiteHousePetitions.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/P09 WhiteHousePetitions/P07 WhiteHousePetitions.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..6e91e49 --- /dev/null +++ b/P09 WhiteHousePetitions/P07 WhiteHousePetitions.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/P09 WhiteHousePetitions/P07 WhiteHousePetitions.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/P09 WhiteHousePetitions/P07 WhiteHousePetitions.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/P09 WhiteHousePetitions/P07 WhiteHousePetitions.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/P09 WhiteHousePetitions/P07 WhiteHousePetitions/AppDelegate.swift b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/AppDelegate.swift new file mode 100644 index 0000000..26c5b72 --- /dev/null +++ b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/AppDelegate.swift @@ -0,0 +1,53 @@ +// +// AppDelegate.swift +// P07 WhiteHousePetitions +// +// Created by Julian Moorhouse on 04/08/2019. +// Copyright © 2019 Mindwarp Consultancy Ltd. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + + if let tabBarController = window?.rootViewController as? UITabBarController { + let storyboard = UIStoryboard(name: "Main", bundle: nil) + let vc = storyboard.instantiateViewController(withIdentifier: "sb_NavController") + vc.tabBarItem = UITabBarItem(tabBarSystemItem: .topRated, tag: 1) + tabBarController.viewControllers?.append(vc) + } + + 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 invalidate graphics rendering callbacks. 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 active 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/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Assets.xcassets/AppIcon.appiconset/Contents.json b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d8db8d6 --- /dev/null +++ b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "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" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "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" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Assets.xcassets/Contents.json b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Base.lproj/LaunchScreen.storyboard b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..bfa3612 --- /dev/null +++ b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Base.lproj/Main.storyboard b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Base.lproj/Main.storyboard new file mode 100644 index 0000000..ef82a96 --- /dev/null +++ b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Base.lproj/Main.storyboard @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/P09 WhiteHousePetitions/P07 WhiteHousePetitions/DetailViewController.swift b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/DetailViewController.swift new file mode 100644 index 0000000..d6574c8 --- /dev/null +++ b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/DetailViewController.swift @@ -0,0 +1,40 @@ +// +// DetailViewController.swift +// P07 WhiteHousePetitions +// +// Created by Julian Moorhouse on 04/08/2019. +// Copyright © 2019 Mindwarp Consultancy Ltd. All rights reserved. +// + +import UIKit +import WebKit + +class DetailViewController: UIViewController { + var webView: WKWebView! + var detailItem: Petition? + + override func loadView() { + webView = WKWebView() + view = webView + } + + override func viewDidLoad() { + super.viewDidLoad() + + guard let detailItem = detailItem else { return} + + let html = """ + + + + + + + \(detailItem.body) + + + """ + + webView.loadHTMLString(html, baseURL: nil) + } +} diff --git a/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Info.plist b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Info.plist new file mode 100644 index 0000000..16be3b6 --- /dev/null +++ b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Info.plist @@ -0,0 +1,45 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Petition.swift b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Petition.swift new file mode 100644 index 0000000..7010111 --- /dev/null +++ b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Petition.swift @@ -0,0 +1,15 @@ +// +// Petition.swift +// P07 WhiteHousePetitions +// +// Created by Julian Moorhouse on 04/08/2019. +// Copyright © 2019 Mindwarp Consultancy Ltd. All rights reserved. +// + +import Foundation + +struct Petition: Codable { + var title: String + var body: String + var signatureCount: Int +} diff --git a/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Petitions.swift b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Petitions.swift new file mode 100644 index 0000000..2619a0e --- /dev/null +++ b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/Petitions.swift @@ -0,0 +1,13 @@ +// +// Petitions.swift +// P07 WhiteHousePetitions +// +// Created by Julian Moorhouse on 04/08/2019. +// Copyright © 2019 Mindwarp Consultancy Ltd. All rights reserved. +// + +import Foundation + +struct Petitions: Codable { + var results: [Petition] +} diff --git a/P09 WhiteHousePetitions/P07 WhiteHousePetitions/ViewController.swift b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/ViewController.swift new file mode 100644 index 0000000..ef89039 --- /dev/null +++ b/P09 WhiteHousePetitions/P07 WhiteHousePetitions/ViewController.swift @@ -0,0 +1,130 @@ +// +// ViewController.swift +// P07 WhiteHousePetitions +// +// Created by Julian Moorhouse on 04/08/2019. +// Copyright © 2019 Mindwarp Consultancy Ltd. All rights reserved. +// + +import UIKit + +class ViewController: UITableViewController { + var petitions = [Petition]() + var filteredPetitions = [Petition]() + + override func viewDidLoad() { + super.viewDidLoad() + + navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Credits", style: .plain, target: self, action: #selector(credits)) + + let filter = UIBarButtonItem(barButtonSystemItem: .search, target: self, action: #selector(showFilter)) + + let reset = UIBarButtonItem(barButtonSystemItem: .trash, target: self, action: #selector(resetList)) + + navigationItem.rightBarButtonItems = [filter, reset] + + //Beware - this code will lock up the app while data is downloaded, but it's ok for example purposes here + let urlString: String + + if navigationController?.tabBarItem.tag == 0 { + // urlString = "https://api.whitehouse.gov/v1/petitions.json?limit=100" + urlString = "https://www.hackingwithswift.com/samples/petitions-1.json" + } else { + // urlString = "https://api.whitehouse.gov/v1/petitions.json?signatureCountFloor=10000&limit=100" + urlString = "https://www.hackingwithswift.com/samples/petitions-2.json" + } + + DispatchQueue.global(qos: .userInitiated).async { + [weak self] in + if let url = URL(string: urlString) { + if let data = try? Data(contentsOf: url) { + self?.parse(json: data) + return + } + } + self?.showError() + } + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return filteredPetitions.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) + + let petition = filteredPetitions[indexPath.row] + cell.textLabel?.text = petition.title + cell.detailTextLabel?.text = petition.body + return cell + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let vc = DetailViewController() + vc.detailItem = filteredPetitions[indexPath.row] + navigationController?.pushViewController(vc, animated: true) + } + + func parse(json: Data) { + let decoder = JSONDecoder() + + if let jsonPetitions = try? decoder.decode(Petitions.self, from: json) { + petitions = jsonPetitions.results + filteredPetitions = petitions + + DispatchQueue.main.async { + [weak self] in + self?.tableView.reloadData() + } + } + } + + func showError() { + DispatchQueue.main.async { + [weak self] in + let ac = UIAlertController(title: "Loading error", message: "There was a problem loading the feed, please check your connection and try again.", preferredStyle: .alert) + ac.addAction(UIAlertAction(title: "OK", style: .default)) + self?.present(ac, animated: true) + } + } + + @objc func credits() { + let ac = UIAlertController(title: "Credits", message: "Data from We The People API of the Whitehouse", preferredStyle: .alert) + + ac.addAction(UIAlertAction(title: "OK", style: .default, handler: nil)) + present(ac, animated: true) + } + + @objc func showFilter() { + let ac = UIAlertController(title: "Enter filter text", message: nil, preferredStyle: .alert) + ac.addTextField() + + let submitAction = UIAlertAction(title: "Search", style: .default) { + [weak self, weak ac] action in + + guard let filter = ac?.textFields?[0].text else { return } + + self?.filterResults(filter) + } + ac.addAction(submitAction) + present(ac, animated: true) + } + + @objc func filterResults(_ filter: String) { + + filteredPetitions.removeAll(keepingCapacity: true) + + for petition in petitions { + if petition.title.contains(filter) || petition.body.contains(filter) { + filteredPetitions.append(petition); + } + } + tableView.reloadData() + } + + @objc func resetList() { + filteredPetitions = petitions + tableView.reloadData() + } +} + diff --git a/README.md b/README.md index c9598ae..ca1d607 100644 --- a/README.md +++ b/README.md @@ -70,3 +70,8 @@ - Folder: P08 SwiftyWords, P08C SwiftyWords - Topics: Text alignment, layout margins, UIFont, addTarget, enumerated, joined, replacingOccurences and more. - Challenge changes also. + +**Day 39** +- Folder: P09 WhiteHousePetitions - DispatchQueue.global - async, DispatchQueue.main.async +- Topics: Grand Central Dispatch, quality of service queues, performSelector() and more. +- An important video on GCD https://www.hackingwithswift.com/read/9/3/gcd-101-async