├── AutocompleteExample.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── George.xcuserdatad │ └── xcschemes │ ├── AutocompleteExample.xcscheme │ └── xcschememanagement.plist ├── AutocompleteExample ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── SearchViewController.swift └── README.md /AutocompleteExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5E8BF1AC1EB0DB4A0083A772 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E8BF1AB1EB0DB4A0083A772 /* AppDelegate.swift */; }; 11 | 5E8BF1AE1EB0DB4A0083A772 /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E8BF1AD1EB0DB4A0083A772 /* SearchViewController.swift */; }; 12 | 5E8BF1B11EB0DB4A0083A772 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5E8BF1AF1EB0DB4A0083A772 /* Main.storyboard */; }; 13 | 5E8BF1B31EB0DB4A0083A772 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5E8BF1B21EB0DB4A0083A772 /* Assets.xcassets */; }; 14 | 5E8BF1B61EB0DB4A0083A772 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5E8BF1B41EB0DB4A0083A772 /* LaunchScreen.storyboard */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | 5E8BF1A81EB0DB4A0083A772 /* AutocompleteExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AutocompleteExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | 5E8BF1AB1EB0DB4A0083A772 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 20 | 5E8BF1AD1EB0DB4A0083A772 /* SearchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchViewController.swift; sourceTree = ""; }; 21 | 5E8BF1B01EB0DB4A0083A772 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 22 | 5E8BF1B21EB0DB4A0083A772 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | 5E8BF1B51EB0DB4A0083A772 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 24 | 5E8BF1B71EB0DB4A0083A772 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 25 | /* End PBXFileReference section */ 26 | 27 | /* Begin PBXFrameworksBuildPhase section */ 28 | 5E8BF1A51EB0DB4A0083A772 /* Frameworks */ = { 29 | isa = PBXFrameworksBuildPhase; 30 | buildActionMask = 2147483647; 31 | files = ( 32 | ); 33 | runOnlyForDeploymentPostprocessing = 0; 34 | }; 35 | /* End PBXFrameworksBuildPhase section */ 36 | 37 | /* Begin PBXGroup section */ 38 | 5E8BF19F1EB0DB4A0083A772 = { 39 | isa = PBXGroup; 40 | children = ( 41 | 5E8BF1AA1EB0DB4A0083A772 /* AutocompleteExample */, 42 | 5E8BF1A91EB0DB4A0083A772 /* Products */, 43 | ); 44 | sourceTree = ""; 45 | }; 46 | 5E8BF1A91EB0DB4A0083A772 /* Products */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | 5E8BF1A81EB0DB4A0083A772 /* AutocompleteExample.app */, 50 | ); 51 | name = Products; 52 | sourceTree = ""; 53 | }; 54 | 5E8BF1AA1EB0DB4A0083A772 /* AutocompleteExample */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 5E8BF1AB1EB0DB4A0083A772 /* AppDelegate.swift */, 58 | 5E8BF1AD1EB0DB4A0083A772 /* SearchViewController.swift */, 59 | 5E8BF1AF1EB0DB4A0083A772 /* Main.storyboard */, 60 | 5E8BF1B21EB0DB4A0083A772 /* Assets.xcassets */, 61 | 5E8BF1B41EB0DB4A0083A772 /* LaunchScreen.storyboard */, 62 | 5E8BF1B71EB0DB4A0083A772 /* Info.plist */, 63 | ); 64 | path = AutocompleteExample; 65 | sourceTree = ""; 66 | }; 67 | /* End PBXGroup section */ 68 | 69 | /* Begin PBXNativeTarget section */ 70 | 5E8BF1A71EB0DB4A0083A772 /* AutocompleteExample */ = { 71 | isa = PBXNativeTarget; 72 | buildConfigurationList = 5E8BF1BA1EB0DB4A0083A772 /* Build configuration list for PBXNativeTarget "AutocompleteExample" */; 73 | buildPhases = ( 74 | 5E8BF1A41EB0DB4A0083A772 /* Sources */, 75 | 5E8BF1A51EB0DB4A0083A772 /* Frameworks */, 76 | 5E8BF1A61EB0DB4A0083A772 /* Resources */, 77 | ); 78 | buildRules = ( 79 | ); 80 | dependencies = ( 81 | ); 82 | name = AutocompleteExample; 83 | productName = AutocompleteExample; 84 | productReference = 5E8BF1A81EB0DB4A0083A772 /* AutocompleteExample.app */; 85 | productType = "com.apple.product-type.application"; 86 | }; 87 | /* End PBXNativeTarget section */ 88 | 89 | /* Begin PBXProject section */ 90 | 5E8BF1A01EB0DB4A0083A772 /* Project object */ = { 91 | isa = PBXProject; 92 | attributes = { 93 | LastSwiftUpdateCheck = 0830; 94 | LastUpgradeCheck = 0830; 95 | ORGANIZATIONNAME = "George McDonnell"; 96 | TargetAttributes = { 97 | 5E8BF1A71EB0DB4A0083A772 = { 98 | CreatedOnToolsVersion = 8.3.2; 99 | ProvisioningStyle = Automatic; 100 | }; 101 | }; 102 | }; 103 | buildConfigurationList = 5E8BF1A31EB0DB4A0083A772 /* Build configuration list for PBXProject "AutocompleteExample" */; 104 | compatibilityVersion = "Xcode 3.2"; 105 | developmentRegion = English; 106 | hasScannedForEncodings = 0; 107 | knownRegions = ( 108 | en, 109 | Base, 110 | ); 111 | mainGroup = 5E8BF19F1EB0DB4A0083A772; 112 | productRefGroup = 5E8BF1A91EB0DB4A0083A772 /* Products */; 113 | projectDirPath = ""; 114 | projectRoot = ""; 115 | targets = ( 116 | 5E8BF1A71EB0DB4A0083A772 /* AutocompleteExample */, 117 | ); 118 | }; 119 | /* End PBXProject section */ 120 | 121 | /* Begin PBXResourcesBuildPhase section */ 122 | 5E8BF1A61EB0DB4A0083A772 /* Resources */ = { 123 | isa = PBXResourcesBuildPhase; 124 | buildActionMask = 2147483647; 125 | files = ( 126 | 5E8BF1B61EB0DB4A0083A772 /* LaunchScreen.storyboard in Resources */, 127 | 5E8BF1B31EB0DB4A0083A772 /* Assets.xcassets in Resources */, 128 | 5E8BF1B11EB0DB4A0083A772 /* Main.storyboard in Resources */, 129 | ); 130 | runOnlyForDeploymentPostprocessing = 0; 131 | }; 132 | /* End PBXResourcesBuildPhase section */ 133 | 134 | /* Begin PBXSourcesBuildPhase section */ 135 | 5E8BF1A41EB0DB4A0083A772 /* Sources */ = { 136 | isa = PBXSourcesBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | 5E8BF1AE1EB0DB4A0083A772 /* SearchViewController.swift in Sources */, 140 | 5E8BF1AC1EB0DB4A0083A772 /* AppDelegate.swift in Sources */, 141 | ); 142 | runOnlyForDeploymentPostprocessing = 0; 143 | }; 144 | /* End PBXSourcesBuildPhase section */ 145 | 146 | /* Begin PBXVariantGroup section */ 147 | 5E8BF1AF1EB0DB4A0083A772 /* Main.storyboard */ = { 148 | isa = PBXVariantGroup; 149 | children = ( 150 | 5E8BF1B01EB0DB4A0083A772 /* Base */, 151 | ); 152 | name = Main.storyboard; 153 | sourceTree = ""; 154 | }; 155 | 5E8BF1B41EB0DB4A0083A772 /* LaunchScreen.storyboard */ = { 156 | isa = PBXVariantGroup; 157 | children = ( 158 | 5E8BF1B51EB0DB4A0083A772 /* Base */, 159 | ); 160 | name = LaunchScreen.storyboard; 161 | sourceTree = ""; 162 | }; 163 | /* End PBXVariantGroup section */ 164 | 165 | /* Begin XCBuildConfiguration section */ 166 | 5E8BF1B81EB0DB4A0083A772 /* Debug */ = { 167 | isa = XCBuildConfiguration; 168 | buildSettings = { 169 | ALWAYS_SEARCH_USER_PATHS = NO; 170 | CLANG_ANALYZER_NONNULL = YES; 171 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 172 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 173 | CLANG_CXX_LIBRARY = "libc++"; 174 | CLANG_ENABLE_MODULES = YES; 175 | CLANG_ENABLE_OBJC_ARC = YES; 176 | CLANG_WARN_BOOL_CONVERSION = YES; 177 | CLANG_WARN_CONSTANT_CONVERSION = YES; 178 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 179 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 180 | CLANG_WARN_EMPTY_BODY = YES; 181 | CLANG_WARN_ENUM_CONVERSION = YES; 182 | CLANG_WARN_INFINITE_RECURSION = YES; 183 | CLANG_WARN_INT_CONVERSION = YES; 184 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 185 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 186 | CLANG_WARN_UNREACHABLE_CODE = YES; 187 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 188 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 189 | COPY_PHASE_STRIP = NO; 190 | DEBUG_INFORMATION_FORMAT = dwarf; 191 | ENABLE_STRICT_OBJC_MSGSEND = YES; 192 | ENABLE_TESTABILITY = YES; 193 | GCC_C_LANGUAGE_STANDARD = gnu99; 194 | GCC_DYNAMIC_NO_PIC = NO; 195 | GCC_NO_COMMON_BLOCKS = YES; 196 | GCC_OPTIMIZATION_LEVEL = 0; 197 | GCC_PREPROCESSOR_DEFINITIONS = ( 198 | "DEBUG=1", 199 | "$(inherited)", 200 | ); 201 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 202 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 203 | GCC_WARN_UNDECLARED_SELECTOR = YES; 204 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 205 | GCC_WARN_UNUSED_FUNCTION = YES; 206 | GCC_WARN_UNUSED_VARIABLE = YES; 207 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 208 | MTL_ENABLE_DEBUG_INFO = YES; 209 | ONLY_ACTIVE_ARCH = YES; 210 | SDKROOT = iphoneos; 211 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 212 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 213 | TARGETED_DEVICE_FAMILY = "1,2"; 214 | }; 215 | name = Debug; 216 | }; 217 | 5E8BF1B91EB0DB4A0083A772 /* Release */ = { 218 | isa = XCBuildConfiguration; 219 | buildSettings = { 220 | ALWAYS_SEARCH_USER_PATHS = NO; 221 | CLANG_ANALYZER_NONNULL = YES; 222 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 223 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 224 | CLANG_CXX_LIBRARY = "libc++"; 225 | CLANG_ENABLE_MODULES = YES; 226 | CLANG_ENABLE_OBJC_ARC = YES; 227 | CLANG_WARN_BOOL_CONVERSION = YES; 228 | CLANG_WARN_CONSTANT_CONVERSION = YES; 229 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 230 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 231 | CLANG_WARN_EMPTY_BODY = YES; 232 | CLANG_WARN_ENUM_CONVERSION = YES; 233 | CLANG_WARN_INFINITE_RECURSION = YES; 234 | CLANG_WARN_INT_CONVERSION = YES; 235 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 236 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 237 | CLANG_WARN_UNREACHABLE_CODE = YES; 238 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 239 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 240 | COPY_PHASE_STRIP = NO; 241 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 242 | ENABLE_NS_ASSERTIONS = NO; 243 | ENABLE_STRICT_OBJC_MSGSEND = YES; 244 | GCC_C_LANGUAGE_STANDARD = gnu99; 245 | GCC_NO_COMMON_BLOCKS = YES; 246 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 247 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 248 | GCC_WARN_UNDECLARED_SELECTOR = YES; 249 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 250 | GCC_WARN_UNUSED_FUNCTION = YES; 251 | GCC_WARN_UNUSED_VARIABLE = YES; 252 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 253 | MTL_ENABLE_DEBUG_INFO = NO; 254 | SDKROOT = iphoneos; 255 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 256 | TARGETED_DEVICE_FAMILY = "1,2"; 257 | VALIDATE_PRODUCT = YES; 258 | }; 259 | name = Release; 260 | }; 261 | 5E8BF1BB1EB0DB4A0083A772 /* Debug */ = { 262 | isa = XCBuildConfiguration; 263 | buildSettings = { 264 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 265 | INFOPLIST_FILE = AutocompleteExample/Info.plist; 266 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 267 | PRODUCT_BUNDLE_IDENTIFIER = com.georgemcdonnell.AutocompleteExample; 268 | PRODUCT_NAME = "$(TARGET_NAME)"; 269 | SWIFT_VERSION = 3.0; 270 | }; 271 | name = Debug; 272 | }; 273 | 5E8BF1BC1EB0DB4A0083A772 /* Release */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 277 | INFOPLIST_FILE = AutocompleteExample/Info.plist; 278 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 279 | PRODUCT_BUNDLE_IDENTIFIER = com.georgemcdonnell.AutocompleteExample; 280 | PRODUCT_NAME = "$(TARGET_NAME)"; 281 | SWIFT_VERSION = 3.0; 282 | }; 283 | name = Release; 284 | }; 285 | /* End XCBuildConfiguration section */ 286 | 287 | /* Begin XCConfigurationList section */ 288 | 5E8BF1A31EB0DB4A0083A772 /* Build configuration list for PBXProject "AutocompleteExample" */ = { 289 | isa = XCConfigurationList; 290 | buildConfigurations = ( 291 | 5E8BF1B81EB0DB4A0083A772 /* Debug */, 292 | 5E8BF1B91EB0DB4A0083A772 /* Release */, 293 | ); 294 | defaultConfigurationIsVisible = 0; 295 | defaultConfigurationName = Release; 296 | }; 297 | 5E8BF1BA1EB0DB4A0083A772 /* Build configuration list for PBXNativeTarget "AutocompleteExample" */ = { 298 | isa = XCConfigurationList; 299 | buildConfigurations = ( 300 | 5E8BF1BB1EB0DB4A0083A772 /* Debug */, 301 | 5E8BF1BC1EB0DB4A0083A772 /* Release */, 302 | ); 303 | defaultConfigurationIsVisible = 0; 304 | }; 305 | /* End XCConfigurationList section */ 306 | }; 307 | rootObject = 5E8BF1A01EB0DB4A0083A772 /* Project object */; 308 | } 309 | -------------------------------------------------------------------------------- /AutocompleteExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AutocompleteExample.xcodeproj/xcuserdata/George.xcuserdatad/xcschemes/AutocompleteExample.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 | -------------------------------------------------------------------------------- /AutocompleteExample.xcodeproj/xcuserdata/George.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | AutocompleteExample.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 5E8BF1A71EB0DB4A0083A772 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /AutocompleteExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // AutocompleteExample 4 | // 5 | // Created by George McDonnell on 26/04/2017. 6 | // Copyright © 2017 George McDonnell. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // 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. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // 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. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /AutocompleteExample/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 | } -------------------------------------------------------------------------------- /AutocompleteExample/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 | -------------------------------------------------------------------------------- /AutocompleteExample/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 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /AutocompleteExample/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 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /AutocompleteExample/SearchViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SearchViewController.swift 3 | // AutocompleteExample 4 | // 5 | // Created by George McDonnell on 26/04/2017. 6 | // Copyright © 2017 George McDonnell. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import MapKit 11 | 12 | class SearchViewController: UIViewController { 13 | 14 | var searchCompleter = MKLocalSearchCompleter() 15 | var searchResults = [MKLocalSearchCompletion]() 16 | 17 | @IBOutlet weak var searchResultsTableView: UITableView! 18 | 19 | override func viewDidLoad() { 20 | super.viewDidLoad() 21 | // Do any additional setup after loading the view, typically from a nib. 22 | 23 | searchCompleter.delegate = self 24 | } 25 | 26 | } 27 | 28 | extension SearchViewController: UISearchBarDelegate { 29 | 30 | func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { 31 | 32 | searchCompleter.queryFragment = searchText 33 | } 34 | } 35 | 36 | extension SearchViewController: MKLocalSearchCompleterDelegate { 37 | 38 | func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) { 39 | searchResults = completer.results 40 | searchResultsTableView.reloadData() 41 | } 42 | 43 | func completer(_ completer: MKLocalSearchCompleter, didFailWithError error: Error) { 44 | // handle error 45 | } 46 | } 47 | 48 | extension SearchViewController: UITableViewDataSource { 49 | 50 | func numberOfSections(in tableView: UITableView) -> Int { 51 | return 1 52 | } 53 | 54 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 55 | return searchResults.count 56 | } 57 | 58 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 59 | let searchResult = searchResults[indexPath.row] 60 | let cell = UITableViewCell(style: .subtitle, reuseIdentifier: nil) 61 | cell.textLabel?.text = searchResult.title 62 | cell.detailTextLabel?.text = searchResult.subtitle 63 | return cell 64 | } 65 | } 66 | 67 | extension SearchViewController: UITableViewDelegate { 68 | 69 | func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 70 | tableView.deselectRow(at: indexPath, animated: true) 71 | 72 | let completion = searchResults[indexPath.row] 73 | 74 | let searchRequest = MKLocalSearchRequest(completion: completion) 75 | let search = MKLocalSearch(request: searchRequest) 76 | search.start { (response, error) in 77 | let coordinate = response?.mapItems[0].placemark.coordinate 78 | print(String(describing: coordinate)) 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MapKit Autocomplete 2 | 3 | A simple example showing Apple MapKit's autocomplete functionality. 4 | 5 | 6 | 7 | 8 | 9 | ### Highlighting the search query 10 | 11 | The method below allows you to highlight the user's search string within the table view. This gives the user more information about their search results as they are appearing. 12 | 13 | ```swift 14 | /** 15 | Highlights the matching search strings with the results 16 | - parameter text: The text to highlight 17 | - parameter ranges: The ranges where the text should be highlighted 18 | - parameter size: The size the text should be set at 19 | - returns: A highlighted attributed string with the ranges highlighted 20 | */ 21 | func highlightedText(_ text: String, inRanges ranges: [NSValue], size: CGFloat) -> NSAttributedString { 22 | let attributedText = NSMutableAttributedString(string: text) 23 | let regular = UIFont.systemFont(ofSize: size) 24 | attributedText.addAttribute(NSFontAttributeName, value:regular, range:NSMakeRange(0, text.characters.count)) 25 | 26 | let bold = UIFont.boldSystemFont(ofSize: size) 27 | for value in ranges { 28 | attributedText.addAttribute(NSFontAttributeName, value:bold, range:value.rangeValue) 29 | } 30 | return attributedText 31 | } 32 | ``` 33 | 34 | All you need to do is slightly modify the ```cellForRowAtIndexPath``` method inside your ```UITableViewDataSource``` to use attributed strings as follows: 35 | 36 | ```swift 37 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 38 | let searchResult = searchResults[indexPath.row] 39 | let cell = UITableViewCell(style: .subtitle, reuseIdentifier: nil) 40 | 41 | cell.textLabel?.attributedText = highlightedText(searchResult.title, inRanges: searchResult.titleHighlightRanges, size: 17.0) 42 | cell.detailTextLabel?.attributedText = highlightedText(searchResult.subtitle, inRanges: searchResult.subtitleHighlightRanges, size: 12.0) 43 | 44 | return cell 45 | } 46 | ``` 47 | 48 | You can see here that we replaced the standard title and subtitle with attributed strings to embolden the text that matches the search query. 49 | 50 | 51 | --------------------------------------------------------------------------------