PXDToolkit
A collection of Swift utility extensions and functions
Install / Use
/learn @pixeldock/PXDToolkitREADME
PXDToolkit
Requirements
iOS 8.0 or Greater
Swift 4
If you are using Swift 3.x use PXDToolkit version 0.3.1
If you are using Swift 2.3 use PXDToolkit version 0.2.1
Integration
CocoaPods
PXDToolkit is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod "PXDToolkit", '~> 0.4'
If you are using Swift 3.x use PXDToolkit version 0.3.1:
pod "PXDToolkit", '0.3.1'
If you are using Swift 2.3 use PXDToolkit version 0.2.1:
pod "PXDToolkit", '0.2.1'
Add this to your podfile (if it is not already there) to make the pod work with Swift 4, 3.1 (or Swift 2.3):
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.0' # or the Swift version you are using
end
end
end
Carthage
You can use Carthage to install PXDToolkit by adding it to your Cartfile:
github "pixeldock/PXDToolkit"
Usage
<h4>Int</h4> Random Int between 0 and 10let randomInt = 10.random
<h4>Array</h4> Get random element from Array
let randomElement = ["A", "B", "C"].randomElement
Get 2 random elements from Array
let randomElements = ["A", "B", "C"].randomElements(2)
Get shuffled array (order elements randomly)
let shuffledArray = ["A", "B", "C"].shuffled
<h4>UIColor</h4> Color from hex int value
let darkRedColor = UIColor(hex: 0xAA0000)
Color from hex int value with alpha
let darkRedColor = UIColor(hex: 0xAA0000, alpha: 0.5)
Hex string from Color
let redColorHexString = UIColor.redColor().hexString
<h4>CGFloat</h4> Degrees to Radians
let angleRadians = CGFloat(180).degreesToRadians
Radians to Degrees
let degrees = CGFloat(3.1415).radiansToDegrees
<h4>NSLocalizedString</h4> If your *Localizable.strings* file contains this:
"GREETING" = "Hello";
"TEMPERATURE" = "It is %f.01°C in %@";
You can do this: Get localized string for a key
print(LocalizedString("GREETING")) // "Hello"
And this: Get localized string with dynamic parts
print(LocalizedString("TEMPERATURE", arguments:[21.8, "Paris"])) // "It is 21.8°C in Paris"
<h4>UIApplication</h4> Get App version
let appVersion = UIApplication.appVersion()
Get Build number
let buildNumber = UIApplication.appBuild()
<h4>Timing Functions</h4> Delay
Delays the execution of the closure. Always runs on the main thread.
delay(seconds: 2) {
print("hello!")
}
Author
Jörn Schoppe, joern@pixeldock.com
Comments and suggestions are highly welcome!
License
PXDToolkit is available under the MIT license. See the LICENSE file for more info.