├── .DS_Store ├── .gitignore ├── AutocompleteTextfieldSwift.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ ├── AutocompleteTextfieldSwift.xccheckout │ │ └── AutocompleteTextfieldSwift.xcscmblueprint │ └── xcuserdata │ │ ├── Mylene.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── admin.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── Mylene.xcuserdatad │ └── xcschemes │ └── AutocompleteTextfieldSwift.xcscheme ├── AutocompleteTextfieldSwift ├── AutoCompleteTextField │ └── AutoCompleteTextField.swift ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Controllers │ ├── AppDelegate.swift │ └── ViewController.swift ├── Helpers │ ├── Location.swift │ └── MKMapViewExtension.swift ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json └── Info.plist ├── AutocompleteTextfieldSwiftTests ├── AutocompleteTextfieldSwiftTests.swift └── Info.plist ├── LICENSE └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mnbayan/AutocompleteTextfieldSwift/2435915feda8dbd5e4793452b5b49db28ebb24e8/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate] 19 | .DS_Store 20 | 21 | # CocoaPods 22 | # 23 | # We recommend against adding the Pods directory to your .gitignore. However 24 | # you should judge for yourself, the pros and cons are mentioned at: 25 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 26 | # 27 | # Pods/ 28 | 29 | # Carthage 30 | # 31 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 32 | # Carthage/Checkouts 33 | -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F905D60F1B419684009DA356 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = F905D60B1B419684009DA356 /* LaunchScreen.xib */; }; 11 | F905D6101B419684009DA356 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F905D60D1B419684009DA356 /* Main.storyboard */; }; 12 | F96E31911A98DC36001DCEBF /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F96E31901A98DC36001DCEBF /* Images.xcassets */; }; 13 | F96E31A01A98DC36001DCEBF /* AutocompleteTextfieldSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F96E319F1A98DC36001DCEBF /* AutocompleteTextfieldSwiftTests.swift */; }; 14 | F96E31B41A98DCA3001DCEBF /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F96E31B11A98DCA3001DCEBF /* AppDelegate.swift */; }; 15 | F96E31B51A98DCA3001DCEBF /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F96E31B21A98DCA3001DCEBF /* ViewController.swift */; }; 16 | F99A8A351A99ACA700DFD19D /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F99A8A341A99ACA700DFD19D /* MapKit.framework */; }; 17 | F99A8A371A99ACAB00DFD19D /* CoreLocation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F99A8A361A99ACAB00DFD19D /* CoreLocation.framework */; }; 18 | F99A8A3C1A99ADAF00DFD19D /* MKMapViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F99A8A3B1A99ADAF00DFD19D /* MKMapViewExtension.swift */; }; 19 | F99A8A421A99CEF500DFD19D /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = F99A8A411A99CEF500DFD19D /* Location.swift */; }; 20 | F9DD71CF1CA3F20200B17E74 /* AutoCompleteTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9DD71CE1CA3F20200B17E74 /* AutoCompleteTextField.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | F96E319A1A98DC36001DCEBF /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = F96E317C1A98DC35001DCEBF /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = F96E31831A98DC35001DCEBF; 29 | remoteInfo = AutocompleteTextfieldSwift; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | F905D60C1B419684009DA356 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = AutocompleteTextfieldSwift/Base.lproj/LaunchScreen.xib; sourceTree = SOURCE_ROOT; }; 35 | F905D60E1B419684009DA356 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = AutocompleteTextfieldSwift/Base.lproj/Main.storyboard; sourceTree = SOURCE_ROOT; }; 36 | F96E31841A98DC35001DCEBF /* AutocompleteTextfieldSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AutocompleteTextfieldSwift.app; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | F96E31881A98DC35001DCEBF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 38 | F96E31901A98DC36001DCEBF /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 39 | F96E31991A98DC36001DCEBF /* AutocompleteTextfieldSwiftTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AutocompleteTextfieldSwiftTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 40 | F96E319E1A98DC36001DCEBF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | F96E319F1A98DC36001DCEBF /* AutocompleteTextfieldSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutocompleteTextfieldSwiftTests.swift; sourceTree = ""; }; 42 | F96E31B11A98DCA3001DCEBF /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 43 | F96E31B21A98DCA3001DCEBF /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 44 | F99A8A341A99ACA700DFD19D /* MapKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MapKit.framework; path = System/Library/Frameworks/MapKit.framework; sourceTree = SDKROOT; }; 45 | F99A8A361A99ACAB00DFD19D /* CoreLocation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreLocation.framework; path = System/Library/Frameworks/CoreLocation.framework; sourceTree = SDKROOT; }; 46 | F99A8A3B1A99ADAF00DFD19D /* MKMapViewExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MKMapViewExtension.swift; sourceTree = ""; }; 47 | F99A8A411A99CEF500DFD19D /* Location.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = ""; }; 48 | F9DD71CE1CA3F20200B17E74 /* AutoCompleteTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutoCompleteTextField.swift; sourceTree = ""; }; 49 | /* End PBXFileReference section */ 50 | 51 | /* Begin PBXFrameworksBuildPhase section */ 52 | F96E31811A98DC35001DCEBF /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | F99A8A371A99ACAB00DFD19D /* CoreLocation.framework in Frameworks */, 57 | F99A8A351A99ACA700DFD19D /* MapKit.framework in Frameworks */, 58 | ); 59 | runOnlyForDeploymentPostprocessing = 0; 60 | }; 61 | F96E31961A98DC36001DCEBF /* Frameworks */ = { 62 | isa = PBXFrameworksBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | ); 66 | runOnlyForDeploymentPostprocessing = 0; 67 | }; 68 | /* End PBXFrameworksBuildPhase section */ 69 | 70 | /* Begin PBXGroup section */ 71 | F96E317B1A98DC35001DCEBF = { 72 | isa = PBXGroup; 73 | children = ( 74 | F99A8A361A99ACAB00DFD19D /* CoreLocation.framework */, 75 | F99A8A341A99ACA700DFD19D /* MapKit.framework */, 76 | F96E31861A98DC35001DCEBF /* AutocompleteTextfieldSwift */, 77 | F96E319C1A98DC36001DCEBF /* AutocompleteTextfieldSwiftTests */, 78 | F96E31851A98DC35001DCEBF /* Products */, 79 | ); 80 | sourceTree = ""; 81 | }; 82 | F96E31851A98DC35001DCEBF /* Products */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | F96E31841A98DC35001DCEBF /* AutocompleteTextfieldSwift.app */, 86 | F96E31991A98DC36001DCEBF /* AutocompleteTextfieldSwiftTests.xctest */, 87 | ); 88 | name = Products; 89 | sourceTree = ""; 90 | }; 91 | F96E31861A98DC35001DCEBF /* AutocompleteTextfieldSwift */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | F9DD71CD1CA3F20200B17E74 /* AutocompleteTextField */, 95 | F99A8A381A99AD4300DFD19D /* Helpers */, 96 | F96E31B01A98DCA3001DCEBF /* Controllers */, 97 | F96E31B31A98DCA3001DCEBF /* Views */, 98 | F96E31901A98DC36001DCEBF /* Images.xcassets */, 99 | F96E31871A98DC35001DCEBF /* Supporting Files */, 100 | ); 101 | path = AutocompleteTextfieldSwift; 102 | sourceTree = ""; 103 | }; 104 | F96E31871A98DC35001DCEBF /* Supporting Files */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | F96E31881A98DC35001DCEBF /* Info.plist */, 108 | ); 109 | name = "Supporting Files"; 110 | sourceTree = ""; 111 | }; 112 | F96E319C1A98DC36001DCEBF /* AutocompleteTextfieldSwiftTests */ = { 113 | isa = PBXGroup; 114 | children = ( 115 | F96E319F1A98DC36001DCEBF /* AutocompleteTextfieldSwiftTests.swift */, 116 | F96E319D1A98DC36001DCEBF /* Supporting Files */, 117 | ); 118 | path = AutocompleteTextfieldSwiftTests; 119 | sourceTree = ""; 120 | }; 121 | F96E319D1A98DC36001DCEBF /* Supporting Files */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | F96E319E1A98DC36001DCEBF /* Info.plist */, 125 | ); 126 | name = "Supporting Files"; 127 | sourceTree = ""; 128 | }; 129 | F96E31B01A98DCA3001DCEBF /* Controllers */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | F96E31B11A98DCA3001DCEBF /* AppDelegate.swift */, 133 | F96E31B21A98DCA3001DCEBF /* ViewController.swift */, 134 | ); 135 | path = Controllers; 136 | sourceTree = ""; 137 | }; 138 | F96E31B31A98DCA3001DCEBF /* Views */ = { 139 | isa = PBXGroup; 140 | children = ( 141 | F905D60B1B419684009DA356 /* LaunchScreen.xib */, 142 | F905D60D1B419684009DA356 /* Main.storyboard */, 143 | ); 144 | path = Views; 145 | sourceTree = ""; 146 | }; 147 | F99A8A381A99AD4300DFD19D /* Helpers */ = { 148 | isa = PBXGroup; 149 | children = ( 150 | F99A8A3B1A99ADAF00DFD19D /* MKMapViewExtension.swift */, 151 | F99A8A411A99CEF500DFD19D /* Location.swift */, 152 | ); 153 | path = Helpers; 154 | sourceTree = ""; 155 | }; 156 | F9DD71CD1CA3F20200B17E74 /* AutocompleteTextField */ = { 157 | isa = PBXGroup; 158 | children = ( 159 | F9DD71CE1CA3F20200B17E74 /* AutoCompleteTextField.swift */, 160 | ); 161 | path = AutocompleteTextField; 162 | sourceTree = ""; 163 | }; 164 | /* End PBXGroup section */ 165 | 166 | /* Begin PBXNativeTarget section */ 167 | F96E31831A98DC35001DCEBF /* AutocompleteTextfieldSwift */ = { 168 | isa = PBXNativeTarget; 169 | buildConfigurationList = F96E31A31A98DC36001DCEBF /* Build configuration list for PBXNativeTarget "AutocompleteTextfieldSwift" */; 170 | buildPhases = ( 171 | F96E31801A98DC35001DCEBF /* Sources */, 172 | F96E31811A98DC35001DCEBF /* Frameworks */, 173 | F96E31821A98DC35001DCEBF /* Resources */, 174 | ); 175 | buildRules = ( 176 | ); 177 | dependencies = ( 178 | ); 179 | name = AutocompleteTextfieldSwift; 180 | productName = AutocompleteTextfieldSwift; 181 | productReference = F96E31841A98DC35001DCEBF /* AutocompleteTextfieldSwift.app */; 182 | productType = "com.apple.product-type.application"; 183 | }; 184 | F96E31981A98DC36001DCEBF /* AutocompleteTextfieldSwiftTests */ = { 185 | isa = PBXNativeTarget; 186 | buildConfigurationList = F96E31A61A98DC36001DCEBF /* Build configuration list for PBXNativeTarget "AutocompleteTextfieldSwiftTests" */; 187 | buildPhases = ( 188 | F96E31951A98DC36001DCEBF /* Sources */, 189 | F96E31961A98DC36001DCEBF /* Frameworks */, 190 | F96E31971A98DC36001DCEBF /* Resources */, 191 | ); 192 | buildRules = ( 193 | ); 194 | dependencies = ( 195 | F96E319B1A98DC36001DCEBF /* PBXTargetDependency */, 196 | ); 197 | name = AutocompleteTextfieldSwiftTests; 198 | productName = AutocompleteTextfieldSwiftTests; 199 | productReference = F96E31991A98DC36001DCEBF /* AutocompleteTextfieldSwiftTests.xctest */; 200 | productType = "com.apple.product-type.bundle.unit-test"; 201 | }; 202 | /* End PBXNativeTarget section */ 203 | 204 | /* Begin PBXProject section */ 205 | F96E317C1A98DC35001DCEBF /* Project object */ = { 206 | isa = PBXProject; 207 | attributes = { 208 | LastSwiftMigration = 0710; 209 | LastSwiftUpdateCheck = 0700; 210 | LastUpgradeCheck = 0710; 211 | ORGANIZATIONNAME = mnbayan; 212 | TargetAttributes = { 213 | F96E31831A98DC35001DCEBF = { 214 | CreatedOnToolsVersion = 6.1; 215 | }; 216 | F96E31981A98DC36001DCEBF = { 217 | CreatedOnToolsVersion = 6.1; 218 | TestTargetID = F96E31831A98DC35001DCEBF; 219 | }; 220 | }; 221 | }; 222 | buildConfigurationList = F96E317F1A98DC35001DCEBF /* Build configuration list for PBXProject "AutocompleteTextfieldSwift" */; 223 | compatibilityVersion = "Xcode 3.2"; 224 | developmentRegion = English; 225 | hasScannedForEncodings = 0; 226 | knownRegions = ( 227 | en, 228 | Base, 229 | ); 230 | mainGroup = F96E317B1A98DC35001DCEBF; 231 | productRefGroup = F96E31851A98DC35001DCEBF /* Products */; 232 | projectDirPath = ""; 233 | projectRoot = ""; 234 | targets = ( 235 | F96E31831A98DC35001DCEBF /* AutocompleteTextfieldSwift */, 236 | F96E31981A98DC36001DCEBF /* AutocompleteTextfieldSwiftTests */, 237 | ); 238 | }; 239 | /* End PBXProject section */ 240 | 241 | /* Begin PBXResourcesBuildPhase section */ 242 | F96E31821A98DC35001DCEBF /* Resources */ = { 243 | isa = PBXResourcesBuildPhase; 244 | buildActionMask = 2147483647; 245 | files = ( 246 | F905D6101B419684009DA356 /* Main.storyboard in Resources */, 247 | F905D60F1B419684009DA356 /* LaunchScreen.xib in Resources */, 248 | F96E31911A98DC36001DCEBF /* Images.xcassets in Resources */, 249 | ); 250 | runOnlyForDeploymentPostprocessing = 0; 251 | }; 252 | F96E31971A98DC36001DCEBF /* Resources */ = { 253 | isa = PBXResourcesBuildPhase; 254 | buildActionMask = 2147483647; 255 | files = ( 256 | ); 257 | runOnlyForDeploymentPostprocessing = 0; 258 | }; 259 | /* End PBXResourcesBuildPhase section */ 260 | 261 | /* Begin PBXSourcesBuildPhase section */ 262 | F96E31801A98DC35001DCEBF /* Sources */ = { 263 | isa = PBXSourcesBuildPhase; 264 | buildActionMask = 2147483647; 265 | files = ( 266 | F99A8A3C1A99ADAF00DFD19D /* MKMapViewExtension.swift in Sources */, 267 | F9DD71CF1CA3F20200B17E74 /* AutoCompleteTextField.swift in Sources */, 268 | F96E31B51A98DCA3001DCEBF /* ViewController.swift in Sources */, 269 | F96E31B41A98DCA3001DCEBF /* AppDelegate.swift in Sources */, 270 | F99A8A421A99CEF500DFD19D /* Location.swift in Sources */, 271 | ); 272 | runOnlyForDeploymentPostprocessing = 0; 273 | }; 274 | F96E31951A98DC36001DCEBF /* Sources */ = { 275 | isa = PBXSourcesBuildPhase; 276 | buildActionMask = 2147483647; 277 | files = ( 278 | F96E31A01A98DC36001DCEBF /* AutocompleteTextfieldSwiftTests.swift in Sources */, 279 | ); 280 | runOnlyForDeploymentPostprocessing = 0; 281 | }; 282 | /* End PBXSourcesBuildPhase section */ 283 | 284 | /* Begin PBXTargetDependency section */ 285 | F96E319B1A98DC36001DCEBF /* PBXTargetDependency */ = { 286 | isa = PBXTargetDependency; 287 | target = F96E31831A98DC35001DCEBF /* AutocompleteTextfieldSwift */; 288 | targetProxy = F96E319A1A98DC36001DCEBF /* PBXContainerItemProxy */; 289 | }; 290 | /* End PBXTargetDependency section */ 291 | 292 | /* Begin PBXVariantGroup section */ 293 | F905D60B1B419684009DA356 /* LaunchScreen.xib */ = { 294 | isa = PBXVariantGroup; 295 | children = ( 296 | F905D60C1B419684009DA356 /* Base */, 297 | ); 298 | name = LaunchScreen.xib; 299 | sourceTree = ""; 300 | }; 301 | F905D60D1B419684009DA356 /* Main.storyboard */ = { 302 | isa = PBXVariantGroup; 303 | children = ( 304 | F905D60E1B419684009DA356 /* Base */, 305 | ); 306 | name = Main.storyboard; 307 | sourceTree = ""; 308 | }; 309 | /* End PBXVariantGroup section */ 310 | 311 | /* Begin XCBuildConfiguration section */ 312 | F96E31A11A98DC36001DCEBF /* Debug */ = { 313 | isa = XCBuildConfiguration; 314 | buildSettings = { 315 | ALWAYS_SEARCH_USER_PATHS = NO; 316 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 317 | CLANG_CXX_LIBRARY = "libc++"; 318 | CLANG_ENABLE_MODULES = YES; 319 | CLANG_ENABLE_OBJC_ARC = YES; 320 | CLANG_WARN_BOOL_CONVERSION = YES; 321 | CLANG_WARN_CONSTANT_CONVERSION = YES; 322 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 323 | CLANG_WARN_EMPTY_BODY = YES; 324 | CLANG_WARN_ENUM_CONVERSION = YES; 325 | CLANG_WARN_INT_CONVERSION = YES; 326 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 327 | CLANG_WARN_UNREACHABLE_CODE = YES; 328 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 329 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 330 | COPY_PHASE_STRIP = NO; 331 | ENABLE_STRICT_OBJC_MSGSEND = YES; 332 | ENABLE_TESTABILITY = YES; 333 | GCC_C_LANGUAGE_STANDARD = gnu99; 334 | GCC_DYNAMIC_NO_PIC = NO; 335 | GCC_OPTIMIZATION_LEVEL = 0; 336 | GCC_PREPROCESSOR_DEFINITIONS = ( 337 | "DEBUG=1", 338 | "$(inherited)", 339 | ); 340 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 341 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 342 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 343 | GCC_WARN_UNDECLARED_SELECTOR = YES; 344 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 345 | GCC_WARN_UNUSED_FUNCTION = YES; 346 | GCC_WARN_UNUSED_VARIABLE = YES; 347 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 348 | MTL_ENABLE_DEBUG_INFO = YES; 349 | ONLY_ACTIVE_ARCH = YES; 350 | SDKROOT = iphoneos; 351 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 352 | TARGETED_DEVICE_FAMILY = "1,2"; 353 | }; 354 | name = Debug; 355 | }; 356 | F96E31A21A98DC36001DCEBF /* Release */ = { 357 | isa = XCBuildConfiguration; 358 | buildSettings = { 359 | ALWAYS_SEARCH_USER_PATHS = NO; 360 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 361 | CLANG_CXX_LIBRARY = "libc++"; 362 | CLANG_ENABLE_MODULES = YES; 363 | CLANG_ENABLE_OBJC_ARC = YES; 364 | CLANG_WARN_BOOL_CONVERSION = YES; 365 | CLANG_WARN_CONSTANT_CONVERSION = YES; 366 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 367 | CLANG_WARN_EMPTY_BODY = YES; 368 | CLANG_WARN_ENUM_CONVERSION = YES; 369 | CLANG_WARN_INT_CONVERSION = YES; 370 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 371 | CLANG_WARN_UNREACHABLE_CODE = YES; 372 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 373 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 374 | COPY_PHASE_STRIP = YES; 375 | ENABLE_NS_ASSERTIONS = NO; 376 | ENABLE_STRICT_OBJC_MSGSEND = YES; 377 | GCC_C_LANGUAGE_STANDARD = gnu99; 378 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 379 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 380 | GCC_WARN_UNDECLARED_SELECTOR = YES; 381 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 382 | GCC_WARN_UNUSED_FUNCTION = YES; 383 | GCC_WARN_UNUSED_VARIABLE = YES; 384 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 385 | MTL_ENABLE_DEBUG_INFO = NO; 386 | SDKROOT = iphoneos; 387 | TARGETED_DEVICE_FAMILY = "1,2"; 388 | VALIDATE_PRODUCT = YES; 389 | }; 390 | name = Release; 391 | }; 392 | F96E31A41A98DC36001DCEBF /* Debug */ = { 393 | isa = XCBuildConfiguration; 394 | buildSettings = { 395 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 396 | CODE_SIGN_IDENTITY = "iPhone Developer"; 397 | ENABLE_BITCODE = NO; 398 | INFOPLIST_FILE = AutocompleteTextfieldSwift/Info.plist; 399 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 400 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 401 | PRODUCT_BUNDLE_IDENTIFIER = mnbayan.AutocompleteTextfieldSwift; 402 | PRODUCT_NAME = "$(TARGET_NAME)"; 403 | TARGETED_DEVICE_FAMILY = "1,2"; 404 | }; 405 | name = Debug; 406 | }; 407 | F96E31A51A98DC36001DCEBF /* Release */ = { 408 | isa = XCBuildConfiguration; 409 | buildSettings = { 410 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 411 | CODE_SIGN_IDENTITY = "iPhone Developer"; 412 | ENABLE_BITCODE = NO; 413 | INFOPLIST_FILE = AutocompleteTextfieldSwift/Info.plist; 414 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 415 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 416 | PRODUCT_BUNDLE_IDENTIFIER = mnbayan.AutocompleteTextfieldSwift; 417 | PRODUCT_NAME = "$(TARGET_NAME)"; 418 | TARGETED_DEVICE_FAMILY = "1,2"; 419 | }; 420 | name = Release; 421 | }; 422 | F96E31A71A98DC36001DCEBF /* Debug */ = { 423 | isa = XCBuildConfiguration; 424 | buildSettings = { 425 | BUNDLE_LOADER = "$(TEST_HOST)"; 426 | FRAMEWORK_SEARCH_PATHS = ( 427 | "$(SDKROOT)/Developer/Library/Frameworks", 428 | "$(inherited)", 429 | ); 430 | GCC_PREPROCESSOR_DEFINITIONS = ( 431 | "DEBUG=1", 432 | "$(inherited)", 433 | ); 434 | INFOPLIST_FILE = AutocompleteTextfieldSwiftTests/Info.plist; 435 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 436 | PRODUCT_BUNDLE_IDENTIFIER = "codefun.$(PRODUCT_NAME:rfc1034identifier)"; 437 | PRODUCT_NAME = "$(TARGET_NAME)"; 438 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AutocompleteTextfieldSwift.app/AutocompleteTextfieldSwift"; 439 | }; 440 | name = Debug; 441 | }; 442 | F96E31A81A98DC36001DCEBF /* Release */ = { 443 | isa = XCBuildConfiguration; 444 | buildSettings = { 445 | BUNDLE_LOADER = "$(TEST_HOST)"; 446 | FRAMEWORK_SEARCH_PATHS = ( 447 | "$(SDKROOT)/Developer/Library/Frameworks", 448 | "$(inherited)", 449 | ); 450 | INFOPLIST_FILE = AutocompleteTextfieldSwiftTests/Info.plist; 451 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 452 | PRODUCT_BUNDLE_IDENTIFIER = "codefun.$(PRODUCT_NAME:rfc1034identifier)"; 453 | PRODUCT_NAME = "$(TARGET_NAME)"; 454 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AutocompleteTextfieldSwift.app/AutocompleteTextfieldSwift"; 455 | }; 456 | name = Release; 457 | }; 458 | /* End XCBuildConfiguration section */ 459 | 460 | /* Begin XCConfigurationList section */ 461 | F96E317F1A98DC35001DCEBF /* Build configuration list for PBXProject "AutocompleteTextfieldSwift" */ = { 462 | isa = XCConfigurationList; 463 | buildConfigurations = ( 464 | F96E31A11A98DC36001DCEBF /* Debug */, 465 | F96E31A21A98DC36001DCEBF /* Release */, 466 | ); 467 | defaultConfigurationIsVisible = 0; 468 | defaultConfigurationName = Release; 469 | }; 470 | F96E31A31A98DC36001DCEBF /* Build configuration list for PBXNativeTarget "AutocompleteTextfieldSwift" */ = { 471 | isa = XCConfigurationList; 472 | buildConfigurations = ( 473 | F96E31A41A98DC36001DCEBF /* Debug */, 474 | F96E31A51A98DC36001DCEBF /* Release */, 475 | ); 476 | defaultConfigurationIsVisible = 0; 477 | defaultConfigurationName = Release; 478 | }; 479 | F96E31A61A98DC36001DCEBF /* Build configuration list for PBXNativeTarget "AutocompleteTextfieldSwiftTests" */ = { 480 | isa = XCConfigurationList; 481 | buildConfigurations = ( 482 | F96E31A71A98DC36001DCEBF /* Debug */, 483 | F96E31A81A98DC36001DCEBF /* Release */, 484 | ); 485 | defaultConfigurationIsVisible = 0; 486 | defaultConfigurationName = Release; 487 | }; 488 | /* End XCConfigurationList section */ 489 | }; 490 | rootObject = F96E317C1A98DC35001DCEBF /* Project object */; 491 | } 492 | -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift.xcodeproj/project.xcworkspace/xcshareddata/AutocompleteTextfieldSwift.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | BB8704C5-244E-4374-A4E4-E64B9E48C8C5 9 | IDESourceControlProjectName 10 | project 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 1D5E9A099DEFDBEC131C996C72A49F371BBEF376 14 | https://github.com/mnbayan/AutocompleteTextfieldSwift.git 15 | 16 | IDESourceControlProjectPath 17 | AutocompleteTextfieldSwift.xcodeproj/project.xcworkspace 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 1D5E9A099DEFDBEC131C996C72A49F371BBEF376 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/mnbayan/AutocompleteTextfieldSwift.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 1D5E9A099DEFDBEC131C996C72A49F371BBEF376 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 1D5E9A099DEFDBEC131C996C72A49F371BBEF376 36 | IDESourceControlWCCName 37 | AutocompleteTextfieldSwift 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift.xcodeproj/project.xcworkspace/xcshareddata/AutocompleteTextfieldSwift.xcscmblueprint: -------------------------------------------------------------------------------- 1 | { 2 | "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "1D5E9A099DEFDBEC131C996C72A49F371BBEF376", 3 | "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { 4 | 5 | }, 6 | "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { 7 | "1D5E9A099DEFDBEC131C996C72A49F371BBEF376" : 0, 8 | "31B7D9808F0765E7D6BE15F22F935774E0FB0523" : 0 9 | }, 10 | "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "BB8704C5-244E-4374-A4E4-E64B9E48C8C5", 11 | "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { 12 | "1D5E9A099DEFDBEC131C996C72A49F371BBEF376" : "AutocompleteTextfieldSwift\/", 13 | "31B7D9808F0765E7D6BE15F22F935774E0FB0523" : "..\/Work\/Stratpoint\/stratpoint_globepeekaboo" 14 | }, 15 | "DVTSourceControlWorkspaceBlueprintNameKey" : "AutocompleteTextfieldSwift", 16 | "DVTSourceControlWorkspaceBlueprintVersion" : 204, 17 | "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "AutocompleteTextfieldSwift.xcodeproj", 18 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ 19 | { 20 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/mnbayan\/AutocompleteTextfieldSwift.git", 21 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 22 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "1D5E9A099DEFDBEC131C996C72A49F371BBEF376" 23 | }, 24 | { 25 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/stratpoint.unfuddle.com\/git\/stratpoint_globepeekaboo\/", 26 | "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", 27 | "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "31B7D9808F0765E7D6BE15F22F935774E0FB0523" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift.xcodeproj/project.xcworkspace/xcuserdata/Mylene.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mnbayan/AutocompleteTextfieldSwift/2435915feda8dbd5e4793452b5b49db28ebb24e8/AutocompleteTextfieldSwift.xcodeproj/project.xcworkspace/xcuserdata/Mylene.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mnbayan/AutocompleteTextfieldSwift/2435915feda8dbd5e4793452b5b49db28ebb24e8/AutocompleteTextfieldSwift.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift.xcodeproj/xcuserdata/Mylene.xcuserdatad/xcschemes/AutocompleteTextfieldSwift.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 68 | 78 | 80 | 86 | 87 | 88 | 89 | 90 | 91 | 97 | 99 | 105 | 106 | 107 | 108 | 110 | 111 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift/AutoCompleteTextField/AutoCompleteTextField.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AutoCompleteTextField.swift 3 | // AutocompleteTextfieldSwift 4 | // 5 | // Created by Mylene Bayan on 6/13/15. 6 | // Copyright (c) 2015 mnbayan. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | public class AutoCompleteTextField:UITextField { 13 | /// Manages the instance of tableview 14 | private var autoCompleteTableView:UITableView? 15 | /// Holds the collection of attributed strings 16 | private lazy var attributedAutoCompleteStrings = [NSAttributedString]() 17 | /// Handles user selection action on autocomplete table view 18 | public var onSelect:(String, NSIndexPath)->() = {_,_ in} 19 | /// Handles textfield's textchanged 20 | public var onTextChange:(String)->() = {_ in} 21 | 22 | /// Font for the text suggestions 23 | public var autoCompleteTextFont = UIFont.systemFontOfSize(12) 24 | /// Color of the text suggestions 25 | public var autoCompleteTextColor = UIColor.blackColor() 26 | /// Used to set the height of cell for each suggestions 27 | public var autoCompleteCellHeight:CGFloat = 44.0 28 | /// The maximum visible suggestion 29 | public var maximumAutoCompleteCount = 3 30 | /// Used to set your own preferred separator inset 31 | public var autoCompleteSeparatorInset = UIEdgeInsetsZero 32 | /// Shows autocomplete text with formatting 33 | public var enableAttributedText = false 34 | /// User Defined Attributes 35 | public var autoCompleteAttributes:[String:AnyObject]? 36 | /// Hides autocomplete tableview after selecting a suggestion 37 | public var hidesWhenSelected = true 38 | /// Hides autocomplete tableview when the textfield is empty 39 | public var hidesWhenEmpty:Bool?{ 40 | didSet{ 41 | assert(hidesWhenEmpty != nil, "hideWhenEmpty cannot be set to nil") 42 | autoCompleteTableView?.hidden = hidesWhenEmpty! 43 | } 44 | } 45 | /// The table view height 46 | public var autoCompleteTableHeight:CGFloat?{ 47 | didSet{ 48 | redrawTable() 49 | } 50 | } 51 | /// The strings to be shown on as suggestions, setting the value of this automatically reload the tableview 52 | public var autoCompleteStrings:[String]?{ 53 | didSet{ reload() } 54 | } 55 | 56 | 57 | //MARK: - Init 58 | override init(frame: CGRect) { 59 | super.init(frame: frame) 60 | commonInit() 61 | setupAutocompleteTable(superview!) 62 | } 63 | 64 | public required init?(coder aDecoder: NSCoder) { 65 | super.init(coder: aDecoder) 66 | } 67 | 68 | public override func awakeFromNib() { 69 | super.awakeFromNib() 70 | commonInit() 71 | setupAutocompleteTable(superview!) 72 | } 73 | 74 | public override func willMoveToSuperview(newSuperview: UIView?) { 75 | super.willMoveToSuperview(newSuperview) 76 | commonInit() 77 | setupAutocompleteTable(newSuperview!) 78 | } 79 | 80 | private func commonInit(){ 81 | hidesWhenEmpty = true 82 | autoCompleteAttributes = [NSForegroundColorAttributeName:UIColor.blackColor()] 83 | autoCompleteAttributes![NSFontAttributeName] = UIFont.boldSystemFontOfSize(12) 84 | self.clearButtonMode = .Always 85 | self.addTarget(self, action: "textFieldDidChange", forControlEvents: .EditingChanged) 86 | self.addTarget(self, action: "textFieldDidEndEditing", forControlEvents: .EditingDidEnd) 87 | } 88 | 89 | private func setupAutocompleteTable(view:UIView){ 90 | let screenSize = UIScreen.mainScreen().bounds.size 91 | let tableView = UITableView(frame: CGRectMake(self.frame.origin.x, self.frame.origin.y + CGRectGetHeight(self.frame), screenSize.width - (self.frame.origin.x * 2), 30.0)) 92 | tableView.dataSource = self 93 | tableView.delegate = self 94 | tableView.rowHeight = autoCompleteCellHeight 95 | tableView.hidden = hidesWhenEmpty ?? true 96 | view.addSubview(tableView) 97 | autoCompleteTableView = tableView 98 | 99 | autoCompleteTableHeight = 100.0 100 | } 101 | 102 | private func redrawTable(){ 103 | if let autoCompleteTableView = autoCompleteTableView, let autoCompleteTableHeight = autoCompleteTableHeight { 104 | var newFrame = autoCompleteTableView.frame 105 | newFrame.size.height = autoCompleteTableHeight 106 | autoCompleteTableView.frame = newFrame 107 | } 108 | } 109 | 110 | //MARK: - Private Methods 111 | private func reload(){ 112 | if enableAttributedText{ 113 | let attrs = [NSForegroundColorAttributeName:autoCompleteTextColor, NSFontAttributeName:autoCompleteTextFont] 114 | 115 | if attributedAutoCompleteStrings.count > 0 { 116 | attributedAutoCompleteStrings.removeAll(keepCapacity: false) 117 | } 118 | 119 | if let autoCompleteStrings = autoCompleteStrings, let autoCompleteAttributes = autoCompleteAttributes { 120 | for i in 0.. Void in 140 | self.autoCompleteTableView?.hidden = self.hidesWhenEmpty! ? self.text!.isEmpty : false 141 | }) 142 | } 143 | 144 | func textFieldDidEndEditing() { 145 | autoCompleteTableView?.hidden = true 146 | } 147 | } 148 | 149 | //MARK: - UITableViewDataSource - UITableViewDelegate 150 | extension AutoCompleteTextField: UITableViewDataSource, UITableViewDelegate { 151 | 152 | public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 153 | return autoCompleteStrings != nil ? (autoCompleteStrings!.count > maximumAutoCompleteCount ? maximumAutoCompleteCount : autoCompleteStrings!.count) : 0 154 | } 155 | 156 | public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 157 | let cellIdentifier = "autocompleteCellIdentifier" 158 | var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) 159 | if cell == nil{ 160 | cell = UITableViewCell(style: .Default, reuseIdentifier: cellIdentifier) 161 | } 162 | 163 | if enableAttributedText{ 164 | cell?.textLabel?.attributedText = attributedAutoCompleteStrings[indexPath.row] 165 | } 166 | else{ 167 | cell?.textLabel?.font = autoCompleteTextFont 168 | cell?.textLabel?.textColor = autoCompleteTextColor 169 | cell?.textLabel?.text = autoCompleteStrings![indexPath.row] 170 | } 171 | 172 | cell?.contentView.gestureRecognizers = nil 173 | return cell! 174 | } 175 | 176 | public func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 177 | let cell = tableView.cellForRowAtIndexPath(indexPath) 178 | 179 | if let selectedText = cell?.textLabel?.text { 180 | self.text = selectedText 181 | onSelect(selectedText, indexPath) 182 | } 183 | 184 | dispatch_async(dispatch_get_main_queue(), { () -> Void in 185 | tableView.hidden = self.hidesWhenSelected 186 | }) 187 | } 188 | 189 | public func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { 190 | if cell.respondsToSelector("setSeparatorInset:"){ 191 | cell.separatorInset = autoCompleteSeparatorInset 192 | } 193 | if cell.respondsToSelector("setPreservesSuperviewLayoutMargins:"){ 194 | cell.preservesSuperviewLayoutMargins = false 195 | } 196 | if cell.respondsToSelector("setLayoutMargins:"){ 197 | cell.layoutMargins = autoCompleteSeparatorInset 198 | } 199 | } 200 | 201 | public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 202 | return autoCompleteCellHeight 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 22 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift/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 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift/Controllers/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // AutocompleteTextfieldSwift 4 | // 5 | // Created by Mylene Bayan on 2/21/15. 6 | // Copyright (c) 2015 mnbayan. 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: [NSObject: AnyObject]?) -> 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 throttle down OpenGL ES frame rates. 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 inactive 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 | -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift/Controllers/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // AutocompleteTextfieldSwift 4 | // 5 | // Created by Mylene Bayan on 2/21/15. 6 | // Copyright (c) 2015 mnbayan. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import MapKit 11 | 12 | class ViewController: UIViewController { 13 | 14 | @IBOutlet weak var mapView: MKMapView! 15 | @IBOutlet weak var autocompleteTextfield: AutoCompleteTextField! 16 | 17 | private var responseData:NSMutableData? 18 | private var selectedPointAnnotation:MKPointAnnotation? 19 | private var dataTask:NSURLSessionDataTask? 20 | 21 | private let googleMapsKey = "AIzaSyDg2tlPcoqxx2Q2rfjhsAKS-9j0n3JA_a4" 22 | private let baseURLString = "https://maps.googleapis.com/maps/api/place/autocomplete/json" 23 | 24 | override func viewDidLoad() { 25 | super.viewDidLoad() 26 | // Do any additional setup after loading the view, typically from a nib. 27 | configureTextField() 28 | handleTextFieldInterfaces() 29 | } 30 | 31 | override func didReceiveMemoryWarning() { 32 | super.didReceiveMemoryWarning() 33 | // Dispose of any resources that can be recreated. 34 | } 35 | 36 | private func configureTextField(){ 37 | autocompleteTextfield.autoCompleteTextColor = UIColor(red: 128.0/255.0, green: 128.0/255.0, blue: 128.0/255.0, alpha: 1.0) 38 | autocompleteTextfield.autoCompleteTextFont = UIFont(name: "HelveticaNeue-Light", size: 12.0)! 39 | autocompleteTextfield.autoCompleteCellHeight = 35.0 40 | autocompleteTextfield.maximumAutoCompleteCount = 20 41 | autocompleteTextfield.hidesWhenSelected = true 42 | autocompleteTextfield.hidesWhenEmpty = true 43 | autocompleteTextfield.enableAttributedText = true 44 | var attributes = [String:AnyObject]() 45 | attributes[NSForegroundColorAttributeName] = UIColor.blackColor() 46 | attributes[NSFontAttributeName] = UIFont(name: "HelveticaNeue-Bold", size: 12.0) 47 | autocompleteTextfield.autoCompleteAttributes = attributes 48 | } 49 | 50 | private func handleTextFieldInterfaces(){ 51 | autocompleteTextfield.onTextChange = {[weak self] text in 52 | if !text.isEmpty{ 53 | if let dataTask = self?.dataTask { 54 | dataTask.cancel() 55 | } 56 | self?.fetchAutocompletePlaces(text) 57 | } 58 | } 59 | 60 | autocompleteTextfield.onSelect = {[weak self] text, indexpath in 61 | Location.geocodeAddressString(text, completion: { (placemark, error) -> Void in 62 | if let coordinate = placemark?.location?.coordinate { 63 | self?.addAnnotation(coordinate, address: text) 64 | self?.mapView.setCenterCoordinate(coordinate, zoomLevel: 12, animated: true) 65 | } 66 | }) 67 | } 68 | } 69 | 70 | //MARK: - Private Methods 71 | private func addAnnotation(coordinate:CLLocationCoordinate2D, address:String?){ 72 | if let annotation = selectedPointAnnotation{ 73 | mapView.removeAnnotation(annotation) 74 | } 75 | 76 | selectedPointAnnotation = MKPointAnnotation() 77 | selectedPointAnnotation!.coordinate = coordinate 78 | selectedPointAnnotation!.title = address 79 | mapView.addAnnotation(selectedPointAnnotation!) 80 | } 81 | 82 | private func fetchAutocompletePlaces(keyword:String) { 83 | let urlString = "\(baseURLString)?key=\(googleMapsKey)&input=\(keyword)" 84 | let s = NSCharacterSet.URLQueryAllowedCharacterSet().mutableCopy() as! NSMutableCharacterSet 85 | s.addCharactersInString("+&") 86 | if let encodedString = urlString.stringByAddingPercentEncodingWithAllowedCharacters(s) { 87 | if let url = NSURL(string: encodedString) { 88 | let request = NSURLRequest(URL: url) 89 | dataTask = NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in 90 | if let data = data{ 91 | 92 | do{ 93 | let result = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments) 94 | 95 | if let status = result["status"] as? String{ 96 | if status == "OK"{ 97 | if let predictions = result["predictions"] as? NSArray{ 98 | var locations = [String]() 99 | for dict in predictions as! [NSDictionary]{ 100 | locations.append(dict["description"] as! String) 101 | } 102 | dispatch_async(dispatch_get_main_queue(), { () -> Void in 103 | self.autocompleteTextfield.autoCompleteStrings = locations 104 | }) 105 | return 106 | } 107 | } 108 | } 109 | dispatch_async(dispatch_get_main_queue(), { () -> Void in 110 | self.autocompleteTextfield.autoCompleteStrings = nil 111 | }) 112 | } 113 | catch let error as NSError{ 114 | print("Error: \(error.localizedDescription)") 115 | } 116 | } 117 | }) 118 | dataTask?.resume() 119 | } 120 | } 121 | } 122 | } 123 | 124 | 125 | -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift/Helpers/Location.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Location.swift 3 | // AutocompleteTextfieldSwift 4 | // 5 | // Created by Mylene Bayan on 2/22/15. 6 | // Copyright (c) 2015 mnbayan. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import CoreLocation 11 | 12 | class Location{ 13 | 14 | class func geocodeAddressString(address:String, completion:(placemark:CLPlacemark?, error:NSError?)->Void){ 15 | let geocoder = CLGeocoder() 16 | geocoder.geocodeAddressString(address, completionHandler: { (placemarks, error) -> Void in 17 | if error == nil{ 18 | if placemarks?.count > 0{ 19 | completion(placemark: (placemarks?[0]), error: error) 20 | } 21 | } 22 | else{ 23 | completion(placemark: nil, error: error) 24 | } 25 | }) 26 | } 27 | 28 | class func reverseGeocodeLocation(location:CLLocation,completion:(placemark:CLPlacemark?, error:NSError?)->Void){ 29 | let geoCoder = CLGeocoder() 30 | geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in 31 | if let err = error{ 32 | print("Error Reverse Geocoding Location: \(err.localizedDescription)") 33 | completion(placemark: nil, error: error) 34 | return 35 | } 36 | completion(placemark: placemarks?[0], error: nil) 37 | 38 | }) 39 | } 40 | 41 | class func addressFromPlacemark(placemark:CLPlacemark)->String{ 42 | var address = "" 43 | 44 | if let name = placemark.addressDictionary?["Name"] as? String { 45 | address = constructAddressString(address, newString: name) 46 | } 47 | 48 | if let city = placemark.addressDictionary?["City"] as? String { 49 | address = constructAddressString(address, newString: city) 50 | } 51 | 52 | if let state = placemark.addressDictionary?["State"] as? String { 53 | address = constructAddressString(address, newString: state) 54 | } 55 | 56 | if let country = placemark.country{ 57 | address = constructAddressString(address, newString: country) 58 | } 59 | 60 | return address 61 | } 62 | 63 | private class func constructAddressString(string:String, newString:String)->String{ 64 | var address = string 65 | if !address.isEmpty{ 66 | address = address.stringByAppendingString(", \(newString)") 67 | } 68 | else{ 69 | address = address.stringByAppendingString(newString) 70 | } 71 | return address 72 | } 73 | } -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift/Helpers/MKMapViewExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MKMapViewExtension.swift 3 | // AutocompleteTextfieldSwift 4 | // 5 | // Created by Mylene Bayan on 2/22/15. 6 | // Copyright (c) 2015 mnbayan. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import MapKit 11 | 12 | 13 | let MERCATOR_OFFSET = 268435456.0 14 | let MERCATOR_RADIUS = 85445659.44705395 15 | let DEGREES = 180.0 16 | 17 | extension MKMapView{ 18 | //MARK: Map Conversion Methods 19 | private func longitudeToPixelSpaceX(longitude:Double)->Double{ 20 | return round(MERCATOR_OFFSET + MERCATOR_RADIUS * longitude * M_PI / DEGREES) 21 | } 22 | 23 | private func latitudeToPixelSpaceY(latitude:Double)->Double{ 24 | return round(MERCATOR_OFFSET - MERCATOR_RADIUS * log((1 + sin(latitude * M_PI / DEGREES)) / (1 - sin(latitude * M_PI / DEGREES))) / 2.0) 25 | } 26 | 27 | private func pixelSpaceXToLongitude(pixelX:Double)->Double{ 28 | return ((round(pixelX) - MERCATOR_OFFSET) / MERCATOR_RADIUS) * DEGREES / M_PI 29 | 30 | } 31 | 32 | private func pixelSpaceYToLatitude(pixelY:Double)->Double{ 33 | return (M_PI / 2.0 - 2.0 * atan(exp((round(pixelY) - MERCATOR_OFFSET) / MERCATOR_RADIUS))) * DEGREES / M_PI 34 | } 35 | 36 | private func coordinateSpanWithCenterCoordinate(centerCoordinate:CLLocationCoordinate2D, zoomLevel:Double)->MKCoordinateSpan{ 37 | 38 | // convert center coordiate to pixel space 39 | let centerPixelX = longitudeToPixelSpaceX(centerCoordinate.longitude) 40 | let centerPixelY = latitudeToPixelSpaceY(centerCoordinate.latitude) 41 | 42 | // determine the scale value from the zoom level 43 | let zoomExponent:Double = 20.0 - zoomLevel 44 | let zoomScale:Double = pow(2.0, zoomExponent) 45 | 46 | // scale the map’s size in pixel space 47 | let mapSizeInPixels = self.bounds.size 48 | let scaledMapWidth = Double(mapSizeInPixels.width) * zoomScale 49 | let scaledMapHeight = Double(mapSizeInPixels.height) * zoomScale 50 | 51 | // figure out the position of the top-left pixel 52 | let topLeftPixelX = centerPixelX - (scaledMapWidth / 2.0) 53 | let topLeftPixelY = centerPixelY - (scaledMapHeight / 2.0) 54 | 55 | // find delta between left and right longitudes 56 | let minLng = pixelSpaceXToLongitude(topLeftPixelX) 57 | let maxLng = pixelSpaceXToLongitude(topLeftPixelX + scaledMapWidth) 58 | let longitudeDelta = maxLng - minLng 59 | 60 | let minLat = pixelSpaceYToLatitude(topLeftPixelY) 61 | let maxLat = pixelSpaceYToLatitude(topLeftPixelY + scaledMapHeight) 62 | let latitudeDelta = -1.0 * (maxLat - minLat) 63 | 64 | return MKCoordinateSpan(latitudeDelta: latitudeDelta, longitudeDelta: longitudeDelta) 65 | } 66 | 67 | func setCenterCoordinate(centerCoordinate:CLLocationCoordinate2D, var zoomLevel:Double, animated:Bool){ 68 | // clamp large numbers to 28 69 | zoomLevel = min(zoomLevel, 28) 70 | 71 | // use the zoom level to compute the region 72 | let span = self.coordinateSpanWithCenterCoordinate(centerCoordinate, zoomLevel: zoomLevel) 73 | let region = MKCoordinateRegionMake(centerCoordinate, span) 74 | if region.center.longitude == -180.00000000{ 75 | print("Invalid Region") 76 | } 77 | else{ 78 | self.setRegion(region, animated: animated) 79 | } 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift/Images.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 | } -------------------------------------------------------------------------------- /AutocompleteTextfieldSwift/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 | 2.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 3 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 | 48 | -------------------------------------------------------------------------------- /AutocompleteTextfieldSwiftTests/AutocompleteTextfieldSwiftTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AutocompleteTextfieldSwiftTests.swift 3 | // AutocompleteTextfieldSwiftTests 4 | // 5 | // Created by Mylene Bayan on 2/21/15. 6 | // Copyright (c) 2015 mnbayan. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class AutocompleteTextfieldSwiftTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /AutocompleteTextfieldSwiftTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Mylene Bayan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutocompleteTextfieldSwift 2 | Simple and straightforward sublass of UITextfield to manage string suggestions 3 | 4 | Plain | Attributed 5 | ------------- | ------------- 6 | ![Plain](http://i.imgur.com/SvyLreh.png?1) | ![Attributed](http://i.imgur.com/qlMgLaB.png?1) 7 | 8 | 9 | ## Installation 10 | Drag AutoCompleteTextField Folder in your project 11 | 12 | ## How to use 13 | 14 | #### Customize 15 | Customize autocomplete suggestions! You can override the provided properties to create your desired appearance. 16 | Properties are pretty self explanatory. Some of them are listed below, with their respective default values: 17 | 18 | ``` 19 | /// Font for the text suggestions 20 | public var autoCompleteTextFont = UIFont(name: "HelveticaNeue-Light", size: 12) 21 | /// When set to true, shows autocomplete text with formatting 22 | public var enableAttributedText = false 23 | /// User Defined Attributes 24 | public var autoCompleteAttributes:[String:AnyObject]? 25 | /// Hides autocomplete tableview after selecting a suggestion 26 | public var hidesWhenSelected = true 27 | ``` 28 | 29 | 30 | #### Setting Content 31 | The most important property to use is the `autoCompleteStrings`. As what is declared in the description setting the value of this will automatically reload the tableview, through the use of `didSet` 32 | ``` 33 | /// The strings to be shown on as suggestions, setting the value of this automatically reload the tableview 34 | public var autoCompleteStrings:[String]?{ 35 | didSet{ reload() } 36 | } 37 | ``` 38 | 39 | 40 | #### User Interactions 41 | To handle text changed event, use `onTextChange:` closure. This returns the current text content of the textfield. 42 | ``` 43 | autocompleteTextfield.onTextChange = {[weak self] text in 44 | // your code goes here 45 | ... 46 | } 47 | ``` 48 | To know when user selected a text, use `onSelect:` closure: This returns the selected text and it's indexPath. 49 | 50 | ``` 51 | autocompleteTextfield.onSelect = {[weak self] text, indexpath in 52 | // your code goes here 53 | ... 54 | } 55 | ``` 56 | It's that easy! Feel free to use it, don't worry, it's free. :) 57 | 58 | ## Example Code: 59 | In the example project, I used [Google Places Autocomplete API](https://developers.google.com/places/documentation/autocomplete) to show the usage of this library. For testing purposes i created my own google api key. 60 | 61 | If you want to create your own Google Api Key follow the steps in this [link](https://developers.google.com/maps/documentation/javascript/tutorial#api_key) 62 | 63 | ##### Note: Recent updates in google places API requires you to enable "Google Places API Web Service" and use a Server Key instead of an iOS key. To do so, go to [Google Developers Console](https://console.developers.google.com/). 64 | 65 | ## License 66 | AutocompleteTextfield is under [MIT license](http://opensource.org/licenses/MIT). See LICENSE for details. --------------------------------------------------------------------------------