Swift-Sugar

Swift's Sugar. Heavily inspired on Objc Sugar(https://github.com/supermarin/ObjectiveSugar)

  • Owner: RuiAAPeres/Swift-Sugar
  • Platform:
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Note: Used as an exercise mainly, still you can make use of it of course

Inspiration

Swift Sugar is heavily inspired on ObjectiveSugar.

Documentation

Int extensions

3.times {
    println("Hello!")
}
// Hello!
// Hello!
// Hello!
3.timesWithIndex {
    index in println(index)
}
// 0
// 1
// 2
3.upTo(5) {
    index in println(index)
}
// 3
// 4
5.downTo(0) {
    index in println(index)
}
// 5
// 4
// 3
// 2
// 1

Array functions

[1,2,3,4].initial(3)
// [1,2,3]
[1,2,3,4].initial()
// [1]
[1,2,3,4].drop {$0 % 2 ==0}
// [2,4]
[1,2,3,4].remove(2)
// [3,4]
[1,2,3,4].minimum()
// 1
[1,2,3,4].maximum()
// 4
[1,2,3,4,1].numberTimesRepeated(1)
// 2

String functions

"Swift programming".length
// 17
"Swift programming"[1]
// w
"Swift programming"[-4]
// m
String.join(["S","w","i"])
//Swi
String.join("S","w","i","f","t")
//Swift
"Swift programming".split()
//["Swift", "programming"]
"Swift programming".split(delimiter:"r")
//["Swift p", "og", "amming"]
"Swift programming".indexOfString("mm")
// 12
"Swift programming".toCharacterArray()
//["S","w","i","f","t"," ","p","r","o","g","r","a","m","m","i","n","g"]
"Swift programming".reverse()
//gnimmargorp tfiwS

Swift Sugar (Global functions)

let x : [(Int,Int)] = zip([1,2,3,4,5], [1,2,3])
// [(1,1),(2,2),(3,3)]

Main metrics

Overview
Name With OwnerRuiAAPeres/Swift-Sugar
Primary LanguageSwift
Program languageSwift (Language Count: 2)
Platform
License:MIT License
所有者活动
Created At2014-06-03 16:14:03
Pushed At2016-09-23 13:02:59
Last Commit At2016-09-23 14:02:59
Release Count0
用户参与
Stargazers Count153
Watchers Count14
Fork Count7
Commits Count71
Has Issues Enabled
Issues Count2
Issue Open Count0
Pull Requests Count3
Pull Requests Open Count0
Pull Requests Close Count3
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private