├── .gitignore ├── LICENSE ├── Placeholders.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── oleg.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── Placeholders.xcscheme │ └── xcschememanagement.plist ├── Placeholders ├── Info.plist ├── Iterators.swift ├── Placeholders+UIKit.swift ├── Placeholders.h └── Placeholders.swift ├── PlaceholdersTests ├── Info.plist └── PlaceholdersTests.swift ├── README.md └── Resources └── Demo.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Oleg Dreyman 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 | -------------------------------------------------------------------------------- /Placeholders.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 7C35B63C1E9F925B004A2BB0 /* Placeholders.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7C35B6321E9F925A004A2BB0 /* Placeholders.framework */; }; 11 | 7C35B6411E9F925B004A2BB0 /* PlaceholdersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C35B6401E9F925B004A2BB0 /* PlaceholdersTests.swift */; }; 12 | 7C35B6431E9F925B004A2BB0 /* Placeholders.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C35B6351E9F925A004A2BB0 /* Placeholders.h */; settings = {ATTRIBUTES = (Public, ); }; }; 13 | 7C35B64D1E9F9280004A2BB0 /* Placeholders.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C35B64C1E9F9280004A2BB0 /* Placeholders.swift */; }; 14 | 7C35B64F1E9F949C004A2BB0 /* Placeholders+UIKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C35B64E1E9F949C004A2BB0 /* Placeholders+UIKit.swift */; }; 15 | 7C7BE6811E9FE8EE001F7CAF /* Iterators.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C7BE6801E9FE8EE001F7CAF /* Iterators.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXContainerItemProxy section */ 19 | 7C35B63D1E9F925B004A2BB0 /* PBXContainerItemProxy */ = { 20 | isa = PBXContainerItemProxy; 21 | containerPortal = 7C35B6291E9F925A004A2BB0 /* Project object */; 22 | proxyType = 1; 23 | remoteGlobalIDString = 7C35B6311E9F925A004A2BB0; 24 | remoteInfo = Placeholders; 25 | }; 26 | /* End PBXContainerItemProxy section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | 7C35B6321E9F925A004A2BB0 /* Placeholders.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Placeholders.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 7C35B6351E9F925A004A2BB0 /* Placeholders.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Placeholders.h; sourceTree = ""; }; 31 | 7C35B6361E9F925A004A2BB0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | 7C35B63B1E9F925B004A2BB0 /* PlaceholdersTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PlaceholdersTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 7C35B6401E9F925B004A2BB0 /* PlaceholdersTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaceholdersTests.swift; sourceTree = ""; }; 34 | 7C35B6421E9F925B004A2BB0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | 7C35B64C1E9F9280004A2BB0 /* Placeholders.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Placeholders.swift; sourceTree = ""; }; 36 | 7C35B64E1E9F949C004A2BB0 /* Placeholders+UIKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Placeholders+UIKit.swift"; sourceTree = ""; }; 37 | 7C7BE6801E9FE8EE001F7CAF /* Iterators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Iterators.swift; sourceTree = ""; }; 38 | /* End PBXFileReference section */ 39 | 40 | /* Begin PBXFrameworksBuildPhase section */ 41 | 7C35B62E1E9F925A004A2BB0 /* Frameworks */ = { 42 | isa = PBXFrameworksBuildPhase; 43 | buildActionMask = 2147483647; 44 | files = ( 45 | ); 46 | runOnlyForDeploymentPostprocessing = 0; 47 | }; 48 | 7C35B6381E9F925B004A2BB0 /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | 7C35B63C1E9F925B004A2BB0 /* Placeholders.framework in Frameworks */, 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | /* End PBXFrameworksBuildPhase section */ 57 | 58 | /* Begin PBXGroup section */ 59 | 7C35B6281E9F925A004A2BB0 = { 60 | isa = PBXGroup; 61 | children = ( 62 | 7C35B6341E9F925A004A2BB0 /* Placeholders */, 63 | 7C35B63F1E9F925B004A2BB0 /* PlaceholdersTests */, 64 | 7C35B6331E9F925A004A2BB0 /* Products */, 65 | ); 66 | sourceTree = ""; 67 | }; 68 | 7C35B6331E9F925A004A2BB0 /* Products */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 7C35B6321E9F925A004A2BB0 /* Placeholders.framework */, 72 | 7C35B63B1E9F925B004A2BB0 /* PlaceholdersTests.xctest */, 73 | ); 74 | name = Products; 75 | sourceTree = ""; 76 | }; 77 | 7C35B6341E9F925A004A2BB0 /* Placeholders */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | 7C35B6351E9F925A004A2BB0 /* Placeholders.h */, 81 | 7C35B6361E9F925A004A2BB0 /* Info.plist */, 82 | 7C7BE6801E9FE8EE001F7CAF /* Iterators.swift */, 83 | 7C35B64C1E9F9280004A2BB0 /* Placeholders.swift */, 84 | 7C35B64E1E9F949C004A2BB0 /* Placeholders+UIKit.swift */, 85 | ); 86 | path = Placeholders; 87 | sourceTree = ""; 88 | }; 89 | 7C35B63F1E9F925B004A2BB0 /* PlaceholdersTests */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 7C35B6401E9F925B004A2BB0 /* PlaceholdersTests.swift */, 93 | 7C35B6421E9F925B004A2BB0 /* Info.plist */, 94 | ); 95 | path = PlaceholdersTests; 96 | sourceTree = ""; 97 | }; 98 | /* End PBXGroup section */ 99 | 100 | /* Begin PBXHeadersBuildPhase section */ 101 | 7C35B62F1E9F925A004A2BB0 /* Headers */ = { 102 | isa = PBXHeadersBuildPhase; 103 | buildActionMask = 2147483647; 104 | files = ( 105 | 7C35B6431E9F925B004A2BB0 /* Placeholders.h in Headers */, 106 | ); 107 | runOnlyForDeploymentPostprocessing = 0; 108 | }; 109 | /* End PBXHeadersBuildPhase section */ 110 | 111 | /* Begin PBXNativeTarget section */ 112 | 7C35B6311E9F925A004A2BB0 /* Placeholders */ = { 113 | isa = PBXNativeTarget; 114 | buildConfigurationList = 7C35B6461E9F925B004A2BB0 /* Build configuration list for PBXNativeTarget "Placeholders" */; 115 | buildPhases = ( 116 | 7C35B62D1E9F925A004A2BB0 /* Sources */, 117 | 7C35B62E1E9F925A004A2BB0 /* Frameworks */, 118 | 7C35B62F1E9F925A004A2BB0 /* Headers */, 119 | 7C35B6301E9F925A004A2BB0 /* Resources */, 120 | ); 121 | buildRules = ( 122 | ); 123 | dependencies = ( 124 | ); 125 | name = Placeholders; 126 | productName = Placeholders; 127 | productReference = 7C35B6321E9F925A004A2BB0 /* Placeholders.framework */; 128 | productType = "com.apple.product-type.framework"; 129 | }; 130 | 7C35B63A1E9F925B004A2BB0 /* PlaceholdersTests */ = { 131 | isa = PBXNativeTarget; 132 | buildConfigurationList = 7C35B6491E9F925B004A2BB0 /* Build configuration list for PBXNativeTarget "PlaceholdersTests" */; 133 | buildPhases = ( 134 | 7C35B6371E9F925B004A2BB0 /* Sources */, 135 | 7C35B6381E9F925B004A2BB0 /* Frameworks */, 136 | 7C35B6391E9F925B004A2BB0 /* Resources */, 137 | ); 138 | buildRules = ( 139 | ); 140 | dependencies = ( 141 | 7C35B63E1E9F925B004A2BB0 /* PBXTargetDependency */, 142 | ); 143 | name = PlaceholdersTests; 144 | productName = PlaceholdersTests; 145 | productReference = 7C35B63B1E9F925B004A2BB0 /* PlaceholdersTests.xctest */; 146 | productType = "com.apple.product-type.bundle.unit-test"; 147 | }; 148 | /* End PBXNativeTarget section */ 149 | 150 | /* Begin PBXProject section */ 151 | 7C35B6291E9F925A004A2BB0 /* Project object */ = { 152 | isa = PBXProject; 153 | attributes = { 154 | LastSwiftUpdateCheck = 0830; 155 | LastUpgradeCheck = 0900; 156 | ORGANIZATIONNAME = AnySuggestion; 157 | TargetAttributes = { 158 | 7C35B6311E9F925A004A2BB0 = { 159 | CreatedOnToolsVersion = 8.3; 160 | DevelopmentTeam = WK35K3FV5Z; 161 | LastSwiftMigration = 0900; 162 | ProvisioningStyle = Automatic; 163 | }; 164 | 7C35B63A1E9F925B004A2BB0 = { 165 | CreatedOnToolsVersion = 8.3; 166 | DevelopmentTeam = WK35K3FV5Z; 167 | LastSwiftMigration = 0900; 168 | ProvisioningStyle = Automatic; 169 | }; 170 | }; 171 | }; 172 | buildConfigurationList = 7C35B62C1E9F925A004A2BB0 /* Build configuration list for PBXProject "Placeholders" */; 173 | compatibilityVersion = "Xcode 3.2"; 174 | developmentRegion = English; 175 | hasScannedForEncodings = 0; 176 | knownRegions = ( 177 | en, 178 | ); 179 | mainGroup = 7C35B6281E9F925A004A2BB0; 180 | productRefGroup = 7C35B6331E9F925A004A2BB0 /* Products */; 181 | projectDirPath = ""; 182 | projectRoot = ""; 183 | targets = ( 184 | 7C35B6311E9F925A004A2BB0 /* Placeholders */, 185 | 7C35B63A1E9F925B004A2BB0 /* PlaceholdersTests */, 186 | ); 187 | }; 188 | /* End PBXProject section */ 189 | 190 | /* Begin PBXResourcesBuildPhase section */ 191 | 7C35B6301E9F925A004A2BB0 /* Resources */ = { 192 | isa = PBXResourcesBuildPhase; 193 | buildActionMask = 2147483647; 194 | files = ( 195 | ); 196 | runOnlyForDeploymentPostprocessing = 0; 197 | }; 198 | 7C35B6391E9F925B004A2BB0 /* Resources */ = { 199 | isa = PBXResourcesBuildPhase; 200 | buildActionMask = 2147483647; 201 | files = ( 202 | ); 203 | runOnlyForDeploymentPostprocessing = 0; 204 | }; 205 | /* End PBXResourcesBuildPhase section */ 206 | 207 | /* Begin PBXSourcesBuildPhase section */ 208 | 7C35B62D1E9F925A004A2BB0 /* Sources */ = { 209 | isa = PBXSourcesBuildPhase; 210 | buildActionMask = 2147483647; 211 | files = ( 212 | 7C7BE6811E9FE8EE001F7CAF /* Iterators.swift in Sources */, 213 | 7C35B64F1E9F949C004A2BB0 /* Placeholders+UIKit.swift in Sources */, 214 | 7C35B64D1E9F9280004A2BB0 /* Placeholders.swift in Sources */, 215 | ); 216 | runOnlyForDeploymentPostprocessing = 0; 217 | }; 218 | 7C35B6371E9F925B004A2BB0 /* Sources */ = { 219 | isa = PBXSourcesBuildPhase; 220 | buildActionMask = 2147483647; 221 | files = ( 222 | 7C35B6411E9F925B004A2BB0 /* PlaceholdersTests.swift in Sources */, 223 | ); 224 | runOnlyForDeploymentPostprocessing = 0; 225 | }; 226 | /* End PBXSourcesBuildPhase section */ 227 | 228 | /* Begin PBXTargetDependency section */ 229 | 7C35B63E1E9F925B004A2BB0 /* PBXTargetDependency */ = { 230 | isa = PBXTargetDependency; 231 | target = 7C35B6311E9F925A004A2BB0 /* Placeholders */; 232 | targetProxy = 7C35B63D1E9F925B004A2BB0 /* PBXContainerItemProxy */; 233 | }; 234 | /* End PBXTargetDependency section */ 235 | 236 | /* Begin XCBuildConfiguration section */ 237 | 7C35B6441E9F925B004A2BB0 /* Debug */ = { 238 | isa = XCBuildConfiguration; 239 | buildSettings = { 240 | ALWAYS_SEARCH_USER_PATHS = NO; 241 | CLANG_ANALYZER_NONNULL = YES; 242 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 243 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 244 | CLANG_CXX_LIBRARY = "libc++"; 245 | CLANG_ENABLE_MODULES = YES; 246 | CLANG_ENABLE_OBJC_ARC = YES; 247 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 248 | CLANG_WARN_BOOL_CONVERSION = YES; 249 | CLANG_WARN_COMMA = YES; 250 | CLANG_WARN_CONSTANT_CONVERSION = YES; 251 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 252 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 253 | CLANG_WARN_EMPTY_BODY = YES; 254 | CLANG_WARN_ENUM_CONVERSION = YES; 255 | CLANG_WARN_INFINITE_RECURSION = YES; 256 | CLANG_WARN_INT_CONVERSION = YES; 257 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 258 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 259 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 260 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 261 | CLANG_WARN_STRICT_PROTOTYPES = YES; 262 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 263 | CLANG_WARN_UNREACHABLE_CODE = YES; 264 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 265 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 266 | COPY_PHASE_STRIP = NO; 267 | CURRENT_PROJECT_VERSION = 1; 268 | DEBUG_INFORMATION_FORMAT = dwarf; 269 | ENABLE_STRICT_OBJC_MSGSEND = YES; 270 | ENABLE_TESTABILITY = YES; 271 | GCC_C_LANGUAGE_STANDARD = gnu99; 272 | GCC_DYNAMIC_NO_PIC = NO; 273 | GCC_NO_COMMON_BLOCKS = YES; 274 | GCC_OPTIMIZATION_LEVEL = 0; 275 | GCC_PREPROCESSOR_DEFINITIONS = ( 276 | "DEBUG=1", 277 | "$(inherited)", 278 | ); 279 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 280 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 281 | GCC_WARN_UNDECLARED_SELECTOR = YES; 282 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 283 | GCC_WARN_UNUSED_FUNCTION = YES; 284 | GCC_WARN_UNUSED_VARIABLE = YES; 285 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 286 | MTL_ENABLE_DEBUG_INFO = YES; 287 | ONLY_ACTIVE_ARCH = YES; 288 | SDKROOT = iphoneos; 289 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 290 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 291 | TARGETED_DEVICE_FAMILY = "1,2"; 292 | VERSIONING_SYSTEM = "apple-generic"; 293 | VERSION_INFO_PREFIX = ""; 294 | }; 295 | name = Debug; 296 | }; 297 | 7C35B6451E9F925B004A2BB0 /* Release */ = { 298 | isa = XCBuildConfiguration; 299 | buildSettings = { 300 | ALWAYS_SEARCH_USER_PATHS = NO; 301 | CLANG_ANALYZER_NONNULL = YES; 302 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 303 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 304 | CLANG_CXX_LIBRARY = "libc++"; 305 | CLANG_ENABLE_MODULES = YES; 306 | CLANG_ENABLE_OBJC_ARC = YES; 307 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 308 | CLANG_WARN_BOOL_CONVERSION = YES; 309 | CLANG_WARN_COMMA = YES; 310 | CLANG_WARN_CONSTANT_CONVERSION = YES; 311 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 312 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 313 | CLANG_WARN_EMPTY_BODY = YES; 314 | CLANG_WARN_ENUM_CONVERSION = YES; 315 | CLANG_WARN_INFINITE_RECURSION = YES; 316 | CLANG_WARN_INT_CONVERSION = YES; 317 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 318 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 319 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 320 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 321 | CLANG_WARN_STRICT_PROTOTYPES = YES; 322 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 323 | CLANG_WARN_UNREACHABLE_CODE = YES; 324 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 325 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 326 | COPY_PHASE_STRIP = NO; 327 | CURRENT_PROJECT_VERSION = 1; 328 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 329 | ENABLE_NS_ASSERTIONS = NO; 330 | ENABLE_STRICT_OBJC_MSGSEND = YES; 331 | GCC_C_LANGUAGE_STANDARD = gnu99; 332 | GCC_NO_COMMON_BLOCKS = YES; 333 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 334 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 335 | GCC_WARN_UNDECLARED_SELECTOR = YES; 336 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 337 | GCC_WARN_UNUSED_FUNCTION = YES; 338 | GCC_WARN_UNUSED_VARIABLE = YES; 339 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 340 | MTL_ENABLE_DEBUG_INFO = NO; 341 | SDKROOT = iphoneos; 342 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 343 | TARGETED_DEVICE_FAMILY = "1,2"; 344 | VALIDATE_PRODUCT = YES; 345 | VERSIONING_SYSTEM = "apple-generic"; 346 | VERSION_INFO_PREFIX = ""; 347 | }; 348 | name = Release; 349 | }; 350 | 7C35B6471E9F925B004A2BB0 /* Debug */ = { 351 | isa = XCBuildConfiguration; 352 | buildSettings = { 353 | CLANG_ENABLE_MODULES = YES; 354 | CODE_SIGN_IDENTITY = ""; 355 | DEFINES_MODULE = YES; 356 | DEVELOPMENT_TEAM = WK35K3FV5Z; 357 | DYLIB_COMPATIBILITY_VERSION = 1; 358 | DYLIB_CURRENT_VERSION = 1; 359 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 360 | INFOPLIST_FILE = Placeholders/Info.plist; 361 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 362 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 363 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 364 | PRODUCT_BUNDLE_IDENTIFIER = com.anysuggestion.Placeholders; 365 | PRODUCT_NAME = "$(TARGET_NAME)"; 366 | SKIP_INSTALL = YES; 367 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 368 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 369 | SWIFT_VERSION = 4.0; 370 | }; 371 | name = Debug; 372 | }; 373 | 7C35B6481E9F925B004A2BB0 /* Release */ = { 374 | isa = XCBuildConfiguration; 375 | buildSettings = { 376 | CLANG_ENABLE_MODULES = YES; 377 | CODE_SIGN_IDENTITY = ""; 378 | DEFINES_MODULE = YES; 379 | DEVELOPMENT_TEAM = WK35K3FV5Z; 380 | DYLIB_COMPATIBILITY_VERSION = 1; 381 | DYLIB_CURRENT_VERSION = 1; 382 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 383 | INFOPLIST_FILE = Placeholders/Info.plist; 384 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 385 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 386 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 387 | PRODUCT_BUNDLE_IDENTIFIER = com.anysuggestion.Placeholders; 388 | PRODUCT_NAME = "$(TARGET_NAME)"; 389 | SKIP_INSTALL = YES; 390 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 391 | SWIFT_VERSION = 4.0; 392 | }; 393 | name = Release; 394 | }; 395 | 7C35B64A1E9F925B004A2BB0 /* Debug */ = { 396 | isa = XCBuildConfiguration; 397 | buildSettings = { 398 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 399 | DEVELOPMENT_TEAM = WK35K3FV5Z; 400 | INFOPLIST_FILE = PlaceholdersTests/Info.plist; 401 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 402 | PRODUCT_BUNDLE_IDENTIFIER = com.anysuggestion.PlaceholdersTests; 403 | PRODUCT_NAME = "$(TARGET_NAME)"; 404 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 405 | SWIFT_VERSION = 4.0; 406 | }; 407 | name = Debug; 408 | }; 409 | 7C35B64B1E9F925B004A2BB0 /* Release */ = { 410 | isa = XCBuildConfiguration; 411 | buildSettings = { 412 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 413 | DEVELOPMENT_TEAM = WK35K3FV5Z; 414 | INFOPLIST_FILE = PlaceholdersTests/Info.plist; 415 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 416 | PRODUCT_BUNDLE_IDENTIFIER = com.anysuggestion.PlaceholdersTests; 417 | PRODUCT_NAME = "$(TARGET_NAME)"; 418 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 419 | SWIFT_VERSION = 4.0; 420 | }; 421 | name = Release; 422 | }; 423 | /* End XCBuildConfiguration section */ 424 | 425 | /* Begin XCConfigurationList section */ 426 | 7C35B62C1E9F925A004A2BB0 /* Build configuration list for PBXProject "Placeholders" */ = { 427 | isa = XCConfigurationList; 428 | buildConfigurations = ( 429 | 7C35B6441E9F925B004A2BB0 /* Debug */, 430 | 7C35B6451E9F925B004A2BB0 /* Release */, 431 | ); 432 | defaultConfigurationIsVisible = 0; 433 | defaultConfigurationName = Release; 434 | }; 435 | 7C35B6461E9F925B004A2BB0 /* Build configuration list for PBXNativeTarget "Placeholders" */ = { 436 | isa = XCConfigurationList; 437 | buildConfigurations = ( 438 | 7C35B6471E9F925B004A2BB0 /* Debug */, 439 | 7C35B6481E9F925B004A2BB0 /* Release */, 440 | ); 441 | defaultConfigurationIsVisible = 0; 442 | defaultConfigurationName = Release; 443 | }; 444 | 7C35B6491E9F925B004A2BB0 /* Build configuration list for PBXNativeTarget "PlaceholdersTests" */ = { 445 | isa = XCConfigurationList; 446 | buildConfigurations = ( 447 | 7C35B64A1E9F925B004A2BB0 /* Debug */, 448 | 7C35B64B1E9F925B004A2BB0 /* Release */, 449 | ); 450 | defaultConfigurationIsVisible = 0; 451 | defaultConfigurationName = Release; 452 | }; 453 | /* End XCConfigurationList section */ 454 | }; 455 | rootObject = 7C35B6291E9F925A004A2BB0 /* Project object */; 456 | } 457 | -------------------------------------------------------------------------------- /Placeholders.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Placeholders.xcodeproj/xcuserdata/oleg.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Placeholders.xcodeproj/xcuserdata/oleg.xcuserdatad/xcschemes/Placeholders.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 65 | 71 | 72 | 73 | 74 | 75 | 76 | 82 | 83 | 89 | 90 | 91 | 92 | 94 | 95 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Placeholders.xcodeproj/xcuserdata/oleg.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Placeholders.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 7C35B6311E9F925A004A2BB0 16 | 17 | primary 18 | 19 | 20 | 7C35B63A1E9F925B004A2BB0 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Placeholders/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 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Placeholders/Iterators.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InfiniteArrayIterator.swift 3 | // The Cleaning App 4 | // 5 | // Created by Олег on 10.04.17. 6 | // Copyright © 2017 Two-212 Apps. All rights reserved. 7 | // 8 | 9 | public struct InfiniteIterator : IteratorProtocol { 10 | 11 | private let sampleIterator: Iterator 12 | private var currentIterator: Iterator 13 | 14 | public init(_ sample: Iterator) { 15 | self.sampleIterator = sample 16 | self.currentIterator = sampleIterator 17 | } 18 | 19 | public mutating func next() -> Iterator.Element? { 20 | if let next = currentIterator.next() { 21 | return next 22 | } else { 23 | self.currentIterator = sampleIterator 24 | return currentIterator.next() 25 | } 26 | } 27 | 28 | } 29 | 30 | public extension IteratorProtocol { 31 | 32 | func infinite() -> InfiniteIterator { 33 | return InfiniteIterator(self) 34 | } 35 | 36 | } 37 | 38 | // Inspired by Nate Cook: https://gist.github.com/natecook1000/0ac03efe07f647b46dae 39 | 40 | extension MutableCollection { 41 | 42 | /// Shuffles the contents of this collection. 43 | internal mutating func shuffle() { 44 | let count = self.count 45 | guard count > 1 else { return } 46 | for (firstUnshuffled, unshuffledCount) in zip(indices, stride(from: count, to: 1, by: -1)) { 47 | let distance: IndexDistance = numericCast(arc4random_uniform(numericCast(unshuffledCount))) 48 | guard distance != 0 else { continue } 49 | let i = index(firstUnshuffled, offsetBy: distance) 50 | self.swapAt(firstUnshuffled, i) 51 | } 52 | } 53 | 54 | } 55 | 56 | extension Sequence { 57 | 58 | internal func shuffled() -> [Iterator.Element] { 59 | var shuffling = Array(self) 60 | shuffling.shuffle() 61 | return shuffling 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /Placeholders/Placeholders+UIKit.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Placeholders+UIKit.swift 3 | // Placeholders 4 | // 5 | // Created by Олег on 13.04.17. 6 | // Copyright © 2017 AnySuggestion. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public protocol TextFieldPlaceholder { 12 | 13 | func set(on textField: UITextField) 14 | 15 | } 16 | 17 | extension String : TextFieldPlaceholder { 18 | 19 | public func set(on textField: UITextField) { 20 | textField.placeholder = self 21 | } 22 | 23 | } 24 | 25 | extension NSAttributedString : TextFieldPlaceholder { 26 | 27 | public func set(on textField: UITextField) { 28 | textField.attributedPlaceholder = self 29 | } 30 | 31 | } 32 | 33 | extension UITextField { 34 | 35 | var isTextEmpty: Bool { 36 | if let text = text { 37 | return text.isEmpty 38 | } 39 | return true 40 | } 41 | 42 | public struct PlaceholderChange { 43 | 44 | private let _setNewPlaceholder: (Placeholder, UITextField) -> () 45 | 46 | public func setNewPlaceholder(_ placeholder: Placeholder, on textField: UITextField) { 47 | guard textField.isTextEmpty else { return } 48 | _setNewPlaceholder(placeholder, textField) 49 | } 50 | 51 | public init(setNewPlaceholder: @escaping (Placeholder, UITextField) -> ()) { 52 | self._setNewPlaceholder = setNewPlaceholder 53 | } 54 | 55 | } 56 | 57 | } 58 | 59 | extension UITextField.PlaceholderChange { 60 | 61 | public static func caTransition(_ transition: @escaping () -> CATransition) -> UITextField.PlaceholderChange { 62 | return UITextField.PlaceholderChange { (placeholder, textField) in 63 | let transition = transition() 64 | textField.subviews.first(where: { NSStringFromClass(type(of: $0)) == "UITextFieldLabel" })?.layer.add(transition, forKey: nil) 65 | placeholder.set(on: textField) 66 | } 67 | } 68 | 69 | public enum TransitionPushDirection { 70 | case fromBottom 71 | case fromLeft 72 | case fromRight 73 | case fromTop 74 | 75 | public var coreAnimationConstant: String { 76 | switch self { 77 | case .fromBottom: 78 | return kCATransitionFromBottom 79 | case .fromTop: 80 | return kCATransitionFromTop 81 | case .fromLeft: 82 | return kCATransitionFromLeft 83 | case .fromRight: 84 | return kCATransitionFromRight 85 | } 86 | } 87 | } 88 | 89 | public static func pushTransition(_ direction: TransitionPushDirection, 90 | duration: TimeInterval = 0.35, 91 | timingFunction: CAMediaTimingFunction = .init(name: kCAMediaTimingFunctionEaseInEaseOut)) -> UITextField.PlaceholderChange { 92 | return .caTransition { 93 | let transition = CATransition() 94 | transition.duration = duration 95 | transition.timingFunction = timingFunction 96 | transition.type = kCATransitionPush 97 | transition.subtype = direction.coreAnimationConstant 98 | return transition 99 | } 100 | } 101 | 102 | } 103 | 104 | extension Placeholders where Element : TextFieldPlaceholder { 105 | 106 | public func start(interval: TimeInterval, 107 | fireInitial: Bool = true, 108 | textField: UITextField, 109 | animation change: UITextField.PlaceholderChange) { 110 | self.start(interval: interval, fireInitial: fireInitial) { [weak textField, weak self] (placeholder) in 111 | if let textField = textField { 112 | change.setNewPlaceholder(placeholder, on: textField) 113 | } else { 114 | self?.timer?.invalidate() 115 | } 116 | } 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /Placeholders/Placeholders.h: -------------------------------------------------------------------------------- 1 | // 2 | // Placeholders.h 3 | // Placeholders 4 | // 5 | // Created by Олег on 13.04.17. 6 | // Copyright © 2017 AnySuggestion. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for Placeholders. 12 | FOUNDATION_EXPORT double PlaceholdersVersionNumber; 13 | 14 | //! Project version string for Placeholders. 15 | FOUNDATION_EXPORT const unsigned char PlaceholdersVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /Placeholders/Placeholders.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Placeholders.swift 3 | // Placeholders 4 | // 5 | // Created by Олег on 13.04.17. 6 | // Copyright © 2017 AnySuggestion. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public struct PlaceholdersOptions : OptionSet { 12 | 13 | public var rawValue: Int 14 | 15 | public init(rawValue: Int) { 16 | self.rawValue = rawValue 17 | } 18 | 19 | public static var infinite = PlaceholdersOptions(rawValue: 1 << 0) 20 | public static var shuffle = PlaceholdersOptions(rawValue: 1 << 1) 21 | 22 | } 23 | 24 | final public class Placeholders { 25 | 26 | public var iterator: AnyIterator 27 | var timer: Timer? 28 | var action: (Element) -> () = { _ in } 29 | 30 | public init(iterator: Iterator) where Iterator.Element == Element { 31 | self.iterator = AnyIterator(iterator) 32 | } 33 | 34 | public convenience init(placeholders: [Element], options: PlaceholdersOptions = []) { 35 | var finalPlaceholders = placeholders 36 | if options.contains(.shuffle) { finalPlaceholders.shuffle() } 37 | if options.contains(.infinite) { 38 | self.init(iterator: finalPlaceholders.makeIterator().infinite()) 39 | } else { 40 | self.init(iterator: finalPlaceholders.makeIterator()) 41 | } 42 | } 43 | 44 | deinit { 45 | timer?.invalidate() 46 | } 47 | 48 | public func start(interval: TimeInterval, fireInitial: Bool, action: @escaping (Element) -> ()) { 49 | self.action = action 50 | let timer = Timer(timeInterval: interval, 51 | target: self, 52 | selector: #selector(act(timer:)), 53 | userInfo: nil, 54 | repeats: true) 55 | RunLoop.current.add(timer, forMode: .defaultRunLoopMode) 56 | self.timer = timer 57 | if fireInitial { 58 | if let firstPlaceholder = iterator.next() { 59 | action(firstPlaceholder) 60 | } 61 | } 62 | } 63 | 64 | @objc private func act(timer: Timer) { 65 | if let nextPlaceholder = iterator.next() { 66 | action(nextPlaceholder) 67 | } else { 68 | timer.invalidate() 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /PlaceholdersTests/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 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /PlaceholdersTests/PlaceholdersTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PlaceholdersTests.swift 3 | // PlaceholdersTests 4 | // 5 | // Created by Олег on 13.04.17. 6 | // Copyright © 2017 AnySuggestion. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import Placeholders 11 | 12 | extension UITextField.PlaceholderChange { 13 | 14 | static var fade_a: UITextField.PlaceholderChange { 15 | return UITextField.PlaceholderChange { (placeholder, textField) in 16 | let transition = CATransition() 17 | transition.duration = 0.35 18 | transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) 19 | transition.type = kCATransitionFade 20 | textField.subviews.first(where: { NSStringFromClass(type(of: $0)) == "UITextFieldLabel" })?.layer.add(transition, forKey: nil) 21 | placeholder.set(on: textField) 22 | } 23 | } 24 | 25 | static var fade: UITextField.PlaceholderChange { 26 | return .caTransition { 27 | let transition = CATransition() 28 | transition.duration = 0.35 29 | transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) 30 | transition.type = kCATransitionFade 31 | return transition 32 | } 33 | } 34 | 35 | } 36 | 37 | class PlaceholdersTests: XCTestCase { 38 | 39 | let placeholders = Placeholders(placeholders: ["First", "Second", "Third"], options: [.infinite, .shuffle]) 40 | 41 | override func setUp() { 42 | super.setUp() 43 | // Put setup code here. This method is called before the invocation of each test method in the class. 44 | } 45 | 46 | override func tearDown() { 47 | // Put teardown code here. This method is called after the invocation of each test method in the class. 48 | super.tearDown() 49 | } 50 | 51 | func testExample() { 52 | // This is an example of a functional test case. 53 | // Use XCTAssert and related functions to verify your tests produce the correct results. 54 | } 55 | 56 | func testREADME2() { 57 | let textField = UITextField() 58 | placeholders.start(interval: 3.0, 59 | fireInitial: true, 60 | textField: textField, 61 | animation: .pushTransition(.fromBottom)) 62 | placeholders.start(interval: 3.0, 63 | fireInitial: true, 64 | textField: textField, 65 | animation: .fade) 66 | } 67 | 68 | func testREADME1() { 69 | let placeholders = Placeholders(placeholders: ["A", "B", "C"], options: .infinite) 70 | placeholders.start(interval: 2.0, fireInitial: true, action: { next in 71 | print(next) 72 | }) 73 | } 74 | 75 | func testPerformanceExample() { 76 | // This is an example of a performance test case. 77 | self.measure { 78 | // Put the code you want to measure the time of here. 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Placeholders 2 | 3 | [![Swift][swift-badge]][swift-url] 4 | [![Platform][platform-badge]][platform-url] 5 | 6 | **Placeholders** gives you the ability to define multiple placeholders for `UITextField`, and also animate their change in the way you like. The result looks like that: 7 | 8 | ![Demo](Resources/Demo.gif) 9 | 10 | You can read more about the library on [Medium][medium-article-url]. 11 | 12 | ## Usage 13 | #### 1. Define a `Placeholder` object in your view controller: 14 | 15 | ```swift 16 | let placeholders = Placeholders(placeholders: ["First", "Second", "Third"]) 17 | ``` 18 | 19 | If you want to loop placeholders (make the set infinite): 20 | 21 | ```swift 22 | let placeholders = Placeholders(placeholders: ["First", "Second", "Third"], options: .infinite) 23 | ``` 24 | 25 | If you also want to show them in a random order: 26 | 27 | ```swift 28 | let placeholders = Placeholders(placeholders: ["First", "Second", "Third"], options: [.infinite, .shuffle]) 29 | ``` 30 | 31 | #### 2. In your `viewWillAppear` method, call `.start`: 32 | 33 | ```swift 34 | placeholders.start(interval: 3.0, 35 | fireInitial: true, 36 | textField: textField, 37 | animation: .pushTransition(.fromBottom)) 38 | ``` 39 | 40 | That's it! 41 | 42 | ## Advanced 43 | While being easy-to-use, **Placeholders** can be highly customized. At it's core, `Placeholders` object doesn't know anything about `UITextField`. You can easily use it for other purposes if you wish: 44 | 45 | ```swift 46 | let placeholders = Placeholders(placeholders: ["A", "B", "C"], options: .infinite) 47 | placeholders.start(interval: 2.0, fireInitial: true, action: { next in 48 | print(next) 49 | }) 50 | ``` 51 | 52 | Actually, the `UITextField` convenience is just a wrapper around this method. 53 | 54 | But if you just want to make a custom `animation` as, for example, `.pushTransition`, you can extend `UITextField.PlaceholderChange`. Here is how you can implement your own custom fade animation: 55 | 56 | ```swift 57 | extension UITextField.PlaceholderChange { 58 | 59 | static var fade: UITextField.PlaceholderChange { 60 | return UITextField.PlaceholderChange { (placeholder, textField) in 61 | let transition = CATransition() 62 | transition.duration = 0.35 63 | transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) 64 | transition.type = kCATransitionFade 65 | textField.subviews.first(where: { NSStringFromClass(type(of: $0)) == "UITextFieldLabel" })?.layer.add(transition, forKey: nil) 66 | placeholder.set(on: textField) 67 | } 68 | } 69 | 70 | } 71 | ``` 72 | 73 | This generic `Placeholder` type and `placeholder.set(on: textField)` syntax exists in order to support `NSAttributedString` as a placeholder. 74 | 75 | You can also use convenience `.caTransition` static function to make your life a bit easier: 76 | 77 | ```swift 78 | extension UITextField.PlaceholderChange { 79 | 80 | static var fade: UITextField.PlaceholderChange { 81 | return .caTransition { 82 | let transition = CATransition() 83 | transition.duration = 0.35 84 | transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) 85 | transition.type = kCATransitionFade 86 | return transition 87 | } 88 | } 89 | 90 | } 91 | ``` 92 | 93 | And now you can simply write: 94 | 95 | ```swift 96 | placeholders.start(interval: 3.0, 97 | fireInitial: true, 98 | textField: textField, 99 | animation: .fade) 100 | ``` 101 | 102 | Neat! 103 | 104 | ## Installation 105 | **Placeholders** is available through [Carthage][carthage-url]. To install, just write into your Cartfile: 106 | 107 | ```ruby 108 | github "dreymonde/Placeholders" ~> 0.1.0 109 | ``` 110 | 111 | We also encourage you to write your very own implementation that fits your needs best. Our source code is there to help. 112 | 113 | [carthage-url]: https://github.com/Carthage/Carthage 114 | [swift-badge]: https://img.shields.io/badge/Swift-3.0-orange.svg?style=flat 115 | [swift-url]: https://swift.org 116 | [platform-badge]: https://img.shields.io/badge/Platform-iOS-lightgray.svg?style=flat 117 | [platform-url]: https://developer.apple.com/swift/ 118 | [medium-article-url]: https://medium.com/anysuggestion/introducing-placeholders-1cc6927b097d 119 | -------------------------------------------------------------------------------- /Resources/Demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dreymonde/Placeholders/45b548a37c51ba90a5e6116d1e13f772720d99d9/Resources/Demo.gif --------------------------------------------------------------------------------