Skip to content

A collection of Swift utility extensions and functions

License

Notifications You must be signed in to change notification settings

pual/PXDToolkit

 
 

Repository files navigation

PXDToolkit

CI Status Version License Platform Swift Twitter

Requirements

iOS 8.0 or Greater
Swift 3.1

If you are using Swift 2.3 use PXDToolkit version 0.2.1

Installation

PXDToolkit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "PXDToolkit", '~> 0.3'

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 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'] = '3.1' # or '2.3'
    end
  end
end

Usage

Int

**Random Int between 0 and 10** ```swift let randomInt = 10.random ``` ----------

Array

**Get random element from Array** ```swift let randomElement = ["A", "B", "C"].randomElement ``` **Get 2 random elements from Array** ```swift let randomElements = ["A", "B", "C"].randomElements(2) ``` **Shuffle array (order elements randomly)** ```swift let shuffledArray = ["A", "B", "C"].shuffled ``` ----------

UIColor

**Color from hex int value** ```swift let darkRedColor = UIColor(hex: 0xAA0000) ``` **Color from hex int value with alpha** ```swift let darkRedColor = UIColor(hex: 0xAA0000, alpha: 0.5) ``` **Hex string from Color** ```swift let redColorHexString = UIColor.redColor().hexString ``` ----------

CGFloat

**Degrees to Radians** ```swift let angleRadians = CGFloat(180).degreesToRadians ``` **Radians to Degrees** ```swift let degrees = CGFloat(3.1415).radiansToDegrees ``` ----------

NSLocalizedString

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** ```swift print(LocalizedString("GREETING")) // "Hello" ``` And this: **Get localized string with dynamic parts** ```swift print(LocalizedString("TEMPERATURE", arguments:[21.8, "Paris"])) // "It is 21.8°C in Paris" ``` ----------

UIApplication

**Get App version** ```swift let appVersion = UIApplication.appVersion() ``` **Get Build number** ```swift let buildNumber = UIApplication.appBuild() ``` ----------

Timing Functions

**Delay**

Delays the execution of the closure. Always runs on the main thread.

delay(seconds: 2) {
   print("hello!")
}

Author

Jörn Schoppe, [email protected]

Comments and suggestions are highly welcome!

License

PXDToolkit is available under the MIT license. See the LICENSE file for more info.

About

A collection of Swift utility extensions and functions

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 82.9%
  • Ruby 13.4%
  • Objective-C 3.7%