├── .gitignore ├── Example └── GCDTimerExample │ ├── ExampleSS.png │ ├── GCDTimerExample.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ ├── GCDTimerExample │ ├── AppDelegate.swift │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ └── ViewController.swift │ └── GCDTimerExampleTests │ ├── GCDTimerExampleTests.swift │ └── Info.plist ├── GCDTimer.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── WorkspaceSettings.xcsettings └── xcshareddata │ └── xcschemes │ └── GCDTimer.xcscheme ├── GCDTimer ├── GCDTimer.h ├── GCDTimer.swift └── Info.plist ├── GCDTimerTests ├── GCDTimerTests.swift └── Info.plist ├── LICENSE └── README.md /.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 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | 28 | # Carthage 29 | # 30 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 31 | # Carthage/Checkouts 32 | 33 | Carthage/Build 34 | 35 | # MacOSX 36 | .DS_Store 37 | -------------------------------------------------------------------------------- /Example/GCDTimerExample/ExampleSS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemantasapkota/GCDTimer/dea3e9d25bf56eee16058c646d1e880cd5bdcf23/Example/GCDTimerExample/ExampleSS.png -------------------------------------------------------------------------------- /Example/GCDTimerExample/GCDTimerExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 2E3CCE221B2038180085EA22 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E3CCE211B2038180085EA22 /* AppDelegate.swift */; }; 11 | 2E3CCE241B2038180085EA22 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E3CCE231B2038180085EA22 /* ViewController.swift */; }; 12 | 2E3CCE271B2038180085EA22 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2E3CCE251B2038180085EA22 /* Main.storyboard */; }; 13 | 2E3CCE291B2038180085EA22 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2E3CCE281B2038180085EA22 /* Images.xcassets */; }; 14 | 2E3CCE2C1B2038180085EA22 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2E3CCE2A1B2038180085EA22 /* LaunchScreen.xib */; }; 15 | 2E3CCE381B2038190085EA22 /* GCDTimerExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E3CCE371B2038190085EA22 /* GCDTimerExampleTests.swift */; }; 16 | 2EB93D15296AB3950098012E /* GCDTimer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E3CCE481B2038400085EA22 /* GCDTimer.framework */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXContainerItemProxy section */ 20 | 2E3CCE321B2038190085EA22 /* PBXContainerItemProxy */ = { 21 | isa = PBXContainerItemProxy; 22 | containerPortal = 2E3CCE141B2038180085EA22 /* Project object */; 23 | proxyType = 1; 24 | remoteGlobalIDString = 2E3CCE1B1B2038180085EA22; 25 | remoteInfo = GCDTimerExample; 26 | }; 27 | 2E3CCE471B2038400085EA22 /* PBXContainerItemProxy */ = { 28 | isa = PBXContainerItemProxy; 29 | containerPortal = 2E3CCE421B2038400085EA22 /* GCDTimer.xcodeproj */; 30 | proxyType = 2; 31 | remoteGlobalIDString = 2EE9CCAF1B200F7A00D1FDF6; 32 | remoteInfo = GCDTimer; 33 | }; 34 | 2E3CCE491B2038400085EA22 /* PBXContainerItemProxy */ = { 35 | isa = PBXContainerItemProxy; 36 | containerPortal = 2E3CCE421B2038400085EA22 /* GCDTimer.xcodeproj */; 37 | proxyType = 2; 38 | remoteGlobalIDString = 2EE9CCBA1B200F7A00D1FDF6; 39 | remoteInfo = GCDTimerTests; 40 | }; 41 | /* End PBXContainerItemProxy section */ 42 | 43 | /* Begin PBXFileReference section */ 44 | 2E3CCE1C1B2038180085EA22 /* GCDTimerExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GCDTimerExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 45 | 2E3CCE201B2038180085EA22 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 46 | 2E3CCE211B2038180085EA22 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 47 | 2E3CCE231B2038180085EA22 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 48 | 2E3CCE261B2038180085EA22 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 49 | 2E3CCE281B2038180085EA22 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 50 | 2E3CCE2B1B2038180085EA22 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 51 | 2E3CCE311B2038190085EA22 /* GCDTimerExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GCDTimerExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 52 | 2E3CCE361B2038190085EA22 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 53 | 2E3CCE371B2038190085EA22 /* GCDTimerExampleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GCDTimerExampleTests.swift; sourceTree = ""; }; 54 | 2E3CCE421B2038400085EA22 /* GCDTimer.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GCDTimer.xcodeproj; path = ../../GCDTimer.xcodeproj; sourceTree = ""; }; 55 | /* End PBXFileReference section */ 56 | 57 | /* Begin PBXFrameworksBuildPhase section */ 58 | 2E3CCE191B2038180085EA22 /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | 2EB93D15296AB3950098012E /* GCDTimer.framework in Frameworks */, 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | 2E3CCE2E1B2038190085EA22 /* Frameworks */ = { 67 | isa = PBXFrameworksBuildPhase; 68 | buildActionMask = 2147483647; 69 | files = ( 70 | ); 71 | runOnlyForDeploymentPostprocessing = 0; 72 | }; 73 | /* End PBXFrameworksBuildPhase section */ 74 | 75 | /* Begin PBXGroup section */ 76 | 2E3CCE131B2038180085EA22 = { 77 | isa = PBXGroup; 78 | children = ( 79 | 2E3CCE1E1B2038180085EA22 /* GCDTimerExample */, 80 | 2E3CCE341B2038190085EA22 /* GCDTimerExampleTests */, 81 | 2E3CCE1D1B2038180085EA22 /* Products */, 82 | 2E3CCE411B2038330085EA22 /* Frameworks */, 83 | ); 84 | sourceTree = ""; 85 | }; 86 | 2E3CCE1D1B2038180085EA22 /* Products */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 2E3CCE1C1B2038180085EA22 /* GCDTimerExample.app */, 90 | 2E3CCE311B2038190085EA22 /* GCDTimerExampleTests.xctest */, 91 | ); 92 | name = Products; 93 | sourceTree = ""; 94 | }; 95 | 2E3CCE1E1B2038180085EA22 /* GCDTimerExample */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 2E3CCE211B2038180085EA22 /* AppDelegate.swift */, 99 | 2E3CCE231B2038180085EA22 /* ViewController.swift */, 100 | 2E3CCE251B2038180085EA22 /* Main.storyboard */, 101 | 2E3CCE281B2038180085EA22 /* Images.xcassets */, 102 | 2E3CCE2A1B2038180085EA22 /* LaunchScreen.xib */, 103 | 2E3CCE1F1B2038180085EA22 /* Supporting Files */, 104 | ); 105 | path = GCDTimerExample; 106 | sourceTree = ""; 107 | }; 108 | 2E3CCE1F1B2038180085EA22 /* Supporting Files */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 2E3CCE201B2038180085EA22 /* Info.plist */, 112 | ); 113 | name = "Supporting Files"; 114 | sourceTree = ""; 115 | }; 116 | 2E3CCE341B2038190085EA22 /* GCDTimerExampleTests */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | 2E3CCE371B2038190085EA22 /* GCDTimerExampleTests.swift */, 120 | 2E3CCE351B2038190085EA22 /* Supporting Files */, 121 | ); 122 | path = GCDTimerExampleTests; 123 | sourceTree = ""; 124 | }; 125 | 2E3CCE351B2038190085EA22 /* Supporting Files */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | 2E3CCE361B2038190085EA22 /* Info.plist */, 129 | ); 130 | name = "Supporting Files"; 131 | sourceTree = ""; 132 | }; 133 | 2E3CCE411B2038330085EA22 /* Frameworks */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | 2E3CCE421B2038400085EA22 /* GCDTimer.xcodeproj */, 137 | ); 138 | name = Frameworks; 139 | sourceTree = ""; 140 | }; 141 | 2E3CCE431B2038400085EA22 /* Products */ = { 142 | isa = PBXGroup; 143 | children = ( 144 | 2E3CCE481B2038400085EA22 /* GCDTimer.framework */, 145 | 2E3CCE4A1B2038400085EA22 /* GCDTimerTests.xctest */, 146 | ); 147 | name = Products; 148 | sourceTree = ""; 149 | }; 150 | /* End PBXGroup section */ 151 | 152 | /* Begin PBXNativeTarget section */ 153 | 2E3CCE1B1B2038180085EA22 /* GCDTimerExample */ = { 154 | isa = PBXNativeTarget; 155 | buildConfigurationList = 2E3CCE3B1B2038190085EA22 /* Build configuration list for PBXNativeTarget "GCDTimerExample" */; 156 | buildPhases = ( 157 | 2E3CCE181B2038180085EA22 /* Sources */, 158 | 2E3CCE191B2038180085EA22 /* Frameworks */, 159 | 2E3CCE1A1B2038180085EA22 /* Resources */, 160 | ); 161 | buildRules = ( 162 | ); 163 | dependencies = ( 164 | ); 165 | name = GCDTimerExample; 166 | productName = GCDTimerExample; 167 | productReference = 2E3CCE1C1B2038180085EA22 /* GCDTimerExample.app */; 168 | productType = "com.apple.product-type.application"; 169 | }; 170 | 2E3CCE301B2038190085EA22 /* GCDTimerExampleTests */ = { 171 | isa = PBXNativeTarget; 172 | buildConfigurationList = 2E3CCE3E1B2038190085EA22 /* Build configuration list for PBXNativeTarget "GCDTimerExampleTests" */; 173 | buildPhases = ( 174 | 2E3CCE2D1B2038190085EA22 /* Sources */, 175 | 2E3CCE2E1B2038190085EA22 /* Frameworks */, 176 | 2E3CCE2F1B2038190085EA22 /* Resources */, 177 | ); 178 | buildRules = ( 179 | ); 180 | dependencies = ( 181 | 2E3CCE331B2038190085EA22 /* PBXTargetDependency */, 182 | ); 183 | name = GCDTimerExampleTests; 184 | productName = GCDTimerExampleTests; 185 | productReference = 2E3CCE311B2038190085EA22 /* GCDTimerExampleTests.xctest */; 186 | productType = "com.apple.product-type.bundle.unit-test"; 187 | }; 188 | /* End PBXNativeTarget section */ 189 | 190 | /* Begin PBXProject section */ 191 | 2E3CCE141B2038180085EA22 /* Project object */ = { 192 | isa = PBXProject; 193 | attributes = { 194 | LastSwiftMigration = 0730; 195 | LastSwiftUpdateCheck = 0730; 196 | LastUpgradeCheck = 0630; 197 | ORGANIZATIONNAME = "Hemanta Sapkota"; 198 | TargetAttributes = { 199 | 2E3CCE1B1B2038180085EA22 = { 200 | CreatedOnToolsVersion = 6.3.2; 201 | }; 202 | 2E3CCE301B2038190085EA22 = { 203 | CreatedOnToolsVersion = 6.3.2; 204 | TestTargetID = 2E3CCE1B1B2038180085EA22; 205 | }; 206 | }; 207 | }; 208 | buildConfigurationList = 2E3CCE171B2038180085EA22 /* Build configuration list for PBXProject "GCDTimerExample" */; 209 | compatibilityVersion = "Xcode 3.2"; 210 | developmentRegion = English; 211 | hasScannedForEncodings = 0; 212 | knownRegions = ( 213 | English, 214 | en, 215 | Base, 216 | ); 217 | mainGroup = 2E3CCE131B2038180085EA22; 218 | productRefGroup = 2E3CCE1D1B2038180085EA22 /* Products */; 219 | projectDirPath = ""; 220 | projectReferences = ( 221 | { 222 | ProductGroup = 2E3CCE431B2038400085EA22 /* Products */; 223 | ProjectRef = 2E3CCE421B2038400085EA22 /* GCDTimer.xcodeproj */; 224 | }, 225 | ); 226 | projectRoot = ""; 227 | targets = ( 228 | 2E3CCE1B1B2038180085EA22 /* GCDTimerExample */, 229 | 2E3CCE301B2038190085EA22 /* GCDTimerExampleTests */, 230 | ); 231 | }; 232 | /* End PBXProject section */ 233 | 234 | /* Begin PBXReferenceProxy section */ 235 | 2E3CCE481B2038400085EA22 /* GCDTimer.framework */ = { 236 | isa = PBXReferenceProxy; 237 | fileType = wrapper.framework; 238 | path = GCDTimer.framework; 239 | remoteRef = 2E3CCE471B2038400085EA22 /* PBXContainerItemProxy */; 240 | sourceTree = BUILT_PRODUCTS_DIR; 241 | }; 242 | 2E3CCE4A1B2038400085EA22 /* GCDTimerTests.xctest */ = { 243 | isa = PBXReferenceProxy; 244 | fileType = wrapper.cfbundle; 245 | path = GCDTimerTests.xctest; 246 | remoteRef = 2E3CCE491B2038400085EA22 /* PBXContainerItemProxy */; 247 | sourceTree = BUILT_PRODUCTS_DIR; 248 | }; 249 | /* End PBXReferenceProxy section */ 250 | 251 | /* Begin PBXResourcesBuildPhase section */ 252 | 2E3CCE1A1B2038180085EA22 /* Resources */ = { 253 | isa = PBXResourcesBuildPhase; 254 | buildActionMask = 2147483647; 255 | files = ( 256 | 2E3CCE271B2038180085EA22 /* Main.storyboard in Resources */, 257 | 2E3CCE2C1B2038180085EA22 /* LaunchScreen.xib in Resources */, 258 | 2E3CCE291B2038180085EA22 /* Images.xcassets in Resources */, 259 | ); 260 | runOnlyForDeploymentPostprocessing = 0; 261 | }; 262 | 2E3CCE2F1B2038190085EA22 /* Resources */ = { 263 | isa = PBXResourcesBuildPhase; 264 | buildActionMask = 2147483647; 265 | files = ( 266 | ); 267 | runOnlyForDeploymentPostprocessing = 0; 268 | }; 269 | /* End PBXResourcesBuildPhase section */ 270 | 271 | /* Begin PBXSourcesBuildPhase section */ 272 | 2E3CCE181B2038180085EA22 /* Sources */ = { 273 | isa = PBXSourcesBuildPhase; 274 | buildActionMask = 2147483647; 275 | files = ( 276 | 2E3CCE241B2038180085EA22 /* ViewController.swift in Sources */, 277 | 2E3CCE221B2038180085EA22 /* AppDelegate.swift in Sources */, 278 | ); 279 | runOnlyForDeploymentPostprocessing = 0; 280 | }; 281 | 2E3CCE2D1B2038190085EA22 /* Sources */ = { 282 | isa = PBXSourcesBuildPhase; 283 | buildActionMask = 2147483647; 284 | files = ( 285 | 2E3CCE381B2038190085EA22 /* GCDTimerExampleTests.swift in Sources */, 286 | ); 287 | runOnlyForDeploymentPostprocessing = 0; 288 | }; 289 | /* End PBXSourcesBuildPhase section */ 290 | 291 | /* Begin PBXTargetDependency section */ 292 | 2E3CCE331B2038190085EA22 /* PBXTargetDependency */ = { 293 | isa = PBXTargetDependency; 294 | target = 2E3CCE1B1B2038180085EA22 /* GCDTimerExample */; 295 | targetProxy = 2E3CCE321B2038190085EA22 /* PBXContainerItemProxy */; 296 | }; 297 | /* End PBXTargetDependency section */ 298 | 299 | /* Begin PBXVariantGroup section */ 300 | 2E3CCE251B2038180085EA22 /* Main.storyboard */ = { 301 | isa = PBXVariantGroup; 302 | children = ( 303 | 2E3CCE261B2038180085EA22 /* Base */, 304 | ); 305 | name = Main.storyboard; 306 | sourceTree = ""; 307 | }; 308 | 2E3CCE2A1B2038180085EA22 /* LaunchScreen.xib */ = { 309 | isa = PBXVariantGroup; 310 | children = ( 311 | 2E3CCE2B1B2038180085EA22 /* Base */, 312 | ); 313 | name = LaunchScreen.xib; 314 | sourceTree = ""; 315 | }; 316 | /* End PBXVariantGroup section */ 317 | 318 | /* Begin XCBuildConfiguration section */ 319 | 2E3CCE391B2038190085EA22 /* Debug */ = { 320 | isa = XCBuildConfiguration; 321 | buildSettings = { 322 | ALWAYS_SEARCH_USER_PATHS = NO; 323 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 324 | CLANG_CXX_LIBRARY = "libc++"; 325 | CLANG_ENABLE_MODULES = YES; 326 | CLANG_ENABLE_OBJC_ARC = YES; 327 | CLANG_WARN_BOOL_CONVERSION = YES; 328 | CLANG_WARN_CONSTANT_CONVERSION = YES; 329 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 330 | CLANG_WARN_EMPTY_BODY = YES; 331 | CLANG_WARN_ENUM_CONVERSION = YES; 332 | CLANG_WARN_INT_CONVERSION = YES; 333 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 334 | CLANG_WARN_UNREACHABLE_CODE = YES; 335 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 336 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 337 | COPY_PHASE_STRIP = NO; 338 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 339 | ENABLE_STRICT_OBJC_MSGSEND = YES; 340 | GCC_C_LANGUAGE_STANDARD = gnu99; 341 | GCC_DYNAMIC_NO_PIC = NO; 342 | GCC_NO_COMMON_BLOCKS = YES; 343 | GCC_OPTIMIZATION_LEVEL = 0; 344 | GCC_PREPROCESSOR_DEFINITIONS = ( 345 | "DEBUG=1", 346 | "$(inherited)", 347 | ); 348 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 349 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 350 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 351 | GCC_WARN_UNDECLARED_SELECTOR = YES; 352 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 353 | GCC_WARN_UNUSED_FUNCTION = YES; 354 | GCC_WARN_UNUSED_VARIABLE = YES; 355 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 356 | MTL_ENABLE_DEBUG_INFO = YES; 357 | ONLY_ACTIVE_ARCH = YES; 358 | SDKROOT = iphoneos; 359 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 360 | TARGETED_DEVICE_FAMILY = "1,2"; 361 | }; 362 | name = Debug; 363 | }; 364 | 2E3CCE3A1B2038190085EA22 /* Release */ = { 365 | isa = XCBuildConfiguration; 366 | buildSettings = { 367 | ALWAYS_SEARCH_USER_PATHS = NO; 368 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 369 | CLANG_CXX_LIBRARY = "libc++"; 370 | CLANG_ENABLE_MODULES = YES; 371 | CLANG_ENABLE_OBJC_ARC = YES; 372 | CLANG_WARN_BOOL_CONVERSION = YES; 373 | CLANG_WARN_CONSTANT_CONVERSION = YES; 374 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 375 | CLANG_WARN_EMPTY_BODY = YES; 376 | CLANG_WARN_ENUM_CONVERSION = YES; 377 | CLANG_WARN_INT_CONVERSION = YES; 378 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 379 | CLANG_WARN_UNREACHABLE_CODE = YES; 380 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 381 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 382 | COPY_PHASE_STRIP = NO; 383 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 384 | ENABLE_NS_ASSERTIONS = NO; 385 | ENABLE_STRICT_OBJC_MSGSEND = YES; 386 | GCC_C_LANGUAGE_STANDARD = gnu99; 387 | GCC_NO_COMMON_BLOCKS = YES; 388 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 389 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 390 | GCC_WARN_UNDECLARED_SELECTOR = YES; 391 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 392 | GCC_WARN_UNUSED_FUNCTION = YES; 393 | GCC_WARN_UNUSED_VARIABLE = YES; 394 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 395 | MTL_ENABLE_DEBUG_INFO = NO; 396 | SDKROOT = iphoneos; 397 | TARGETED_DEVICE_FAMILY = "1,2"; 398 | VALIDATE_PRODUCT = YES; 399 | }; 400 | name = Release; 401 | }; 402 | 2E3CCE3C1B2038190085EA22 /* Debug */ = { 403 | isa = XCBuildConfiguration; 404 | buildSettings = { 405 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 406 | INFOPLIST_FILE = GCDTimerExample/Info.plist; 407 | IPHONEOS_DEPLOYMENT_TARGET = 15.6; 408 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 409 | PRODUCT_NAME = "$(TARGET_NAME)"; 410 | SWIFT_VERSION = 5.0; 411 | }; 412 | name = Debug; 413 | }; 414 | 2E3CCE3D1B2038190085EA22 /* Release */ = { 415 | isa = XCBuildConfiguration; 416 | buildSettings = { 417 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 418 | INFOPLIST_FILE = GCDTimerExample/Info.plist; 419 | IPHONEOS_DEPLOYMENT_TARGET = 15.6; 420 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 421 | PRODUCT_NAME = "$(TARGET_NAME)"; 422 | SWIFT_VERSION = 5.0; 423 | }; 424 | name = Release; 425 | }; 426 | 2E3CCE3F1B2038190085EA22 /* Debug */ = { 427 | isa = XCBuildConfiguration; 428 | buildSettings = { 429 | BUNDLE_LOADER = "$(TEST_HOST)"; 430 | FRAMEWORK_SEARCH_PATHS = ( 431 | "$(SDKROOT)/Developer/Library/Frameworks", 432 | "$(inherited)", 433 | ); 434 | GCC_PREPROCESSOR_DEFINITIONS = ( 435 | "DEBUG=1", 436 | "$(inherited)", 437 | ); 438 | INFOPLIST_FILE = GCDTimerExampleTests/Info.plist; 439 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 440 | PRODUCT_NAME = "$(TARGET_NAME)"; 441 | SWIFT_VERSION = 5.0; 442 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GCDTimerExample.app/GCDTimerExample"; 443 | }; 444 | name = Debug; 445 | }; 446 | 2E3CCE401B2038190085EA22 /* Release */ = { 447 | isa = XCBuildConfiguration; 448 | buildSettings = { 449 | BUNDLE_LOADER = "$(TEST_HOST)"; 450 | FRAMEWORK_SEARCH_PATHS = ( 451 | "$(SDKROOT)/Developer/Library/Frameworks", 452 | "$(inherited)", 453 | ); 454 | INFOPLIST_FILE = GCDTimerExampleTests/Info.plist; 455 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 456 | PRODUCT_NAME = "$(TARGET_NAME)"; 457 | SWIFT_VERSION = 5.0; 458 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GCDTimerExample.app/GCDTimerExample"; 459 | }; 460 | name = Release; 461 | }; 462 | /* End XCBuildConfiguration section */ 463 | 464 | /* Begin XCConfigurationList section */ 465 | 2E3CCE171B2038180085EA22 /* Build configuration list for PBXProject "GCDTimerExample" */ = { 466 | isa = XCConfigurationList; 467 | buildConfigurations = ( 468 | 2E3CCE391B2038190085EA22 /* Debug */, 469 | 2E3CCE3A1B2038190085EA22 /* Release */, 470 | ); 471 | defaultConfigurationIsVisible = 0; 472 | defaultConfigurationName = Release; 473 | }; 474 | 2E3CCE3B1B2038190085EA22 /* Build configuration list for PBXNativeTarget "GCDTimerExample" */ = { 475 | isa = XCConfigurationList; 476 | buildConfigurations = ( 477 | 2E3CCE3C1B2038190085EA22 /* Debug */, 478 | 2E3CCE3D1B2038190085EA22 /* Release */, 479 | ); 480 | defaultConfigurationIsVisible = 0; 481 | defaultConfigurationName = Release; 482 | }; 483 | 2E3CCE3E1B2038190085EA22 /* Build configuration list for PBXNativeTarget "GCDTimerExampleTests" */ = { 484 | isa = XCConfigurationList; 485 | buildConfigurations = ( 486 | 2E3CCE3F1B2038190085EA22 /* Debug */, 487 | 2E3CCE401B2038190085EA22 /* Release */, 488 | ); 489 | defaultConfigurationIsVisible = 0; 490 | defaultConfigurationName = Release; 491 | }; 492 | /* End XCConfigurationList section */ 493 | }; 494 | rootObject = 2E3CCE141B2038180085EA22 /* Project object */; 495 | } 496 | -------------------------------------------------------------------------------- /Example/GCDTimerExample/GCDTimerExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/GCDTimerExample/GCDTimerExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/GCDTimerExample/GCDTimerExample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // GCDTimerExample 4 | // 5 | // Created by Hemanta Sapkota on 4/06/2015. 6 | // Copyright (c) 2023 Hemanta Sapkota. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | private 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 | internal 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 | internal 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 | internal 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 | internal func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Example/GCDTimerExample/GCDTimerExample/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 22 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Example/GCDTimerExample/GCDTimerExample/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 | -------------------------------------------------------------------------------- /Example/GCDTimerExample/GCDTimerExample/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 | } -------------------------------------------------------------------------------- /Example/GCDTimerExample/GCDTimerExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.laex.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | NSAppTransportSecurity 47 | 48 | NSExceptionDomains 49 | 50 | hacker-news.firebaseio.com 51 | 52 | NSIncludesSubdomains 53 | 54 | NSExceptionRequiresForwardSecrecy 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Example/GCDTimerExample/GCDTimerExample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // GCDTimerExample 4 | // 5 | // Created by Hemanta Sapkota on 4/06/2015. 6 | // Copyright (c) 2023 Hemanta Sapkota. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import GCDTimer 11 | 12 | class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { 13 | 14 | @IBOutlet weak var tableView: UITableView! 15 | 16 | var stories = Array() 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | 21 | tableView.register(TableViewCell.self, forCellReuseIdentifier: "Cell") 22 | 23 | // Use Timer 24 | let timer = GCDTimer(intervalInSecs: 30) 25 | timer.Event = { 26 | print("Reloading stories...") 27 | self.loadStories() 28 | } 29 | timer.start() 30 | } 31 | 32 | func loadStories() { 33 | // Load new HN stories 34 | stories.removeAll(keepingCapacity: false) 35 | 36 | let url = NSURL(string: "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty") 37 | 38 | let task = URLSession.shared.dataTask(with: url! as URL) {(data, response, error) in 39 | 40 | if data == nil { 41 | print("\(String(describing: error))") 42 | return 43 | } 44 | 45 | let json = (try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers)) as! NSArray 46 | for i in (0..<10) { 47 | let itemUrl = NSURL(string: "https://hacker-news.firebaseio.com/v0/item/\(json[i]).json?print=pretty") 48 | let itemTask = URLSession.shared.dataTask(with: itemUrl! as URL) { (data, response, error) in 49 | let json = (try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers)) as! NSDictionary 50 | DispatchQueue.main.async { 51 | let title = json["title"] as! String 52 | 53 | print("\(String(describing: title))") 54 | 55 | self.stories.append(title) 56 | self.tableView.reloadData() 57 | } 58 | } 59 | itemTask.resume() 60 | } 61 | } 62 | 63 | task.resume() 64 | } 65 | 66 | override func didReceiveMemoryWarning() { 67 | super.didReceiveMemoryWarning() 68 | } 69 | } 70 | 71 | extension ViewController { 72 | 73 | class TableViewCell : UITableViewCell { 74 | 75 | override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { 76 | super.init(style: style, reuseIdentifier: reuseIdentifier) 77 | } 78 | 79 | required init?(coder aDecoder: NSCoder) { 80 | fatalError("init(coder:) has not been implemented") 81 | } 82 | } 83 | 84 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 85 | return stories.count 86 | } 87 | 88 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 89 | let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! TableViewCell 90 | 91 | cell.textLabel?.text = stories[indexPath.item] 92 | 93 | return cell 94 | } 95 | 96 | func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 97 | return 80 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Example/GCDTimerExample/GCDTimerExampleTests/GCDTimerExampleTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GCDTimerExampleTests.swift 3 | // GCDTimerExampleTests 4 | // 5 | // Created by Hemanta Sapkota on 4/06/2015. 6 | // Copyright (c) 2023 Hemanta Sapkota. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class GCDTimerExampleTests: 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.measure() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Example/GCDTimerExample/GCDTimerExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.laex.$(PRODUCT_NAME:rfc1034identifier) 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 | -------------------------------------------------------------------------------- /GCDTimer.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 2EB196BD1B20152600A06922 /* GCDTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EE9CCCB1B200F8500D1FDF6 /* GCDTimer.swift */; }; 11 | 2EE9CCB51B200F7A00D1FDF6 /* GCDTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 2EE9CCB41B200F7A00D1FDF6 /* GCDTimer.h */; settings = {ATTRIBUTES = (Public, ); }; }; 12 | 2EE9CCBB1B200F7A00D1FDF6 /* GCDTimer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2EE9CCAF1B200F7A00D1FDF6 /* GCDTimer.framework */; }; 13 | 2EE9CCC21B200F7A00D1FDF6 /* GCDTimerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EE9CCC11B200F7A00D1FDF6 /* GCDTimerTests.swift */; }; 14 | 2EE9CCCC1B200F8500D1FDF6 /* GCDTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EE9CCCB1B200F8500D1FDF6 /* GCDTimer.swift */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXContainerItemProxy section */ 18 | 2EE9CCBC1B200F7A00D1FDF6 /* PBXContainerItemProxy */ = { 19 | isa = PBXContainerItemProxy; 20 | containerPortal = 2EE9CCA61B200F7A00D1FDF6 /* Project object */; 21 | proxyType = 1; 22 | remoteGlobalIDString = 2EE9CCAE1B200F7A00D1FDF6; 23 | remoteInfo = GCDTimer; 24 | }; 25 | /* End PBXContainerItemProxy section */ 26 | 27 | /* Begin PBXFileReference section */ 28 | 2EE9CCAF1B200F7A00D1FDF6 /* GCDTimer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GCDTimer.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 29 | 2EE9CCB31B200F7A00D1FDF6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 2EE9CCB41B200F7A00D1FDF6 /* GCDTimer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GCDTimer.h; sourceTree = ""; }; 31 | 2EE9CCBA1B200F7A00D1FDF6 /* GCDTimerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GCDTimerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | 2EE9CCC01B200F7A00D1FDF6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | 2EE9CCC11B200F7A00D1FDF6 /* GCDTimerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GCDTimerTests.swift; sourceTree = ""; }; 34 | 2EE9CCCB1B200F8500D1FDF6 /* GCDTimer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GCDTimer.swift; sourceTree = ""; }; 35 | /* End PBXFileReference section */ 36 | 37 | /* Begin PBXFrameworksBuildPhase section */ 38 | 2EE9CCAB1B200F7A00D1FDF6 /* Frameworks */ = { 39 | isa = PBXFrameworksBuildPhase; 40 | buildActionMask = 2147483647; 41 | files = ( 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | 2EE9CCB71B200F7A00D1FDF6 /* Frameworks */ = { 46 | isa = PBXFrameworksBuildPhase; 47 | buildActionMask = 2147483647; 48 | files = ( 49 | 2EE9CCBB1B200F7A00D1FDF6 /* GCDTimer.framework in Frameworks */, 50 | ); 51 | runOnlyForDeploymentPostprocessing = 0; 52 | }; 53 | /* End PBXFrameworksBuildPhase section */ 54 | 55 | /* Begin PBXGroup section */ 56 | 2EE9CCA51B200F7A00D1FDF6 = { 57 | isa = PBXGroup; 58 | children = ( 59 | 2EE9CCB11B200F7A00D1FDF6 /* GCDTimer */, 60 | 2EE9CCBE1B200F7A00D1FDF6 /* GCDTimerTests */, 61 | 2EE9CCB01B200F7A00D1FDF6 /* Products */, 62 | ); 63 | sourceTree = ""; 64 | }; 65 | 2EE9CCB01B200F7A00D1FDF6 /* Products */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | 2EE9CCAF1B200F7A00D1FDF6 /* GCDTimer.framework */, 69 | 2EE9CCBA1B200F7A00D1FDF6 /* GCDTimerTests.xctest */, 70 | ); 71 | name = Products; 72 | sourceTree = ""; 73 | }; 74 | 2EE9CCB11B200F7A00D1FDF6 /* GCDTimer */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 2EE9CCB41B200F7A00D1FDF6 /* GCDTimer.h */, 78 | 2EE9CCCB1B200F8500D1FDF6 /* GCDTimer.swift */, 79 | 2EE9CCB21B200F7A00D1FDF6 /* Supporting Files */, 80 | ); 81 | path = GCDTimer; 82 | sourceTree = ""; 83 | }; 84 | 2EE9CCB21B200F7A00D1FDF6 /* Supporting Files */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 2EE9CCB31B200F7A00D1FDF6 /* Info.plist */, 88 | ); 89 | name = "Supporting Files"; 90 | sourceTree = ""; 91 | }; 92 | 2EE9CCBE1B200F7A00D1FDF6 /* GCDTimerTests */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | 2EE9CCC11B200F7A00D1FDF6 /* GCDTimerTests.swift */, 96 | 2EE9CCBF1B200F7A00D1FDF6 /* Supporting Files */, 97 | ); 98 | path = GCDTimerTests; 99 | sourceTree = ""; 100 | }; 101 | 2EE9CCBF1B200F7A00D1FDF6 /* Supporting Files */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 2EE9CCC01B200F7A00D1FDF6 /* Info.plist */, 105 | ); 106 | name = "Supporting Files"; 107 | sourceTree = ""; 108 | }; 109 | /* End PBXGroup section */ 110 | 111 | /* Begin PBXHeadersBuildPhase section */ 112 | 2EE9CCAC1B200F7A00D1FDF6 /* Headers */ = { 113 | isa = PBXHeadersBuildPhase; 114 | buildActionMask = 2147483647; 115 | files = ( 116 | 2EE9CCB51B200F7A00D1FDF6 /* GCDTimer.h in Headers */, 117 | ); 118 | runOnlyForDeploymentPostprocessing = 0; 119 | }; 120 | /* End PBXHeadersBuildPhase section */ 121 | 122 | /* Begin PBXNativeTarget section */ 123 | 2EE9CCAE1B200F7A00D1FDF6 /* GCDTimer */ = { 124 | isa = PBXNativeTarget; 125 | buildConfigurationList = 2EE9CCC51B200F7A00D1FDF6 /* Build configuration list for PBXNativeTarget "GCDTimer" */; 126 | buildPhases = ( 127 | 2EE9CCAA1B200F7A00D1FDF6 /* Sources */, 128 | 2EE9CCAB1B200F7A00D1FDF6 /* Frameworks */, 129 | 2EE9CCAC1B200F7A00D1FDF6 /* Headers */, 130 | 2EE9CCAD1B200F7A00D1FDF6 /* Resources */, 131 | ); 132 | buildRules = ( 133 | ); 134 | dependencies = ( 135 | ); 136 | name = GCDTimer; 137 | productName = GCDTimer; 138 | productReference = 2EE9CCAF1B200F7A00D1FDF6 /* GCDTimer.framework */; 139 | productType = "com.apple.product-type.framework"; 140 | }; 141 | 2EE9CCB91B200F7A00D1FDF6 /* GCDTimerTests */ = { 142 | isa = PBXNativeTarget; 143 | buildConfigurationList = 2EE9CCC81B200F7A00D1FDF6 /* Build configuration list for PBXNativeTarget "GCDTimerTests" */; 144 | buildPhases = ( 145 | 2EE9CCB61B200F7A00D1FDF6 /* Sources */, 146 | 2EE9CCB71B200F7A00D1FDF6 /* Frameworks */, 147 | 2EE9CCB81B200F7A00D1FDF6 /* Resources */, 148 | ); 149 | buildRules = ( 150 | ); 151 | dependencies = ( 152 | 2EE9CCBD1B200F7A00D1FDF6 /* PBXTargetDependency */, 153 | ); 154 | name = GCDTimerTests; 155 | productName = GCDTimerTests; 156 | productReference = 2EE9CCBA1B200F7A00D1FDF6 /* GCDTimerTests.xctest */; 157 | productType = "com.apple.product-type.bundle.unit-test"; 158 | }; 159 | /* End PBXNativeTarget section */ 160 | 161 | /* Begin PBXProject section */ 162 | 2EE9CCA61B200F7A00D1FDF6 /* Project object */ = { 163 | isa = PBXProject; 164 | attributes = { 165 | LastSwiftMigration = 0730; 166 | LastSwiftUpdateCheck = 0700; 167 | LastUpgradeCheck = 0630; 168 | ORGANIZATIONNAME = "Hemanta Sapkota"; 169 | TargetAttributes = { 170 | 2EE9CCAE1B200F7A00D1FDF6 = { 171 | CreatedOnToolsVersion = 6.3.2; 172 | LastSwiftMigration = 0800; 173 | }; 174 | 2EE9CCB91B200F7A00D1FDF6 = { 175 | CreatedOnToolsVersion = 6.3.2; 176 | LastSwiftMigration = 0800; 177 | }; 178 | }; 179 | }; 180 | buildConfigurationList = 2EE9CCA91B200F7A00D1FDF6 /* Build configuration list for PBXProject "GCDTimer" */; 181 | compatibilityVersion = "Xcode 3.2"; 182 | developmentRegion = English; 183 | hasScannedForEncodings = 0; 184 | knownRegions = ( 185 | English, 186 | en, 187 | ); 188 | mainGroup = 2EE9CCA51B200F7A00D1FDF6; 189 | productRefGroup = 2EE9CCB01B200F7A00D1FDF6 /* Products */; 190 | projectDirPath = ""; 191 | projectRoot = ""; 192 | targets = ( 193 | 2EE9CCAE1B200F7A00D1FDF6 /* GCDTimer */, 194 | 2EE9CCB91B200F7A00D1FDF6 /* GCDTimerTests */, 195 | ); 196 | }; 197 | /* End PBXProject section */ 198 | 199 | /* Begin PBXResourcesBuildPhase section */ 200 | 2EE9CCAD1B200F7A00D1FDF6 /* Resources */ = { 201 | isa = PBXResourcesBuildPhase; 202 | buildActionMask = 2147483647; 203 | files = ( 204 | ); 205 | runOnlyForDeploymentPostprocessing = 0; 206 | }; 207 | 2EE9CCB81B200F7A00D1FDF6 /* Resources */ = { 208 | isa = PBXResourcesBuildPhase; 209 | buildActionMask = 2147483647; 210 | files = ( 211 | ); 212 | runOnlyForDeploymentPostprocessing = 0; 213 | }; 214 | /* End PBXResourcesBuildPhase section */ 215 | 216 | /* Begin PBXSourcesBuildPhase section */ 217 | 2EE9CCAA1B200F7A00D1FDF6 /* Sources */ = { 218 | isa = PBXSourcesBuildPhase; 219 | buildActionMask = 2147483647; 220 | files = ( 221 | 2EE9CCCC1B200F8500D1FDF6 /* GCDTimer.swift in Sources */, 222 | ); 223 | runOnlyForDeploymentPostprocessing = 0; 224 | }; 225 | 2EE9CCB61B200F7A00D1FDF6 /* Sources */ = { 226 | isa = PBXSourcesBuildPhase; 227 | buildActionMask = 2147483647; 228 | files = ( 229 | 2EB196BD1B20152600A06922 /* GCDTimer.swift in Sources */, 230 | 2EE9CCC21B200F7A00D1FDF6 /* GCDTimerTests.swift in Sources */, 231 | ); 232 | runOnlyForDeploymentPostprocessing = 0; 233 | }; 234 | /* End PBXSourcesBuildPhase section */ 235 | 236 | /* Begin PBXTargetDependency section */ 237 | 2EE9CCBD1B200F7A00D1FDF6 /* PBXTargetDependency */ = { 238 | isa = PBXTargetDependency; 239 | target = 2EE9CCAE1B200F7A00D1FDF6 /* GCDTimer */; 240 | targetProxy = 2EE9CCBC1B200F7A00D1FDF6 /* PBXContainerItemProxy */; 241 | }; 242 | /* End PBXTargetDependency section */ 243 | 244 | /* Begin XCBuildConfiguration section */ 245 | 2EE9CCC31B200F7A00D1FDF6 /* Debug */ = { 246 | isa = XCBuildConfiguration; 247 | buildSettings = { 248 | ALWAYS_SEARCH_USER_PATHS = NO; 249 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 250 | CLANG_CXX_LIBRARY = "libc++"; 251 | CLANG_ENABLE_MODULES = YES; 252 | CLANG_ENABLE_OBJC_ARC = YES; 253 | CLANG_WARN_BOOL_CONVERSION = YES; 254 | CLANG_WARN_CONSTANT_CONVERSION = YES; 255 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 256 | CLANG_WARN_EMPTY_BODY = YES; 257 | CLANG_WARN_ENUM_CONVERSION = YES; 258 | CLANG_WARN_INT_CONVERSION = YES; 259 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 260 | CLANG_WARN_UNREACHABLE_CODE = YES; 261 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 262 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 263 | COPY_PHASE_STRIP = NO; 264 | CURRENT_PROJECT_VERSION = 1; 265 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 266 | ENABLE_STRICT_OBJC_MSGSEND = YES; 267 | GCC_C_LANGUAGE_STANDARD = gnu99; 268 | GCC_DYNAMIC_NO_PIC = NO; 269 | GCC_NO_COMMON_BLOCKS = YES; 270 | GCC_OPTIMIZATION_LEVEL = 0; 271 | GCC_PREPROCESSOR_DEFINITIONS = ( 272 | "DEBUG=1", 273 | "$(inherited)", 274 | ); 275 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 276 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 277 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 278 | GCC_WARN_UNDECLARED_SELECTOR = YES; 279 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 280 | GCC_WARN_UNUSED_FUNCTION = YES; 281 | GCC_WARN_UNUSED_VARIABLE = YES; 282 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 283 | MTL_ENABLE_DEBUG_INFO = YES; 284 | ONLY_ACTIVE_ARCH = YES; 285 | SDKROOT = iphoneos; 286 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 287 | TARGETED_DEVICE_FAMILY = "1,2"; 288 | VERSIONING_SYSTEM = "apple-generic"; 289 | VERSION_INFO_PREFIX = ""; 290 | }; 291 | name = Debug; 292 | }; 293 | 2EE9CCC41B200F7A00D1FDF6 /* Release */ = { 294 | isa = XCBuildConfiguration; 295 | buildSettings = { 296 | ALWAYS_SEARCH_USER_PATHS = NO; 297 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 298 | CLANG_CXX_LIBRARY = "libc++"; 299 | CLANG_ENABLE_MODULES = YES; 300 | CLANG_ENABLE_OBJC_ARC = YES; 301 | CLANG_WARN_BOOL_CONVERSION = YES; 302 | CLANG_WARN_CONSTANT_CONVERSION = YES; 303 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 304 | CLANG_WARN_EMPTY_BODY = YES; 305 | CLANG_WARN_ENUM_CONVERSION = YES; 306 | CLANG_WARN_INT_CONVERSION = YES; 307 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 308 | CLANG_WARN_UNREACHABLE_CODE = YES; 309 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 310 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 311 | COPY_PHASE_STRIP = NO; 312 | CURRENT_PROJECT_VERSION = 1; 313 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 314 | ENABLE_NS_ASSERTIONS = NO; 315 | ENABLE_STRICT_OBJC_MSGSEND = YES; 316 | GCC_C_LANGUAGE_STANDARD = gnu99; 317 | GCC_NO_COMMON_BLOCKS = YES; 318 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 319 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 320 | GCC_WARN_UNDECLARED_SELECTOR = YES; 321 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 322 | GCC_WARN_UNUSED_FUNCTION = YES; 323 | GCC_WARN_UNUSED_VARIABLE = YES; 324 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 325 | MTL_ENABLE_DEBUG_INFO = NO; 326 | SDKROOT = iphoneos; 327 | TARGETED_DEVICE_FAMILY = "1,2"; 328 | VALIDATE_PRODUCT = YES; 329 | VERSIONING_SYSTEM = "apple-generic"; 330 | VERSION_INFO_PREFIX = ""; 331 | }; 332 | name = Release; 333 | }; 334 | 2EE9CCC61B200F7A00D1FDF6 /* Debug */ = { 335 | isa = XCBuildConfiguration; 336 | buildSettings = { 337 | CLANG_ENABLE_MODULES = YES; 338 | DEFINES_MODULE = YES; 339 | DYLIB_COMPATIBILITY_VERSION = 1; 340 | DYLIB_CURRENT_VERSION = 1; 341 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 342 | INFOPLIST_FILE = GCDTimer/Info.plist; 343 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 344 | IPHONEOS_DEPLOYMENT_TARGET = 15.6; 345 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 346 | PRODUCT_NAME = "$(TARGET_NAME)"; 347 | SKIP_INSTALL = YES; 348 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 349 | SWIFT_VERSION = 5.0; 350 | }; 351 | name = Debug; 352 | }; 353 | 2EE9CCC71B200F7A00D1FDF6 /* Release */ = { 354 | isa = XCBuildConfiguration; 355 | buildSettings = { 356 | CLANG_ENABLE_MODULES = YES; 357 | DEFINES_MODULE = YES; 358 | DYLIB_COMPATIBILITY_VERSION = 1; 359 | DYLIB_CURRENT_VERSION = 1; 360 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 361 | INFOPLIST_FILE = GCDTimer/Info.plist; 362 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 363 | IPHONEOS_DEPLOYMENT_TARGET = 15.6; 364 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 365 | PRODUCT_NAME = "$(TARGET_NAME)"; 366 | SKIP_INSTALL = YES; 367 | SWIFT_VERSION = 5.0; 368 | }; 369 | name = Release; 370 | }; 371 | 2EE9CCC91B200F7A00D1FDF6 /* Debug */ = { 372 | isa = XCBuildConfiguration; 373 | buildSettings = { 374 | FRAMEWORK_SEARCH_PATHS = ( 375 | "$(SDKROOT)/Developer/Library/Frameworks", 376 | "$(inherited)", 377 | ); 378 | GCC_PREPROCESSOR_DEFINITIONS = ( 379 | "DEBUG=1", 380 | "$(inherited)", 381 | ); 382 | INFOPLIST_FILE = GCDTimerTests/Info.plist; 383 | IPHONEOS_DEPLOYMENT_TARGET = 15.6; 384 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 385 | PRODUCT_NAME = "$(TARGET_NAME)"; 386 | SWIFT_VERSION = 5.0; 387 | }; 388 | name = Debug; 389 | }; 390 | 2EE9CCCA1B200F7A00D1FDF6 /* Release */ = { 391 | isa = XCBuildConfiguration; 392 | buildSettings = { 393 | FRAMEWORK_SEARCH_PATHS = ( 394 | "$(SDKROOT)/Developer/Library/Frameworks", 395 | "$(inherited)", 396 | ); 397 | INFOPLIST_FILE = GCDTimerTests/Info.plist; 398 | IPHONEOS_DEPLOYMENT_TARGET = 15.6; 399 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 400 | PRODUCT_NAME = "$(TARGET_NAME)"; 401 | SWIFT_VERSION = 5.0; 402 | }; 403 | name = Release; 404 | }; 405 | /* End XCBuildConfiguration section */ 406 | 407 | /* Begin XCConfigurationList section */ 408 | 2EE9CCA91B200F7A00D1FDF6 /* Build configuration list for PBXProject "GCDTimer" */ = { 409 | isa = XCConfigurationList; 410 | buildConfigurations = ( 411 | 2EE9CCC31B200F7A00D1FDF6 /* Debug */, 412 | 2EE9CCC41B200F7A00D1FDF6 /* Release */, 413 | ); 414 | defaultConfigurationIsVisible = 0; 415 | defaultConfigurationName = Release; 416 | }; 417 | 2EE9CCC51B200F7A00D1FDF6 /* Build configuration list for PBXNativeTarget "GCDTimer" */ = { 418 | isa = XCConfigurationList; 419 | buildConfigurations = ( 420 | 2EE9CCC61B200F7A00D1FDF6 /* Debug */, 421 | 2EE9CCC71B200F7A00D1FDF6 /* Release */, 422 | ); 423 | defaultConfigurationIsVisible = 0; 424 | defaultConfigurationName = Release; 425 | }; 426 | 2EE9CCC81B200F7A00D1FDF6 /* Build configuration list for PBXNativeTarget "GCDTimerTests" */ = { 427 | isa = XCConfigurationList; 428 | buildConfigurations = ( 429 | 2EE9CCC91B200F7A00D1FDF6 /* Debug */, 430 | 2EE9CCCA1B200F7A00D1FDF6 /* Release */, 431 | ); 432 | defaultConfigurationIsVisible = 0; 433 | defaultConfigurationName = Release; 434 | }; 435 | /* End XCConfigurationList section */ 436 | }; 437 | rootObject = 2EE9CCA61B200F7A00D1FDF6 /* Project object */; 438 | } 439 | -------------------------------------------------------------------------------- /GCDTimer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /GCDTimer.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /GCDTimer.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /GCDTimer.xcodeproj/xcshareddata/xcschemes/GCDTimer.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 | 75 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 94 | 100 | 101 | 102 | 103 | 105 | 106 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /GCDTimer/GCDTimer.h: -------------------------------------------------------------------------------- 1 | // 2 | // GCDTimer.h 3 | // GCDTimer 4 | // 5 | // Created by Hemanta Sapkota on 4/06/2015. 6 | // Copyright (c) 2023 Hemanta Sapkota. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for GCDTimer. 12 | FOUNDATION_EXPORT double GCDTimerVersionNumber; 13 | 14 | //! Project version string for GCDTimer. 15 | FOUNDATION_EXPORT const unsigned char GCDTimerVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /GCDTimer/GCDTimer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GCDTimer.swift 3 | // GCDTimer 4 | // 5 | // Created by Hemanta Sapkota on 4/06/2015. 6 | // Copyright (c) 2023 Hemanta Sapkota. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | /** 12 | * GCD Timer. 13 | */ 14 | open class GCDTimer { 15 | 16 | // Swift 3 has removed support for dispatch_once. This class does the same thing ( roughly ) 17 | class Once { 18 | 19 | private var _onceTracker = [String]() 20 | 21 | // From: http://stackoverflow.com/questions/37886994/dispatch-once-in-swift-3 22 | public func doIt(token: String, block:()->Void) { 23 | objc_sync_enter(self); defer { objc_sync_exit(self) } 24 | 25 | if _onceTracker.contains(token) { 26 | return 27 | } 28 | 29 | _onceTracker.append(token) 30 | block() 31 | 32 | } 33 | 34 | public func reset(token: String) { 35 | if let tokenIndex = _onceTracker.firstIndex(of: token) { 36 | _onceTracker.remove(at: tokenIndex) 37 | } 38 | } 39 | 40 | } 41 | 42 | /// A serial queue for processing our timer tasks 43 | fileprivate static let gcdTimerQueue = DispatchQueue(label: "gcdTimerQueue", attributes: []) 44 | 45 | /// Timer Source 46 | public let timerSource = DispatchSource.makeTimerSource(flags: DispatchSource.TimerFlags(rawValue: UInt(0)), queue: GCDTimer.gcdTimerQueue) 47 | 48 | /// Default internal: 1 second 49 | fileprivate var interval:Double = 1 50 | 51 | /// dispatch_once alternative 52 | fileprivate let once = Once() 53 | 54 | /// Event that is executed repeatedly 55 | fileprivate var event: (() -> Void)! 56 | open var Event: (() -> Void) { 57 | get { 58 | return event 59 | } 60 | set { 61 | event = newValue 62 | 63 | self.timerSource.schedule(deadline: DispatchTime.now(), repeating: DispatchTimeInterval.seconds(Int(interval))) 64 | self.timerSource.setEventHandler { 65 | self.event() 66 | } 67 | } 68 | } 69 | 70 | /** 71 | Init a GCD timer in a paused state. 72 | 73 | - parameter intervalInSecs: Time interval in seconds 74 | 75 | - returns: self 76 | */ 77 | public init(intervalInSecs: Double) { 78 | self.interval = intervalInSecs 79 | } 80 | 81 | /** 82 | Start the timer. 83 | */ 84 | open func start() { 85 | once.doIt(token: "com.laex.GCDTimer") { () in 86 | self.timerSource.resume() 87 | } 88 | } 89 | 90 | /** 91 | Pause the timer. 92 | */ 93 | open func pause() { 94 | timerSource.suspend() 95 | once.reset(token: "com.laex.GCDTimer") 96 | } 97 | 98 | /** 99 | Executes a block after a delay on the main thread. 100 | */ 101 | open class func delay(_ afterSecs: Double, block: @escaping ()->()) { 102 | let delayTime = DispatchTime.now() + Double(Int64(afterSecs * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC) 103 | DispatchQueue.main.asyncAfter(deadline: delayTime, execute: block) 104 | } 105 | 106 | /** 107 | Executes a block after a delay on a specified queue. 108 | */ 109 | open class func delay(_ afterSecs: Double, queue: DispatchQueue, block: @escaping ()->()) { 110 | let delayTime = DispatchTime.now() + Double(Int64(afterSecs * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC) 111 | queue.asyncAfter(deadline: delayTime, execute: block) 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /GCDTimer/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.laex.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 0.1 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /GCDTimerTests/GCDTimerTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GCDTimerTests.swift 3 | // GCDTimerTests 4 | // 5 | // Created by Hemanta Sapkota on 4/06/2015. 6 | // Copyright (c) 2023 Hemanta Sapkota. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class GCDTimerTests: 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 testTimerIsStartedOnce() { 25 | let timer = GCDTimer(intervalInSecs: 1) 26 | 27 | var index = 0 28 | timer.Event = { 29 | index += 1 30 | print("Hello \(index)") 31 | } 32 | 33 | // start the timer three times 34 | timer.start() 35 | timer.start() 36 | timer.start() 37 | 38 | RunLoop.current.run(until: Date(timeIntervalSinceNow: 5)) 39 | XCTAssert(index >= 5, "Event should have run for at least 5 seconds.") 40 | 41 | index = 0 42 | 43 | timer.pause() 44 | 45 | timer.start() 46 | 47 | RunLoop.current.run(until: Date(timeIntervalSinceNow: 5)) 48 | XCTAssert(index >= 5, "Event should have run for at least 5 seconds.") 49 | } 50 | 51 | func testTimer1() { 52 | let timer = GCDTimer(intervalInSecs: 1) 53 | 54 | var index = 0 55 | timer.Event = { 56 | index += 1 57 | print("Hello \(index)") 58 | } 59 | 60 | timer.start() 61 | 62 | RunLoop.current.run(until: Date(timeIntervalSinceNow: 10)) 63 | 64 | XCTAssert(index > 10, "Event should have run for at least 10 seconds.") 65 | } 66 | 67 | func testTimer2() { 68 | let timer = GCDTimer(intervalInSecs: 0.1) 69 | 70 | var index = 0 71 | timer.Event = { 72 | index += 1 73 | print("Hello \(index)") 74 | } 75 | 76 | timer.start() 77 | 78 | RunLoop.current.run(until: Date(timeIntervalSinceNow: 1)) 79 | 80 | XCTAssert(index > 10, "Event should have run for at least 1 seconds.") 81 | } 82 | 83 | func testAutofinishingTimer() { 84 | let timer = GCDTimer(intervalInSecs: 1) 85 | 86 | var index = 0 87 | timer.Event = { 88 | index += 1 89 | print("Timer is running: \(index)") 90 | if index == 10 { 91 | timer.pause() 92 | index = 0 93 | } 94 | } 95 | 96 | timer.start() 97 | 98 | RunLoop.current.run(until: Date(timeIntervalSinceNow: 10)) 99 | 100 | XCTAssert(index == 0, "Timer should have paused.") 101 | } 102 | 103 | func testDelayedExecution() { 104 | var index = 0 105 | GCDTimer.delay(2, block: { () -> Void in 106 | index += 1 107 | }) 108 | 109 | RunLoop.current.run(until: Date(timeIntervalSinceNow: 1)) 110 | 111 | XCTAssert(index == 0, "The block shouldn't have been executed") 112 | 113 | RunLoop.current.run(until: Date(timeIntervalSinceNow: 2)) 114 | 115 | XCTAssert(index == 1, "The block should have executed after 2 secs.") 116 | } 117 | 118 | func testPerformanceExample() { 119 | // This is an example of a performance test case. 120 | self.measure() { 121 | // Put the code you want to measure the time of here. 122 | let timer = GCDTimer(intervalInSecs: 0.001) 123 | var count = 0 124 | 125 | timer.Event = { 126 | count += 1 127 | if count >= 1000 { 128 | timer.pause() 129 | } 130 | } 131 | 132 | timer.start() 133 | 134 | // Wait for timer to complete 1000 iterations 135 | RunLoop.current.run(until: Date(timeIntervalSinceNow: 5)) 136 | } 137 | } 138 | 139 | func testTimerCreationPerformance() { 140 | self.measure { 141 | for _ in 0..<100 { 142 | let timer = GCDTimer(intervalInSecs: 0.01) 143 | // Make sure we set an Event handler to properly initialize the timer 144 | timer.Event = {} 145 | } 146 | } 147 | } 148 | 149 | func testTimerStartStopPerformance() { 150 | self.measure { 151 | let timer = GCDTimer(intervalInSecs: 0.01) 152 | // Set an Event handler before starting the timer 153 | timer.Event = {} 154 | 155 | for _ in 0..<50 { 156 | timer.start() 157 | timer.pause() 158 | } 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /GCDTimerTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.laex.$(PRODUCT_NAME:rfc1034identifier) 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) 2017 Hemanta Sapkota 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 | [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 2 | 3 | ### GCDTimer ### 4 | Well tested Grand Central Dispatch (GCD) Timer in Swift. Checkout the [test](GCDTimerTests/GCDTimerTests.swift) file. 5 | 6 | ### Usage ### 7 | 8 | #### Long running timer #### 9 | ```swift 10 | import GCDTimer 11 | 12 | class Demo { 13 | 14 | init() { 15 | let timer = GCDTimer(intervalInSecs: 20) 16 | 17 | timer.Event = { 18 | println("Hello World") 19 | 20 | // Send some data to the server 21 | } 22 | 23 | timer.start() 24 | 25 | //Don't forget to pause the timer in the AppDelegate:applicationWillResignActive(application: UIApplication) method. 26 | } 27 | 28 | } 29 | 30 | ``` 31 | 32 | #### Autofinishing timer #### 33 | 34 | ```swift 35 | import GCDTimer 36 | 37 | class Demo { 38 | 39 | init() { 40 | let timer = GCDTimer(intervalInSecs: 2) 41 | 42 | timer.Event = { 43 | timer.pause() 44 | //Process after finishing the timer 45 | } 46 | 47 | timer.start() 48 | } 49 | 50 | } 51 | ``` 52 | 53 | #### Dispatch After - Delay #### 54 | 55 | ```swift 56 | var index = 0 57 | GCDTimer.delay(2) { 58 | index += 1 59 | } 60 | ``` 61 | 62 | ### Installation ### 63 | 64 | * Add ```github "hemantasapkota/GCDTimer"``` to your ```cartfile``` 65 | * Execute ```carthage update``` 66 | 67 | ### Example ### 68 | The example shows how to use GCDTimer to periodically poll newly submitted items from Hacker News. 69 | 70 | ![ExampleSS](Example/GCDTimerExample/ExampleSS.png) 71 | 72 | ### License ### 73 | The MIT License (MIT) 74 | 75 | Copyright (c) 2023 Hemanta Sapkota 76 | 77 | Permission is hereby granted, free of charge, to any person obtaining a copy 78 | of this software and associated documentation files (the "Software"), to deal 79 | in the Software without restriction, including without limitation the rights 80 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 81 | copies of the Software, and to permit persons to whom the Software is 82 | furnished to do so, subject to the following conditions: 83 | 84 | The above copyright notice and this permission notice shall be included in all 85 | copies or substantial portions of the Software. 86 | 87 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 88 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 89 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 90 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 91 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 92 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 93 | SOFTWARE. 94 | 95 | --------------------------------------------------------------------------------