• Stars
    star
    1,068
  • Rank 43,257 (Top 0.9 %)
  • Language
    Swift
  • License
    Other
  • Created over 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

โ˜• Something sweet that goes great with your Cocoa

Sugar

Sugar is a sweetener for your Cocoa implementations.

CI Status Version Carthage Compatible License Platform Swift

Table of Contents

Hue Icon

iOS

Application

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.

Screen

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

Get the actual pixel information of the device screen.

Simulator

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

UIView

.optimize()
let view = UIView.optimize
/*
  clipsToBounds = true
  layer.drawsAsynchronously = true
  opaque = true
*/

UIImage

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

Shared

SequenceType

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

Dates

Compare

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

Construct

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

Frame

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.

Localization

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.

Once

let once = Once()
once.run {
  // do something
}

once.run {
  // no effect
}

Operators

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.

Range

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

Regex

if "[email protected]".isEmail() {
  // Is email
}

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

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

Shared Extensions

+Queueable

struct Object: Queueable {

  func process() -> Bool { return true }
}

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

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

public protocol Queueable {
  func process() -> Bool
}

URLStringConvertible

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.

Swizzler

class Swizzled: NSObject {

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

    if self !== Swizzled.self {
    return
  }

  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.

Then

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]

UITesting

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.

UnitTesting

if UnitTesting.isRunning {
  // running test
}

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

Check if you are running UniTests and to measure performance.

Installation

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"

Sugar is also available through Swift Package Manager.

.package(url: "https://github.com/hyperoslo/Sugar.git", .upToNextMajor(from: "5.0.1")),

Author

Hyper Interaktiv AS, [email protected]

License

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

More Repositories

1

ImagePicker

๐Ÿ“ท Reinventing the way ImagePicker works.
Swift
4,867
star
2

Whisper

๐Ÿ“ฃ Whisper is a component that will make the task of display messages and in-app notifications simple. It has three different views inside
Swift
3,754
star
3

Presentation

๐Ÿ“‘ Presentation helps you to make tutorials, release notes and animated pages.
Swift
3,046
star
4

Cache

๐Ÿ“ฆ Nothing but Cache.
Swift
2,969
star
5

BarcodeScanner

๐Ÿ”Ž A simple and beautiful barcode scanner.
Swift
1,688
star
6

Lightbox

๐ŸŒŒ A convenient and easy to use image viewer for your iOS app
Swift
1,640
star
7

Gallery

๐Ÿ“น Your next favorite image and video picker
Swift
1,419
star
8

Compass

๐ŸŒ Compass helps you setup a central navigation system for your application
Swift
826
star
9

Imaginary

๐Ÿฆ„ Remote images, as easy as one, two, three.
Swift
614
star
10

Pages

๐Ÿ“„ UIPageViewController made simple
Swift
495
star
11

iOS-playbook

Hyper's iOS playbook
228
star
12

capistrano-foreman

Capistrano tasks for foreman and upstart.
Ruby
136
star
13

Tabby

โ›ฉ A fancy tabbar
Swift
103
star
14

Keychains

๐Ÿ”‘ A keychain wrapper that is so easy to use that your cat could use it.
Swift
75
star
15

Aftermath

๐Ÿ”ฎ Stateless message-driven micro-framework in Swift.
Swift
71
star
16

novel

๐Ÿ“– A content management system (CMS) built in Swift
Swift
68
star
17

OhMyAuth

๐Ÿ” Simple OAuth2 library with a support of multiple services.
Swift
66
star
18

Brick

๐Ÿ’ง A generic view model for both basic and complex scenarios
Swift
59
star
19

gamification

Gamification is a collection of models for Ruby on Rails that allows you to make anything a game
Ruby
51
star
20

Signature

UIView with signature support
Objective-C
49
star
21

playbook

How we do things, and why
42
star
22

SwiftPackage

๐Ÿ† Template to make a Swift package
Ruby
38
star
23

hyper-alerts

Hyper Alerts notifies people whenever someone posts to Facebook or Twitter
Ruby
34
star
24

knowledge_base

Knowledge Base is a bunch of models for Ruby on Rails that you probably need to build your own
Ruby
31
star
25

SwiftProject

๐Ÿ† Generate Swift project with necessary toolings
Swift
30
star
26

github-s3

Shell scripts that make it really easy to archive and restore repositories between GitHub and AWS S3
Shell
20
star
27

cellular

Sending and receiving SMSs with Ruby through pluggable backends.
Ruby
20
star
28

mingle

Social media integration for Ruby on Rails
Ruby
20
star
29

activeadmin_polymorphic

Ruby
20
star
30

HYPEventManager

HYPEventManager is the easiest way to add, update and remove iOS calendar events.
Objective-C
17
star
31

hyper-recipes

Ruby
16
star
32

Contract

The easiest way to sign your soul away
Objective-C
15
star
33

Postman

ยซYou're nothing but a drifter who found a bag of mailยป
Objective-C
15
star
34

Minced

Convert JSON keys to camelCase
Objective-C
14
star
35

code-review

A simple application that selects a random commit for code review.
Ruby
14
star
36

CardStack

A container view controller implementing a stack of "cards" (each card is a view controller)
Objective-C
13
star
37

hyper-radar

๐Ÿ’ก Research and development at Hyper
12
star
38

Offline

๐Ÿ“ดOffline request storage.
Swift
11
star
39

TimeAgo

Swift
11
star
40

Scatter

