Just wrap the SequenceType in your loop with the Progress SequenceType and you’ll automatically get beautiful progress bars.
Updating the progress bar does not work in the Xcode console because it does not support the cursor movements. If you want it to look nice run it in a real terminal.
Example
Just take a regular loop like this for i in 1...9 { ... and wrap the 1...9 range in the Progress type and you’ll automatically get a nice progress bar.
It also works with all the other types adopting the CollectionType protocol like dictionarys: Progress(["key": "value", "key2": "also value"]) and arrays: Progress([1, 52, 6, 26, 1]).
You can also create the progress bar manually without a sequence type:
var bar = ProgressBar(count: 4)
for i in 0...3 {
bar.next()
sleep(1)
}
Configuration
You can configure the progress bar by combining single building blocks of type ProgressElementType.
Progress.swift
Just wrap the
SequenceTypein your loop with theProgress SequenceTypeand you’ll automatically get beautiful progress bars.Updating the progress bar does not work in the Xcode console because it does not support the cursor movements. If you want it to look nice run it in a real terminal.
Example
Just take a regular loop like this
for i in 1...9 { ...and wrap the1...9range in theProgresstype and you’ll automatically get a nice progress bar.Creates this output:
It also works with all the other types adopting the
CollectionTypeprotocol like dictionarys:Progress(["key": "value", "key2": "also value"])and arrays:Progress([1, 52, 6, 26, 1]).You can also create the progress bar manually without a sequence type:
Configuration
You can configure the progress bar by combining single building blocks of type
ProgressElementType.Either by setting a default configuration:
which creates the following result:
or by providing a specific configuration in the Process initializer:
resulting in something like this:
Available
ProgressElementTypeelements:ProgressBarLine(The actual bar. E.g. “[———————- ]”).ProgressIndex(The current index & overall count. E.g. “2 of 3”).ProgressPercent(The progress in percent. E.g. “60%”).ProgressTimeEstimates(Estimated time remaining & items per second. E.g. “ETA: 00:00:02 (at 1.00 it/s)”).ProgressString(Adds an arbitrary string to the progress bar).Installation
Cocoapods
Progress.swift is available through CocoaPods. To install it, simply add the following line to your Podfile:
Carthage
To integrate Progress.swift into your Xcode project using Carthage, specify it in your Cartfile:
Run
carthage updateto build the framework and drag the builtProgress.frameworkinto your Xcode project.Swift Package Manager
To install with the Swift Package Manager, add the following in your
Package.swift:Manual
You can also copy the
Progress.swiftfile into your Xcode project.Contribution
You are welcome to fork and submit pull requests.
Author
Justus Kandzi, justus.kandzi@gmail.com
License
Progress.swift is available under the MIT license. See the LICENSE file for more info.