Want to take your software engineering career to the next level? Join the mailing list for career tips & advice Click here


:coffee: Something sweet that goes great with your Cocoa

Subscribe to updates I use Sugar

Statistics on Sugar

Number of watchers on Github 907
Number of open issues 2
Average time to close an issue 7 days
Main language Swift
Average time to merge a PR about 15 hours
Open pull requests 6+
Closed pull requests 8+
Last commit over 2 years ago
Repo Created almost 5 years ago
Repo Last Updated about 2 years ago
Size 276 KB
Homepage https://github.co...
Organization / Authorhyperoslo
Latest Release4.0.0
Page Updated
Do you use Sugar? Leave a review!
View open issues (2)
View Sugar activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Software engineers: It's time to get promoted. Starting NOW! Subscribe to my mailing list and I will equip you with tools, tips and actionable advice to grow in your career.
Evaluating Sugar for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)


Sugar is a sweetener for your Cocoa implementations.

CI Status Version Carthage Compatible License Platform Swift

Table of Contents

Hue Icon



let appName = Application.name             // CFBundleDisplayName : String
let appVersion = Application.version       // CFBundleShortVersionString : String
let appExecutable = Application.executable // CFBundleExecutable : String
let appBundle = Application.bundle         // CFBundleIdentifier : String
let appSchemes = Application.schemes       // CFBundleURLSchemes : [String]
let mainAppScheme = Application.mainScheme // CFBundleURLSchemes.first : String?

Gain easy access to main bundle information.


let pixelSize = Screen.pixelSize // CGSize(width: screenWidth * scale, height: screenHeight * scale)

Get the actual pixel information of the device screen.


