Simple helpers to convert degrees to radians and vice-versa.
Math.degreesToRadians()
Math.radiansToDegrees()
Dispatch async after using seconds (Double
), instead of dealing with DispatchTime
.
DispatchQueue.asyncAfter(seconds: 1.5) { }
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)
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)
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
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"
SweetFoundation is available under the MIT license. See the LICENSE file for more info.
Bakken & Bæck, @SweetOrg