Skip to content

Commit

Permalink
Merge pull request #183 from ankurp/public-extensions
Browse files Browse the repository at this point in the history
Making extensions public
  • Loading branch information
ankurp committed Sep 20, 2015
2 parents f2245f6 + 247d182 commit ebd494e
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 50 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ osx_image: xcode7
script:
- xctool -workspace Dollar.xcworkspace -scheme Dollar -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' ONLY_ACTIVE_ARCH=NO clean build test
- xctool -workspace Dollar.xcworkspace -scheme Cent -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6' ONLY_ACTIVE_ARCH=NO clean build test

before_install:
- brew update
- brew uninstall xctool && brew install --HEAD xctool
2 changes: 1 addition & 1 deletion Cent.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Cent"
s.version = "4.0.0"
s.version = "4.0.1"
s.summary = "Extension for common object types for Swift Language"
s.homepage = "https://github.com/ankurp/Dollar.swift"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
2 changes: 1 addition & 1 deletion Cent/Cent/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import Dollar

internal extension Array {
public extension Array {

/// Creates an array of elements from the specified indexes, or keys, of the collection.
/// Indexes may be specified as individual arguments or as arrays of indexes.
Expand Down
2 changes: 1 addition & 1 deletion Cent/Cent/Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

extension NSDate {
public extension NSDate {

/// Returns a new Date given the year month and day
///
Expand Down
2 changes: 1 addition & 1 deletion Cent/Cent/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import Dollar

internal extension Dictionary {
public extension Dictionary {
/// Merges the dictionary with dictionaries passed. The latter dictionaries will override
/// values of the keys that are already set
///
Expand Down
75 changes: 36 additions & 39 deletions Cent/Cent/Int.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import Dollar

extension Int {
public extension Int {

/// Invoke a callback n times
///
Expand Down Expand Up @@ -110,44 +110,6 @@ extension Int {
callback(selfCopy--)
}
}

}

public extension Int {
struct CalendarMath {
private let unit: NSCalendarUnit
private let value: Int
private var calendar: NSCalendar {
return NSCalendar.autoupdatingCurrentCalendar()
}

private init(unit: NSCalendarUnit, value: Int) {
self.unit = unit
self.value = value
}

private func generateComponents(modifer: (Int) -> (Int) = (+)) -> NSDateComponents {
let components = NSDateComponents()
components.setValue(modifer(value), forComponent: unit)
return components
}

public func from(date: NSDate) -> NSDate? {
return calendar.dateByAddingComponents(generateComponents(), toDate: date, options: [])
}

public var fromNow: NSDate? {
return from(NSDate())
}

public func before(date: NSDate) -> NSDate? {
return calendar.dateByAddingComponents(generateComponents(-), toDate: date, options: [])
}

public var ago: NSDate? {
return before(NSDate())
}
}

private func mathForUnit(unit: NSCalendarUnit) -> CalendarMath {
return CalendarMath(unit: unit, value: self)
Expand Down Expand Up @@ -208,4 +170,39 @@ public extension Int {
var year: CalendarMath {
return years
}

struct CalendarMath {
private let unit: NSCalendarUnit
private let value: Int
private var calendar: NSCalendar {
return NSCalendar.autoupdatingCurrentCalendar()
}

private init(unit: NSCalendarUnit, value: Int) {
self.unit = unit
self.value = value
}

private func generateComponents(modifer: (Int) -> (Int) = (+)) -> NSDateComponents {
let components = NSDateComponents()
components.setValue(modifer(value), forComponent: unit)
return components
}

public func from(date: NSDate) -> NSDate? {
return calendar.dateByAddingComponents(generateComponents(), toDate: date, options: [])
}

public var fromNow: NSDate? {
return from(NSDate())
}

public func before(date: NSDate) -> NSDate? {
return calendar.dateByAddingComponents(generateComponents(-), toDate: date, options: [])
}

public var ago: NSDate? {
return before(NSDate())
}
}
}
2 changes: 1 addition & 1 deletion Cent/Cent/Range.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import Dollar

internal extension Range {
public extension Range {

/// For each index in the range invoke the callback by passing the item in range
///
Expand Down
4 changes: 2 additions & 2 deletions Cent/Cent/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import Dollar

extension String {
public extension String {

public var length: Int {
get {
Expand Down Expand Up @@ -102,7 +102,7 @@ extension String {
}
}

extension Character {
public extension Character {
public var description: String {
get {
return String(self)
Expand Down
2 changes: 1 addition & 1 deletion Dollar.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Dollar"
s.version = "4.0.0"
s.version = "4.0.1"
s.summary = "A functional tool-belt for Swift Language"
s.homepage = "https://github.com/ankurp/Dollar.swift"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand Down
2 changes: 1 addition & 1 deletion Dollar/Dollar/AutoCurry.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This is an autogenerated file. Do not edit this file manually.

extension $ {
public extension $ {

public class func curry<T1, T2, R>(f: (T1, T2) -> R) -> T1 -> T2 -> R {
return { t1 in { t2 in f(t1, t2) } }
Expand Down
2 changes: 1 addition & 1 deletion Dollar/gen_auto_curry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def curry_generator(n)

funcs = [
"// This is an autogenerated file. Do not edit this file manually.",
"extension $ {",
"public extension $ {",
(2..MAX_AUTO_CURRY_ARG_COUNT).map {|i| curry_generator(i) }.join("\n\n"),
"}"
].join("\n\n")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Cent is a library that extends certain Swift object types using the extension fe

## Using [Carthage](https://github.com/Carthage/Carthage)

Add `github "ankurp/Dollar.swift" ~> 4.0.0` to your `Cartfile` and run `carthage update`. If unfamiliar with Carthage then checkout their [Getting Started section](https://github.com/Carthage/Carthage#getting-started) or this [sample app](https://github.com/ankurp/DollarCarthageApp)
Add `github "ankurp/Dollar.swift" ~> 4.0.1` to your `Cartfile` and run `carthage update`. If unfamiliar with Carthage then checkout their [Getting Started section](https://github.com/Carthage/Carthage#getting-started) or this [sample app](https://github.com/ankurp/DollarCarthageApp)

## Using [cocoapods](http://cocoapods.org/) version 0.36.x or greater

Expand Down

0 comments on commit ebd494e

Please sign in to comment.