Skip to content
Helpers and sugar for the Foundation framework
Swift Other
  1. Swift 98.1%
  2. Other 1.9%
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
Demo.xcodeproj
Sources
SweetFoundation
SweetFoundationMac
Tests
.gitignore
.slather.yml
.swift-version
CHANGELOG.md
CONTRIBUTING.md
LICENSE.md
Package.swift
README.md
SweetFoundation.podspec

README.md

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

You can’t perform that action at this time.