Skip to content

Commit

Permalink
Merge pull request #7 from buzzfeed/fix/swift-deprecations
Browse files Browse the repository at this point in the history
Updated Swift 2.2 deprecations
  • Loading branch information
ChadEBrady committed Mar 29, 2016
2 parents 4fac8d6 + ab732fc commit d033ea2
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Hashids/Hashids.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct HashidsOptions {
// MARK: Hashids protocol

public protocol HashidsGenerator {
typealias Char
associatedtype Char

func encode(value: Int64...) -> String?

Expand Down Expand Up @@ -129,7 +129,8 @@ public class Hashids_<T: protocol<Equatable, UnsignedIntegerType>>: HashidsGener

public func encode(values: [Int64]) -> String? {
let ret = _encode(values)
return ret.reduce(String(), combine: { (var so, i) in
return ret.reduce(String(), combine: { (so, i) in
var so = so
let scalar:UInt32 = numericCast(i)
so.append(UnicodeScalar(scalar))
return so
Expand Down Expand Up @@ -252,8 +253,9 @@ public class Hashids_<T: protocol<Equatable, UnsignedIntegerType>>: HashidsGener
return ret
}

private func _hash(inout hash: [Char], var number: Int64, alphabet: [Char]) {
private func _hash(inout hash: [Char], number: Int64, alphabet: [Char]) {
let length = alphabet.count, index = hash.count
var number = number
repeat {
hash.insert(alphabet[Int(number % Int64(length))], atIndex: index)
number = number / Int64(length)
Expand Down Expand Up @@ -305,23 +307,23 @@ func transform<T: CollectionType where T.Generator.Element: Equatable>(a: T, _ b
}

func unique<T: CollectionType where T.Generator.Element: Equatable>(a: T) -> [T.Generator.Element] {
return transform(a, a) { (var c, a, b, e) in
return transform(a, a) { (c, a, b, e) in
if !c.contains(e) {
c.append(e)
}
}
}

func intersection<T: CollectionType where T.Generator.Element: Equatable>(a: T, _ b: T) -> [T.Generator.Element] {
return transform(a, b) { (var c, a, b, e) in
return transform(a, b) { (c, a, b, e) in
if b.contains(e) {
c.append(e)
}
}
}

func difference<T: CollectionType where T.Generator.Element: Equatable>(a: T, _ b: T) -> [T.Generator.Element] {
return transform(a, b) { (var c, a, b, e) in
return transform(a, b) { (c, a, b, e) in
if !b.contains(e) {
c.append(e)
}
Expand All @@ -346,7 +348,7 @@ func shuffle<T: MutableCollectionType, U:CollectionType where T.Index == Int, T.
let tmp = source[sourceIndex]
source[sourceIndex] = source[_j]
source[_j] = tmp
v++
sourceIndex--
v += 1
sourceIndex -= 1
}
}

0 comments on commit d033ea2

Please sign in to comment.