Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Mar 6, 2018
2 parents 6dcd530 + 186b8b1 commit 5b83017
Show file tree
Hide file tree
Showing 7 changed files with 409 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Configs/Repeat.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.1.0</string>
<string>0.3.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
70 changes: 64 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,31 @@ Main features offered by Repeat are:
* Ability to pause , start , resume and reset our timer without allocating a new instance.
* Ability to set different repeat modes (`infinite` : infinite sequence of fires, at regular intervals, `finite` : a finite sequence of fires, at regular intervals, `once` : a single fire events at specified interval since start).

## Other Libraries You May Like

I'm also working on several other projects you may like.
Take a look below:

<p align="center" >

| Library | Description |
|-----------------|--------------------------------------------------|
| [**SwiftDate**](https://github.com/malcommac/SwiftDate) | The best way to manage date/timezones in Swift |
| [**Hydra**](https://github.com/malcommac/Hydra) | Write better async code: async/await & promises |
| [**Flow**](https://github.com/malcommac/Flow) | A new declarative approach to table managment. Forget datasource & delegates. |
| [**SwiftRichString**](https://github.com/malcommac/SwiftRichString) | Elegant & Painless NSAttributedString in Swift |
| [**SwiftLocation**](https://github.com/malcommac/SwiftLocation) | Efficient location manager |
| [**SwiftMsgPack**](https://github.com/malcommac/SwiftMsgPack) | Fast/efficient msgPack encoder/decoder |
</p>

## Examples

### Create single fire timer

The following code create a timer which fires a single time after 5 seconds.

```swift
Repeat.once(after: .seconds(5)) { timer in
Repeater.once(after: .seconds(5)) { timer in
// do something
}
```
Expand All @@ -37,7 +54,7 @@ Repeat.once(after: .seconds(5)) { timer in
The following code create a recurrent timer: it will fire every 10 minutes for 5 times, then stops.

```swift
Repeat.every(.minutes(10), count: 5) { timer in
Repeater.every(.minutes(10), count: 5) { timer in
// do something
}
```
Expand All @@ -47,7 +64,7 @@ Repeat.every(.minutes(10), count: 5) { timer in
The following code create a recurrent timer which fires every hour until it is manually stopped .

```swift
Repeat.every(.hours(1)) { timer in
Repeater.every(.hours(1)) { timer in
// do something
}
```
Expand All @@ -57,7 +74,7 @@ Repeat.every(.hours(1)) { timer in
You can create a new instance of timer and start as needed by calling the `start()` function.

```swift
let timer = Repeat(interval: .seconds(5), mode: .infinite) { _ in
let timer = Repeater(interval: .seconds(5), mode: .infinite) { _ in
// do something
}
timer.start()
Expand All @@ -67,9 +84,15 @@ Other functions are:

* `start()`: start a paused or newly created timer
* `pause()`: pause a running timer
* `reset(_ interval: Interval)`: reset a running timer, change the interval and restart again
* `reset(_ interval: Interval, restart: Bool)`: reset a running timer, change the interval and restart again if set.
* `fire()`: manually fire an event of the timer from an external source

Properties:

* `.id`: unique identifier of the timer
* `.mode`: define the type of timer (`infinite`,`finite`,`once`)
* `.remainingIterations`: for a `.finite` mode it contains the remaining number of iterations before it finishes.

### Adding/Removing Observers

By default a new timer has a single observer specified by the init functions. You can, however, create additional observer by using `observe()` function. The result of this call is a token identifier you can use to remove the observer in a second time.
Expand All @@ -87,6 +110,23 @@ You can remove an observer by using the token:
```swift
timer.remove(token)
```

### Observing state change

Each timer can be in one of the following states, you can observe via `.state` property:

* `.paused`: timer is in idle (never started yet) or paused
* `.running`: timer is currently active and running
* `.finished`: timer lifecycle is finished (it's valid for a finite/once state timer)

You can listen for state change by assigning a function callback for `.onStateChanged` property.

```swift
timer.onStateChanged = { (timer,newState) in
// your own code
}
```

## Requirements

Repeat is compatible with Swift 4.x.
Expand All @@ -97,6 +137,24 @@ All Apple platforms are supported:
* watchOS 2.0+
* tvOS 9.0+

## Latest Version

Latest version of Repeat is [0.3.0](https://github.com/malcommac/Repeat/releases/tag/0.3.0) published on 2018/03/05.

**Changelog - 0.3.0**:

* [#7](https://github.com/malcommac/Repeat/issues/7): Renamed `Repeat` in `Repeater` in order to avoid collision with `Swift.Repeat`.

**Changelog - 0.2.1**:

* [#6](https://github.com/malcommac/Repeat/issues/6): Fixed crash on `deinit()` a running timer.

**Changelog - 0.2.0**:

* [#1](https://github.com/malcommac/Repeat/issues/3): Fixed CocoaPods installation
* [#2](https://github.com/malcommac/Repeat/issues/2): Fixed leaks with GCD while deallocating dispatch queue
* [#3](https://github.com/malcommac/Repeat/issues/3): Refactoring timer's state using a `State` enum which define the possible states of the timer (`paused`,`running` or `finished`).

## Installation

<a name="cocoapods" />
Expand All @@ -106,7 +164,7 @@ All Apple platforms are supported:
[CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like Repeat in your projects. You can install it with the following command:

```bash
$ gem install cocoapods
$ sudo gem install cocoapods
```

> CocoaPods 1.0.1+ is required to build Repeat.
Expand Down
4 changes: 2 additions & 2 deletions Repeat.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Repeat"
s.version = "0.1.0"
s.version = "0.3.0"
s.summary = "Modern NSTimer alternative in Swift"
s.description = <<-DESC
Repeat is a modern alternative to NSTimer; no strong references, multiple observers, reusable instances with start/stop/pause support in swifty syntax.
Expand All @@ -13,7 +13,7 @@ Pod::Spec.new do |s|
s.osx.deployment_target = "10.9"
s.watchos.deployment_target = "2.0"
s.tvos.deployment_target = "9.0"
s.source = { :git => ".git", :tag => s.version.to_s }
s.source = { :git => "https://github.com/malcommac/Repeat.git", :tag => s.version.to_s }
s.source_files = "Sources/**/*"
s.frameworks = "Foundation"
s.swift_version = '4.0'
Expand Down
43 changes: 29 additions & 14 deletions Repeat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

/* Begin PBXBuildFile section */
52D6D9871BEFF229002C0205 /* Repeat.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6D97C1BEFF229002C0205 /* Repeat.framework */; };
8933C7851EB5B820000D00A4 /* Repeat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8933C7841EB5B820000D00A4 /* Repeat.swift */; };
8933C7861EB5B820000D00A4 /* Repeat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8933C7841EB5B820000D00A4 /* Repeat.swift */; };
8933C7871EB5B820000D00A4 /* Repeat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8933C7841EB5B820000D00A4 /* Repeat.swift */; };
8933C7881EB5B820000D00A4 /* Repeat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8933C7841EB5B820000D00A4 /* Repeat.swift */; };
64A18884204D313800DC2B4B /* Repeater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64A18883204D313800DC2B4B /* Repeater.swift */; };
64A18885204D313800DC2B4B /* Repeater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64A18883204D313800DC2B4B /* Repeater.swift */; };
64A18886204D313800DC2B4B /* Repeater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64A18883204D313800DC2B4B /* Repeater.swift */; };
64A18887204D313800DC2B4B /* Repeater.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64A18883204D313800DC2B4B /* Repeater.swift */; };
8933C78E1EB5B82C000D00A4 /* RepeatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8933C7891EB5B82A000D00A4 /* RepeatTests.swift */; };
8933C78F1EB5B82C000D00A4 /* RepeatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8933C7891EB5B82A000D00A4 /* RepeatTests.swift */; };
8933C7901EB5B82D000D00A4 /* RepeatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8933C7891EB5B82A000D00A4 /* RepeatTests.swift */; };
Expand Down Expand Up @@ -49,7 +49,7 @@
52D6D9E21BEFFF6E002C0205 /* Repeat.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Repeat.framework; sourceTree = BUILT_PRODUCTS_DIR; };
52D6D9F01BEFFFBE002C0205 /* Repeat.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Repeat.framework; sourceTree = BUILT_PRODUCTS_DIR; };
52D6DA0F1BF000BD002C0205 /* Repeat.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Repeat.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8933C7841EB5B820000D00A4 /* Repeat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Repeat.swift; sourceTree = "<group>"; };
64A18883204D313800DC2B4B /* Repeater.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Repeater.swift; path = Repeat/Repeater.swift; sourceTree = "<group>"; };
8933C7891EB5B82A000D00A4 /* RepeatTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RepeatTests.swift; sourceTree = "<group>"; };
AD2FAA261CD0B6D800659CF4 /* Repeat.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Repeat.plist; sourceTree = "<group>"; };
AD2FAA281CD0B6E100659CF4 /* RepeatTests.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = RepeatTests.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -149,7 +149,7 @@
8933C7811EB5B7E0000D00A4 /* Sources */ = {
isa = PBXGroup;
children = (
8933C7841EB5B820000D00A4 /* Repeat.swift */,
64A18883204D313800DC2B4B /* Repeater.swift */,
);
path = Sources;
sourceTree = "<group>";
Expand Down Expand Up @@ -351,23 +351,23 @@
TargetAttributes = {
52D6D97B1BEFF229002C0205 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0920;
};
52D6D9851BEFF229002C0205 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
};
52D6D9E11BEFFF6E002C0205 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0920;
};
52D6D9EF1BEFFFBE002C0205 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0920;
};
52D6DA0E1BF000BD002C0205 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0920;
};
DD7502791C68FCFC006590AF = {
CreatedOnToolsVersion = 7.2.1;
Expand Down Expand Up @@ -459,7 +459,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8933C7851EB5B820000D00A4 /* Repeat.swift in Sources */,
64A18884204D313800DC2B4B /* Repeater.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -475,23 +475,23 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8933C7871EB5B820000D00A4 /* Repeat.swift in Sources */,
64A18886204D313800DC2B4B /* Repeater.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
52D6D9EB1BEFFFBE002C0205 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8933C7881EB5B820000D00A4 /* Repeat.swift in Sources */,
64A18887204D313800DC2B4B /* Repeater.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
52D6DA0A1BF000BD002C0205 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8933C7861EB5B820000D00A4 /* Repeat.swift in Sources */,
64A18885204D313800DC2B4B /* Repeater.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -687,6 +687,7 @@
52D6D9941BEFF229002C0205 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = Configs/RepeatTests.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
Expand All @@ -700,6 +701,7 @@
52D6D9951BEFF229002C0205 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
INFOPLIST_FILE = Configs/RepeatTests.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
Expand All @@ -714,6 +716,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -726,6 +729,7 @@
PRODUCT_NAME = Repeat;
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
Expand All @@ -736,6 +740,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=watchos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -759,6 +764,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -771,6 +777,7 @@
PRODUCT_NAME = Repeat;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
Expand All @@ -781,6 +788,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -804,6 +812,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
Expand All @@ -819,6 +828,7 @@
PRODUCT_NAME = Repeat;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
};
name = Debug;
Expand All @@ -827,6 +837,7 @@
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
Expand All @@ -850,6 +861,7 @@
DD7502831C68FCFC006590AF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = Configs/RepeatTests.plist;
Expand All @@ -865,6 +877,7 @@
DD7502841C68FCFC006590AF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = Configs/RepeatTests.plist;
Expand All @@ -881,6 +894,7 @@
DD7502961C690C7A006590AF /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
INFOPLIST_FILE = Configs/RepeatTests.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.Repeat.Repeat-tvOS-Tests";
Expand All @@ -894,6 +908,7 @@
DD7502971C690C7A006590AF /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
INFOPLIST_FILE = Configs/RepeatTests.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.Repeat.Repeat-tvOS-Tests";
Expand Down
Binary file not shown.
Loading

0 comments on commit 5b83017

Please sign in to comment.