if !Simulator.isRunning {
  // add device specific operations here

To easily exclude operations from when you as a developer runs the application in the simulator, not subscribing to push notification or running analytics operations etc.

Keyboard Observer

Observe keyboard showing and hiding events, and handle it

let handler = BasicKeyboardHandler()
handler.show = { [weak self] height in
  // move text fields up

handler.hide = { [weak self] in
  // move text fields back to original position

keyboardObserver = KeyboardObserver(handler: handler)

Currently support

  • BasicKeyboardHandler: basic UIView animation
  • InsetKeyboardHandler: animate UIScrollView insets
  • ConstraintKeyboardHandler: animate bottom layout constraint
  • CustomKeyboardHandler: custom handling

iOS Extensions


let view = UIView.optimize
  clipsToBounds = true
  layer.drawsAsynchronously = true
  opaque = true


+Rendering mode
image.original // imageWithRenderingMode(.AlwaysOriginal)
image.template // imageWithRenderingMode(.AlwaysTemplate)



let first: Int? = items.findFirst({ $0 > 10 })



if date1 < date2 {
  // do something
} else if date1 >= date2 {
  // do something else


let _ = 5.day
let _ = 3.week


let view = UIView()
view.width = 200
view.height = 200
view.x = 25
view.y = 25

print(view.width) // prints 200
print(view.height) // prints 200
print(view.x) // prints 25
print(view.y) // prints 25

Grand Central Dispatch

dispatch {
  // dispatch in main queue

dispatch(queue: .Background) {
  // dispatch in background queue

lazy var serialQueue = dispatch_queue_create("serialQueue", DISPATCH_QUEUE_SERIAL)
dispatch(queue: .Custom(serialQueue)) {
  // dispatch in a serial queue

Easy dispatching with grand central dispatch. Support all the regular global queues: Main, Interactive, Initiated, Utility, Background. And .Custom() for your own dispatch queues.


let string = localizedString("My Profile")
let formattedString = localizedString(key: "%d numbers", arguments: 10)

Swift access (pun intended) to NSLocalizedString, you will get more valid auto completion with this one, we promise.


var url = NSURL(string: "hyper.no")!
url ?= NSURL(string: "\\/http")
// url is equal to hyper.no

The ?= only assigns values if the right is not nil.


let acceptable = 200..<300
if acceptable.contains(response.statusCode) {
  // Status code is between 200 and 299.


if "ios@hyper.no".isEmail() {
  // Is email

let stringNumber = "1984"
if stringNumber.isNumber() {
  // Is a number

if stringNumber.matches("^[0-9]+$") {
  // Is a number

Shared Extensions


struct Object: Queueable {

  func process() -> Bool { return true }

let myQueue = [Object(), Object()]

Make your own processing queue with ease, just make your object conform the Queueable.

public protocol Queueable {
  func process() -> Bool


let urlString = "https://hyper.no"
let url = urlString.url

Highly inspired by / borrowed from Alamofire's implementation of URLStringConvertible.

Core Foundation

let string = "hyper/oslo"
string.length // 10
string.truncate(5) // hyper...
string.split(/) // ["hyper", oslo]

if string.isPresent {
  // do something

if string.contains("hyper") {
  // found hyper

var dirtyString = "   hyper   "
print(dirtyString.trim()) // prints "hyper"

Just some extra sugar on top of String for getting the length, truncating, trimming or splitting a String.

isPresent is the opposite of isEmpty.

contains and be used to check if a string contains a word or pharse.


class Swizzled: NSObject {

  override class func initialize() {
    struct Static {
      static var token: dispatch_once_t = 0

    if self !== Swizzled.self {

  dispatch_once(&Static.token) {
    Swizzler.swizzle("method", cls: self)

  dynamic func method() -> Bool {
    return true

  func swizzled_method() -> Bool {
    return false

let object = Swizzled()
object.method() // false

Everyday we are swizzling, this use to be mundane, now it just Swiftling, we mean, super fast.


let UIView().then {
  $0.backgroundColor = UIColor.blackColor()

This implementation is brought to you by @devxoul by his awesome Then repository.

Type Alias

public typealias JSONArray = [[String : AnyObject]]
public typealias JSONDictionary = [String : AnyObject]


if UITesting.isRunning {
  // tests are running
} else {
  // everything is fine, move along

To easily include or exclude operations for when you are running UI tests.


if UnitTesting.isRunning {
  // running test

func testPerformance() {
  let measurement = measure {
    // run operation

Check if you are running UniTests and to measure performance.


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

pod 'Sugar'

Sugar is also available through Carthage. To install just write into your Cartfile:

github "hyperoslo/Sugar"


Hyper Interaktiv AS, ios@hyper.no


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

Sugar open issues Ask a question     (View All Issues)
  • about 4 years Adress the elephant in the room, is Sugar starting to get obese ?
Sugar open pull requests (View All Pulls)
  • NSURL might return nil, a cause of crash
  • Removed unnecessary self
  • Adds a extension in Int to convert into a timer string
  • UIView extension for UINib initializer wrapper method.
  • Feature/uiimage check
  • Handling gesture the easy way
Sugar questions on Stackoverflow (View All Questions)
  • How can I use the same syntax sugar of Array or Dictionary in an Object in Swift?
  • Android Sugar ORM - Custom/prepopulated database in custom SD path
  • Want ti send mail using sugar CRM PHP mailer outside sugar folder
  • NullPointerException on BaseAdapter when reading from Sugar ORM database
  • gradle error while add sugar ORM 1.4 dependancy
  • using foreach to iterate simultaneously through multiple lists (syntax sugar)
  • Sugar ORM blocking UI Thread on init
  • Syntactical sugar for Doxygen to link a MonoBehaviour with Unity3D
  • Android: Sugar ORM No Such Table Exception
  • Sugar ORM droping a column on updating database
  • How to Migrate ORM Grendao to ORM Sugar in Android MySQLite, its Possible?
  • Conflict with sugar orm and gson
  • How to make a custom SugarCRM module that has a manually created Database table extend a Sugar Bean?
  • how to make multiple database tables using sugar orm
  • Is () => node.js specific syntactic sugar?
  • Mule and Sugar Connector: How get data on module relationship (Opportunities + Accounts)?
  • Forcing arithmetic precedence with syntactic sugar
  • Sugar ORM - Update record but ignore fields if null value
  • int.TryParse syntatic sugar
  • Syntactic sugar for Safe Navigation operator(&.)
  • Sugar CRM saves index.php file after migrating to new server
  • Sugar Record with base adapter
  • Sugar CRM: How can we do hierarchy using report to field?
  • No Such Column Sugar ORM only in release version
  • android: sugar orm library database migration not work
  • Using Sugar ORM with UUID or Joda-Time
  • Javascript's syntactic sugar for accessing object properties
  • What are "sugar", "desugar" terms in context of Java 8?
  • Sugar CRM Excel Plugin: Date Format
  • Docusing Plugin for Sugar CRM does not craete envelope with document
Sugar list of languages used
Sugar latest release notes
4.0.0 4.0.0

Merged pull requests

  • Fix bundle name https://github.com/hyperoslo/Sugar/pull/98, by onmyway133
  • Add isPushNotificationEnabled https://github.com/hyperoslo/Sugar/pull/99, by onmyway133
  • Swift 3 Date is comparable. These operators will conflict with Swift 3 operators. https://github.com/hyperoslo/Sugar/pull/100, by yfujiki
  • Once https://github.com/hyperoslo/Sugar/pull/103, by onmyway133
  • Check for content before apply templating https://github.com/hyperoslo/Sugar/pull/102, by onmyway133
  • Remove sizes https://github.com/hyperoslo/Sugar/pull/104, by onmyway133
  • Fix email validation https://github.com/hyperoslo/Sugar/pull/105, by lipka
  • Support new TLDs https://github.com/hyperoslo/Sugar/pull/106, by lipka
  • Update project to Swift 4 https://github.com/hyperoslo/Sugar/pull/108, by onmyway133
  • Update Application https://github.com/hyperoslo/Sugar/pull/109, by onmyway133
  • Swift 4 update https://github.com/hyperoslo/Sugar/pull/110, by onmyway133
  • Remove localisations https://github.com/hyperoslo/Sugar/pull/111, by onmyway133
3.1.2 3.1.2
3.1.1 3.1.1
Other projects in Swift