Skip to content

bakkenbaeck/SweetFoundation

Repository files navigation

SweetFoundation

Version License Platform

Usage

Math helpers

Simple helpers to convert degrees to radians and vice-versa.

Math.degreesToRadians()
Math.radiansToDegrees()

DispatchQueue helpers

Dispatch async after using seconds (Double), instead of dealing with DispatchTime.

DispatchQueue.asyncAfter(seconds: 1.5) { }

Serialisation

We include a simple JSON to String serialiser that guarantees the order of dictionary keys to be alphabetical. This is essential when signing or hashing payloads.

let hashableString = OrderedSerializer.string(from: jsonPayload)

String range helpers

We've added a computed property to request the whole range of a string:

let range = "This is a test string".wholeRange

Also to avoid having to do constant casts to String or NSString to get the range type you need, we've added two simple methods to convert between them:

// from Range<String.Index> to NSRange
let range = string.range(of: "substring")
let nsRange = range.nsRange(on: string)

// from NSRange to Range<String.Index>
let range = nsRange.range(on: string as NSString)

Base64 with or without padding

Sometimes you need to deal with base64 strings without the padding.

// Generate base64 string without padding from a Data structure.
let noPadding = "This is a test string".data(using: .utf8)!.base64EncodedStringWithoutPadding()

// sometimes you want the padding back.
noPadding.paddedForBase64

Installation

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

pod 'SweetFoundation'

SweetFoundation is also available through Carthage. To install it, simply add the following line to your Cartfile:

github "SweetOrg/SweetFoundation"

License

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

Author

Bakken & Bæck, @SweetOrg