Customizable Scatter Chart for iOS
Objective-C
11
star
41

AftermathCompass

Message-driven navigation system built on top of Aftermath and Compass.
Swift
10
star
42

AsyncWall

Swift
10
star
43

heroku-deploy

Deploying your applications to Heroku should never involve manually chaining shell commands together
Ruby
10
star
44

HYPLocalNotificationManager

Handle local notifications like a pro
Objective-C
9
star
45

hyper-content-for-angular

Inject content into a different part of your page
JavaScript
9
star
46

tasuku

Tasks for Ruby on Rails
Ruby
9
star
47

CollectionAnimations

UICollectionView animations
Swift
9
star
48

UIViewController-HYPKeyboardToolbar

Snap a toolbar to a keyboard like a pro
Objective-C
8
star
49

refile-input

Refile support for Formtastic
Ruby
8
star
50

singleton-rails

Adds singleton functionallity to ActiveRecord models
Ruby
8
star
51

Champagne

The Champagne Web Framework.
Swift
7
star
52

obix

Ruby OBIX parser
Ruby
6
star
53

android-playbook

6
star
54

feeder

Provides simple feed functionality through an engine
Ruby
6
star
55

hyper-says

Heard @hyperoslo
JavaScript
6
star
56

embeddable

Embeddable makes it easier to embed videos
Ruby
6
star
57

tv

The TV in our lobby
HTML
6
star
58

hyper_admin

Admin solution for Ruby on Rails.
Ruby
6
star
59

openid-token-proxy

Retrieves and refreshes OpenID tokens on behalf of a user when dealing with complex authentication schemes, such as client-side certificates
Ruby
6
star
60

Flasker

๐Ÿถ Secure User Defaults
Swift
6
star
61

ImageCrop

android library to zoom, pan and crop pictures
Java
6
star
62

facebook-messenger-demo

A demo rails app for facebook-messenger gem
Ruby
6
star
63

yr

Yr makes it easy to get weather forecast from Yr.no.
Ruby
5
star
64

Orchestra

Swift
5
star
65

date-interval-picker

A nice little date interval picker for Android
Java
5
star
66

NSString-HYPWordExtractor

The easiest way of extracting all words from a string
Objective-C
5
star
67

Transition

Swift
5
star
68

pissuu

Python client for the Issuu API
Python
5
star
69

javascript-playbook

A place to define our conventions for working with JavaScript
5
star
70

NSString-HYPFormula

Creating and running string-based formulas have never been this easy
Objective-C
5
star
71

heroku-pages

Easily inspect, view and upload your Heroku error and maintenance pages
Ruby
5
star
72

ios-foundation

๐Ÿ…An established foundation within iOS team
Ruby
5
star
73

bot

Bot all the thingsโ„ข
CoffeeScript
5
star
74

slack-andreasbot

A bot that is always typing. Just like the non-bot Andreas.
Ruby
5
star
75

deviser

Allows impersonation straight from the command line for Devise projects
Ruby
4
star
76

DistributedSpaceLayout

This is a tiny library extending LinearLayout to automatically distribute evenly spaces between children
Java
4
star
77

django-mobile

Simple, easy to use Django SMS app with support for pluggable backends
Python
4
star
78

hyper-validator-base

Enables validation for inputs in conjunction with hyper-validator modules.
JavaScript
4
star
79

api-playbook

A place to define the conventions we use to build APIs
4
star
80

NSManagedObjectContext-HYPSafeSave

Warns you of unsafe NSManagedObjectContext saves
Objective-C
4
star
81

HYPLocationManager

The easiest way to use CLLocationManager.
Objective-C
4
star
82

gulp-frontend-starterkit

Gulp Frontend StarterKit is a minimal mix of tasks and tools integrated with [Gulp](http://gulpjs.com/) to form a asset pipeline. It provides an efficient and modular workflow to develop and deploy static websites quickly.
JavaScript
4
star
83

one-repo-split-angular-rails-example

this is a prototype of playing together with angular and rails on the same repo, but without mixing their code together (heroku deployed)
Ruby
3
star
84

eslint-config

Hyper's ESLint config
JavaScript
3
star
85

reverse-proxy

Simple reverse proxy application.
Ruby
3
star
86

Sequent

Sequent iOS Framework
Swift
3
star
87

spot-hyper

Spot Hyper shares where you are and what you working on in realtime with other team members, right from any slack channel
Ruby
3
star
88

AftermathSpots

Swift
3
star
89

mysql-s3

A shell script that archives a MySQL database to AWS S3
Shell
3
star
90

Masquerade

Swift
3
star
91

grumbles-the-lame-wizard

"Grumbles the Lame Wizard" game
Ruby
3
star
92

hyper-guides

Miscellaneous guides from Hyper
Ruby
3
star
93

Depot

A convenience storage/caching library for Android.
Java
2
star
94

HYPInputValidators

Objective-C
2
star
95

HYPPopoverBackgroundView

Makes popover controllers look so good you'll want to lick them
Objective-C
2
star
96

HYPImagePicker

UIImagePickerController without the tears
Shell
2
star
97

AsyncMediaSlider

A simple to use media slider that loads remote images asynchronously on demand
Objective-C
2
star
98

HYPWebView

WebView++
Objective-C
2
star
99

amazon-s3-backup

Utility that creates storage buckets and transfer jobs that backup Amazon S3 Buckets to Google Cloud Storage
JavaScript
2
star
100

AftermathTools

Development tools for Aftermath.
Swift
2
star