├── Base.lproj └── InfoPlist.strings ├── DGQuickActionsTutorial.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── danil.gontovik.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── DGQuickActionsTutorial.xcscheme ├── DGQuickActionsTutorial ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── ShortcutIcons │ │ ├── Contents.json │ │ └── ShortcutIconFavorites.imageset │ │ ├── Contents.json │ │ ├── ShortcutIconFavorites@2x.png │ │ └── ShortcutIconFavorites@3x.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift ├── README.md ├── en.lproj └── InfoPlist.strings └── preview.PNG /Base.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | "SHORTCUT_TITLE_SEARCH" = "Search"; 2 | "SHORTCUT_TITLE_FAVORITES" = "Favorites"; -------------------------------------------------------------------------------- /DGQuickActionsTutorial.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 05D1028D1BB800740036FBB4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05D1028C1BB800740036FBB4 /* AppDelegate.swift */; }; 11 | 05D1028F1BB800740036FBB4 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05D1028E1BB800740036FBB4 /* ViewController.swift */; }; 12 | 05D102921BB800740036FBB4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 05D102901BB800740036FBB4 /* Main.storyboard */; }; 13 | 05D102941BB800740036FBB4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 05D102931BB800740036FBB4 /* Assets.xcassets */; }; 14 | 05D102971BB800740036FBB4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 05D102951BB800740036FBB4 /* LaunchScreen.storyboard */; }; 15 | 05D102AC1BB809DC0036FBB4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 05D102AE1BB809DC0036FBB4 /* InfoPlist.strings */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 05D102891BB800740036FBB4 /* DGQuickActionsTutorial.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DGQuickActionsTutorial.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 05D1028C1BB800740036FBB4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | 05D1028E1BB800740036FBB4 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | 05D102911BB800740036FBB4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | 05D102931BB800740036FBB4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | 05D102961BB800740036FBB4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | 05D102981BB800740036FBB4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | 05D102AD1BB809DC0036FBB4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/InfoPlist.strings; sourceTree = ""; }; 27 | 05D102AF1BB80A720036FBB4 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 28 | /* End PBXFileReference section */ 29 | 30 | /* Begin PBXFrameworksBuildPhase section */ 31 | 05D102861BB800740036FBB4 /* Frameworks */ = { 32 | isa = PBXFrameworksBuildPhase; 33 | buildActionMask = 2147483647; 34 | files = ( 35 | ); 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXFrameworksBuildPhase section */ 39 | 40 | /* Begin PBXGroup section */ 41 | 05D102801BB800730036FBB4 = { 42 | isa = PBXGroup; 43 | children = ( 44 | 05D102AE1BB809DC0036FBB4 /* InfoPlist.strings */, 45 | 05D1028B1BB800740036FBB4 /* DGQuickActionsTutorial */, 46 | 05D1028A1BB800740036FBB4 /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 05D1028A1BB800740036FBB4 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 05D102891BB800740036FBB4 /* DGQuickActionsTutorial.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 05D1028B1BB800740036FBB4 /* DGQuickActionsTutorial */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 05D1028C1BB800740036FBB4 /* AppDelegate.swift */, 62 | 05D1028E1BB800740036FBB4 /* ViewController.swift */, 63 | 05D102901BB800740036FBB4 /* Main.storyboard */, 64 | 05D102931BB800740036FBB4 /* Assets.xcassets */, 65 | 05D102951BB800740036FBB4 /* LaunchScreen.storyboard */, 66 | 05D102981BB800740036FBB4 /* Info.plist */, 67 | ); 68 | path = DGQuickActionsTutorial; 69 | sourceTree = ""; 70 | }; 71 | /* End PBXGroup section */ 72 | 73 | /* Begin PBXNativeTarget section */ 74 | 05D102881BB800740036FBB4 /* DGQuickActionsTutorial */ = { 75 | isa = PBXNativeTarget; 76 | buildConfigurationList = 05D1029B1BB800740036FBB4 /* Build configuration list for PBXNativeTarget "DGQuickActionsTutorial" */; 77 | buildPhases = ( 78 | 05D102851BB800740036FBB4 /* Sources */, 79 | 05D102861BB800740036FBB4 /* Frameworks */, 80 | 05D102871BB800740036FBB4 /* Resources */, 81 | ); 82 | buildRules = ( 83 | ); 84 | dependencies = ( 85 | ); 86 | name = DGQuickActionsTutorial; 87 | productName = DGQuickActionsTutorial; 88 | productReference = 05D102891BB800740036FBB4 /* DGQuickActionsTutorial.app */; 89 | productType = "com.apple.product-type.application"; 90 | }; 91 | /* End PBXNativeTarget section */ 92 | 93 | /* Begin PBXProject section */ 94 | 05D102811BB800730036FBB4 /* Project object */ = { 95 | isa = PBXProject; 96 | attributes = { 97 | LastUpgradeCheck = 0700; 98 | ORGANIZATIONNAME = "Danil Gontovnik"; 99 | TargetAttributes = { 100 | 05D102881BB800740036FBB4 = { 101 | CreatedOnToolsVersion = 7.0; 102 | }; 103 | }; 104 | }; 105 | buildConfigurationList = 05D102841BB800730036FBB4 /* Build configuration list for PBXProject "DGQuickActionsTutorial" */; 106 | compatibilityVersion = "Xcode 3.2"; 107 | developmentRegion = English; 108 | hasScannedForEncodings = 0; 109 | knownRegions = ( 110 | en, 111 | Base, 112 | ); 113 | mainGroup = 05D102801BB800730036FBB4; 114 | productRefGroup = 05D1028A1BB800740036FBB4 /* Products */; 115 | projectDirPath = ""; 116 | projectRoot = ""; 117 | targets = ( 118 | 05D102881BB800740036FBB4 /* DGQuickActionsTutorial */, 119 | ); 120 | }; 121 | /* End PBXProject section */ 122 | 123 | /* Begin PBXResourcesBuildPhase section */ 124 | 05D102871BB800740036FBB4 /* Resources */ = { 125 | isa = PBXResourcesBuildPhase; 126 | buildActionMask = 2147483647; 127 | files = ( 128 | 05D102971BB800740036FBB4 /* LaunchScreen.storyboard in Resources */, 129 | 05D102AC1BB809DC0036FBB4 /* InfoPlist.strings in Resources */, 130 | 05D102941BB800740036FBB4 /* Assets.xcassets in Resources */, 131 | 05D102921BB800740036FBB4 /* Main.storyboard in Resources */, 132 | ); 133 | runOnlyForDeploymentPostprocessing = 0; 134 | }; 135 | /* End PBXResourcesBuildPhase section */ 136 | 137 | /* Begin PBXSourcesBuildPhase section */ 138 | 05D102851BB800740036FBB4 /* Sources */ = { 139 | isa = PBXSourcesBuildPhase; 140 | buildActionMask = 2147483647; 141 | files = ( 142 | 05D1028F1BB800740036FBB4 /* ViewController.swift in Sources */, 143 | 05D1028D1BB800740036FBB4 /* AppDelegate.swift in Sources */, 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXSourcesBuildPhase section */ 148 | 149 | /* Begin PBXVariantGroup section */ 150 | 05D102901BB800740036FBB4 /* Main.storyboard */ = { 151 | isa = PBXVariantGroup; 152 | children = ( 153 | 05D102911BB800740036FBB4 /* Base */, 154 | ); 155 | name = Main.storyboard; 156 | sourceTree = ""; 157 | }; 158 | 05D102951BB800740036FBB4 /* LaunchScreen.storyboard */ = { 159 | isa = PBXVariantGroup; 160 | children = ( 161 | 05D102961BB800740036FBB4 /* Base */, 162 | ); 163 | name = LaunchScreen.storyboard; 164 | sourceTree = ""; 165 | }; 166 | 05D102AE1BB809DC0036FBB4 /* InfoPlist.strings */ = { 167 | isa = PBXVariantGroup; 168 | children = ( 169 | 05D102AD1BB809DC0036FBB4 /* Base */, 170 | 05D102AF1BB80A720036FBB4 /* en */, 171 | ); 172 | name = InfoPlist.strings; 173 | sourceTree = ""; 174 | }; 175 | /* End PBXVariantGroup section */ 176 | 177 | /* Begin XCBuildConfiguration section */ 178 | 05D102991BB800740036FBB4 /* Debug */ = { 179 | isa = XCBuildConfiguration; 180 | buildSettings = { 181 | ALWAYS_SEARCH_USER_PATHS = NO; 182 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 183 | CLANG_CXX_LIBRARY = "libc++"; 184 | CLANG_ENABLE_MODULES = YES; 185 | CLANG_ENABLE_OBJC_ARC = YES; 186 | CLANG_WARN_BOOL_CONVERSION = YES; 187 | CLANG_WARN_CONSTANT_CONVERSION = YES; 188 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 189 | CLANG_WARN_EMPTY_BODY = YES; 190 | CLANG_WARN_ENUM_CONVERSION = YES; 191 | CLANG_WARN_INT_CONVERSION = YES; 192 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 193 | CLANG_WARN_UNREACHABLE_CODE = YES; 194 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 195 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 196 | COPY_PHASE_STRIP = NO; 197 | DEBUG_INFORMATION_FORMAT = dwarf; 198 | ENABLE_STRICT_OBJC_MSGSEND = YES; 199 | ENABLE_TESTABILITY = YES; 200 | GCC_C_LANGUAGE_STANDARD = gnu99; 201 | GCC_DYNAMIC_NO_PIC = NO; 202 | GCC_NO_COMMON_BLOCKS = YES; 203 | GCC_OPTIMIZATION_LEVEL = 0; 204 | GCC_PREPROCESSOR_DEFINITIONS = ( 205 | "DEBUG=1", 206 | "$(inherited)", 207 | ); 208 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 209 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 210 | GCC_WARN_UNDECLARED_SELECTOR = YES; 211 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 212 | GCC_WARN_UNUSED_FUNCTION = YES; 213 | GCC_WARN_UNUSED_VARIABLE = YES; 214 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 215 | MTL_ENABLE_DEBUG_INFO = YES; 216 | ONLY_ACTIVE_ARCH = YES; 217 | SDKROOT = iphoneos; 218 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 219 | TARGETED_DEVICE_FAMILY = "1,2"; 220 | }; 221 | name = Debug; 222 | }; 223 | 05D1029A1BB800740036FBB4 /* Release */ = { 224 | isa = XCBuildConfiguration; 225 | buildSettings = { 226 | ALWAYS_SEARCH_USER_PATHS = NO; 227 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 228 | CLANG_CXX_LIBRARY = "libc++"; 229 | CLANG_ENABLE_MODULES = YES; 230 | CLANG_ENABLE_OBJC_ARC = YES; 231 | CLANG_WARN_BOOL_CONVERSION = YES; 232 | CLANG_WARN_CONSTANT_CONVERSION = YES; 233 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 234 | CLANG_WARN_EMPTY_BODY = YES; 235 | CLANG_WARN_ENUM_CONVERSION = YES; 236 | CLANG_WARN_INT_CONVERSION = YES; 237 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 238 | CLANG_WARN_UNREACHABLE_CODE = YES; 239 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 240 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 241 | COPY_PHASE_STRIP = NO; 242 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 243 | ENABLE_NS_ASSERTIONS = NO; 244 | ENABLE_STRICT_OBJC_MSGSEND = YES; 245 | GCC_C_LANGUAGE_STANDARD = gnu99; 246 | GCC_NO_COMMON_BLOCKS = YES; 247 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 248 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 249 | GCC_WARN_UNDECLARED_SELECTOR = YES; 250 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 251 | GCC_WARN_UNUSED_FUNCTION = YES; 252 | GCC_WARN_UNUSED_VARIABLE = YES; 253 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 254 | MTL_ENABLE_DEBUG_INFO = NO; 255 | SDKROOT = iphoneos; 256 | TARGETED_DEVICE_FAMILY = "1,2"; 257 | VALIDATE_PRODUCT = YES; 258 | }; 259 | name = Release; 260 | }; 261 | 05D1029C1BB800740036FBB4 /* Debug */ = { 262 | isa = XCBuildConfiguration; 263 | buildSettings = { 264 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 265 | INFOPLIST_FILE = DGQuickActionsTutorial/Info.plist; 266 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 267 | PRODUCT_BUNDLE_IDENTIFIER = com.gatafan.DGQuickActionsTutorial; 268 | PRODUCT_NAME = "$(TARGET_NAME)"; 269 | }; 270 | name = Debug; 271 | }; 272 | 05D1029D1BB800740036FBB4 /* Release */ = { 273 | isa = XCBuildConfiguration; 274 | buildSettings = { 275 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 276 | INFOPLIST_FILE = DGQuickActionsTutorial/Info.plist; 277 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 278 | PRODUCT_BUNDLE_IDENTIFIER = com.gatafan.DGQuickActionsTutorial; 279 | PRODUCT_NAME = "$(TARGET_NAME)"; 280 | }; 281 | name = Release; 282 | }; 283 | /* End XCBuildConfiguration section */ 284 | 285 | /* Begin XCConfigurationList section */ 286 | 05D102841BB800730036FBB4 /* Build configuration list for PBXProject "DGQuickActionsTutorial" */ = { 287 | isa = XCConfigurationList; 288 | buildConfigurations = ( 289 | 05D102991BB800740036FBB4 /* Debug */, 290 | 05D1029A1BB800740036FBB4 /* Release */, 291 | ); 292 | defaultConfigurationIsVisible = 0; 293 | defaultConfigurationName = Release; 294 | }; 295 | 05D1029B1BB800740036FBB4 /* Build configuration list for PBXNativeTarget "DGQuickActionsTutorial" */ = { 296 | isa = XCConfigurationList; 297 | buildConfigurations = ( 298 | 05D1029C1BB800740036FBB4 /* Debug */, 299 | 05D1029D1BB800740036FBB4 /* Release */, 300 | ); 301 | defaultConfigurationIsVisible = 0; 302 | }; 303 | /* End XCConfigurationList section */ 304 | }; 305 | rootObject = 05D102811BB800730036FBB4 /* Project object */; 306 | } 307 | -------------------------------------------------------------------------------- /DGQuickActionsTutorial.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DGQuickActionsTutorial.xcodeproj/xcuserdata/danil.gontovik.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /DGQuickActionsTutorial.xcodeproj/xcuserdata/danil.gontovik.xcuserdatad/xcschemes/DGQuickActionsTutorial.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /DGQuickActionsTutorial/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // DGQuickActionsTutorial 4 | // 5 | // Created by Danil Gontovnik on 9/27/15. 6 | // Copyright © 2015 Danil Gontovnik. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | enum DGShortcutItemType: String { 12 | case Search 13 | case Favorites 14 | case Dynamic 15 | 16 | init?(shortcutItem: UIApplicationShortcutItem) { 17 | guard let last = shortcutItem.type.componentsSeparatedByString(".").last else { return nil } 18 | self.init(rawValue: last) 19 | } 20 | 21 | var type: String { 22 | return NSBundle.mainBundle().bundleIdentifier! + ".\(self.rawValue)" 23 | } 24 | } 25 | 26 | @UIApplicationMain 27 | class AppDelegate: UIResponder, UIApplicationDelegate { 28 | 29 | var window: UIWindow? 30 | 31 | 32 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 33 | 34 | if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsShortcutItemKey] as? UIApplicationShortcutItem { 35 | handleShortcutItem(shortcutItem) 36 | } 37 | 38 | return true 39 | } 40 | 41 | private func handleShortcutItem(shortcutItem: UIApplicationShortcutItem) { 42 | if let rootViewController = window?.rootViewController, let shortcutItemType = DGShortcutItemType(shortcutItem: shortcutItem) { 43 | rootViewController.dismissViewControllerAnimated(false, completion: nil) 44 | let alertController = UIAlertController(title: "", message: "", preferredStyle: .Alert) 45 | 46 | switch shortcutItemType { 47 | case .Search: 48 | alertController.message = "It's time to search" 49 | break 50 | case .Favorites: 51 | alertController.message = "Show me my favorites" 52 | break 53 | case .Dynamic: 54 | alertController.message = "Dynamic shortcut works!" 55 | break 56 | } 57 | 58 | alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil)) 59 | rootViewController.presentViewController(alertController, animated: true, completion: nil) 60 | } 61 | } 62 | 63 | func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) { 64 | handleShortcutItem(shortcutItem) 65 | } 66 | 67 | func applicationWillResignActive(application: UIApplication) { 68 | // 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. 69 | // 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. 70 | } 71 | 72 | func applicationDidEnterBackground(application: UIApplication) { 73 | // 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. 74 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 75 | } 76 | 77 | func applicationWillEnterForeground(application: UIApplication) { 78 | // 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. 79 | } 80 | 81 | func applicationDidBecomeActive(application: UIApplication) { 82 | // 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. 83 | } 84 | 85 | func applicationWillTerminate(application: UIApplication) { 86 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 87 | } 88 | 89 | 90 | } 91 | 92 | -------------------------------------------------------------------------------- /DGQuickActionsTutorial/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /DGQuickActionsTutorial/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /DGQuickActionsTutorial/Assets.xcassets/ShortcutIcons/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /DGQuickActionsTutorial/Assets.xcassets/ShortcutIcons/ShortcutIconFavorites.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "ShortcutIconFavorites@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "ShortcutIconFavorites@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /DGQuickActionsTutorial/Assets.xcassets/ShortcutIcons/ShortcutIconFavorites.imageset/ShortcutIconFavorites@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gontovnik/DGQuickActionsTutorial/16ba9eed3bb1521923941d95e9ef5596e5239c54/DGQuickActionsTutorial/Assets.xcassets/ShortcutIcons/ShortcutIconFavorites.imageset/ShortcutIconFavorites@2x.png -------------------------------------------------------------------------------- /DGQuickActionsTutorial/Assets.xcassets/ShortcutIcons/ShortcutIconFavorites.imageset/ShortcutIconFavorites@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gontovnik/DGQuickActionsTutorial/16ba9eed3bb1521923941d95e9ef5596e5239c54/DGQuickActionsTutorial/Assets.xcassets/ShortcutIcons/ShortcutIconFavorites.imageset/ShortcutIconFavorites@3x.png -------------------------------------------------------------------------------- /DGQuickActionsTutorial/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /DGQuickActionsTutorial/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /DGQuickActionsTutorial/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | UIApplicationShortcutItems 48 | 49 | 50 | UIApplicationShortcutItemIconType 51 | UIApplicationShortcutIconTypeSearch 52 | UIApplicationShortcutItemTitle 53 | SHORTCUT_TITLE_SEARCH 54 | UIApplicationShortcutItemType 55 | $(PRODUCT_BUNDLE_IDENTIFIER).Search 56 | 57 | 58 | UIApplicationShortcutItemTitle 59 | SHORTCUT_TITLE_FAVORITES 60 | UIApplicationShortcutItemType 61 | $(PRODUCT_BUNDLE_IDENTIFIER).Favorites 62 | UIApplicationShortcutItemIconFile 63 | ShortcutIconFavorites 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /DGQuickActionsTutorial/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // DGQuickActionsTutorial 4 | // 5 | // Created by Danil Gontovnik on 9/27/15. 6 | // Copyright © 2015 Danil Gontovnik. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension UIApplicationShortcutIconType { 12 | var toString: String { 13 | switch self { 14 | case .Compose: return "Compose" 15 | case .Play: return "Play" 16 | case .Pause: return "Pause" 17 | case .Add: return "Add" 18 | case .Location: return "Location" 19 | case .Search: return "Search" 20 | case .Share: return "Share" 21 | } 22 | } 23 | 24 | init?(string: String) { 25 | switch string { 26 | case "Compose": self.init(rawValue: UIApplicationShortcutIconType.Compose.rawValue) 27 | case "Play": self.init(rawValue: UIApplicationShortcutIconType.Play.rawValue) 28 | case "Pause": self.init(rawValue: UIApplicationShortcutIconType.Pause.rawValue) 29 | case "Add": self.init(rawValue: UIApplicationShortcutIconType.Add.rawValue) 30 | case "Location": self.init(rawValue: UIApplicationShortcutIconType.Location.rawValue) 31 | case "Search": self.init(rawValue: UIApplicationShortcutIconType.Search.rawValue) 32 | case "Share": self.init(rawValue: UIApplicationShortcutIconType.Share.rawValue) 33 | default: return nil 34 | } 35 | } 36 | 37 | static var allTypesToStrings: [String] { 38 | return [UIApplicationShortcutIconType.Compose.toString, UIApplicationShortcutIconType.Play.toString, UIApplicationShortcutIconType.Pause.toString, UIApplicationShortcutIconType.Add.toString, UIApplicationShortcutIconType.Location.toString, UIApplicationShortcutIconType.Search.toString, UIApplicationShortcutIconType.Share.toString] 39 | } 40 | } 41 | 42 | class ViewController: UIViewController { 43 | 44 | // MARK: - 45 | // MARK: Vars 46 | 47 | private let titleTextField = UITextField() 48 | private let subtitleTextField = UITextField() 49 | private var iconTypeSegmentedControl = UISegmentedControl(items: UIApplicationShortcutIconType.allTypesToStrings) 50 | private let updateButton = UIButton(type: .System) 51 | 52 | // MARK: - 53 | 54 | override func loadView() { 55 | super.loadView() 56 | titleTextField.placeholder = "Title" 57 | titleTextField.delegate = self 58 | view.addSubview(titleTextField) 59 | 60 | subtitleTextField.placeholder = "Subtitle" 61 | subtitleTextField.delegate = self 62 | view.addSubview(subtitleTextField); 63 | 64 | updateButton.setTitle("Update shortcut", forState: .Normal) 65 | updateButton.addTarget(self, action: Selector("updateDynamicAction"), forControlEvents: .TouchUpInside) 66 | view.addSubview(updateButton) 67 | 68 | iconTypeSegmentedControl.selectedSegmentIndex = 0 69 | view.addSubview(iconTypeSegmentedControl) 70 | 71 | view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "viewTapped")) 72 | } 73 | 74 | // MARK: - 75 | // MARK: Methods 76 | 77 | func viewTapped() { 78 | view.endEditing(true) 79 | } 80 | 81 | func updateDynamicAction() { 82 | guard let title = titleTextField.text else { 83 | UIApplication.sharedApplication().shortcutItems = nil 84 | return 85 | } 86 | 87 | let type = DGShortcutItemType.Dynamic.type 88 | let shortcutIconType = UIApplicationShortcutIconType(string: iconTypeSegmentedControl.titleForSegmentAtIndex(iconTypeSegmentedControl.selectedSegmentIndex)!)! 89 | let icon = UIApplicationShortcutIcon(type: shortcutIconType) 90 | 91 | let dynamicShortcut = UIApplicationShortcutItem(type: type, localizedTitle: title, localizedSubtitle: subtitleTextField.text, icon: icon, userInfo: nil) 92 | UIApplication.sharedApplication().shortcutItems = [dynamicShortcut] 93 | } 94 | 95 | // MARK: - 96 | // MARK: Layout 97 | 98 | override func viewWillLayoutSubviews() { 99 | super.viewWillLayoutSubviews() 100 | 101 | let width = view.bounds.width 102 | 103 | let horizontalMargin: CGFloat = 20.0 104 | let elementHeight: CGFloat = 40.0 105 | let verticalSpacing: CGFloat = 20.0 106 | 107 | titleTextField.frame = CGRect(x: horizontalMargin, y: 50.0, width: width - 2 * horizontalMargin, height: elementHeight) 108 | subtitleTextField.frame = CGRectOffset(titleTextField.frame, 0.0, elementHeight + verticalSpacing) 109 | iconTypeSegmentedControl.frame = CGRectOffset(subtitleTextField.frame, 0.0, elementHeight + verticalSpacing) 110 | updateButton.frame = CGRectOffset(iconTypeSegmentedControl.frame, 0.0, elementHeight + verticalSpacing) 111 | } 112 | 113 | } 114 | 115 | // MARK: - 116 | // MARK: UITextField Delegate 117 | 118 | extension ViewController: UITextFieldDelegate { 119 | 120 | func textFieldShouldReturn(textField: UITextField) -> Bool { 121 | if textField == titleTextField { 122 | subtitleTextField.becomeFirstResponder() 123 | } else if textField == subtitleTextField { 124 | subtitleTextField.resignFirstResponder() 125 | } 126 | 127 | return true 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DGQuickActionsTutorial 2 | Source code for quick actions tutorial (http://iostuts.io/2015/10/08/how-to-add-quick-actions/) 3 | 4 | ![alt tag](https://raw.githubusercontent.com/gontovnik/DGQuickActionsTutorial/master/preview.PNG) 5 | -------------------------------------------------------------------------------- /en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | "SHORTCUT_TITLE_SEARCH" = "Search"; 2 | "SHORTCUT_TITLE_FAVORITES" = "Favorites"; -------------------------------------------------------------------------------- /preview.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gontovnik/DGQuickActionsTutorial/16ba9eed3bb1521923941d95e9ef5596e5239c54/preview.PNG --------------------------------------------------------------------------------