Skip to content

Commit

Permalink
Update code to Swift 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
malczak committed Apr 3, 2016
1 parent 97cb8bd commit ff21ffe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Hashids-Swift.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|

s.name = "Hashids-Swift"
s.version = "0.3.0"
s.version = "0.3.1"
s.license = "MIT"
s.homepage = "http://hashids.org/swift/"
s.summary = "Small open-source library that generates short, unique, non-sequential ids from numbers."
s.author = { "Mateusz Malczak" => "[email protected]" }
s.author = { "Matt" => "[email protected]" }
s.source = { :git => "https://github.com/malczak/hashids.git", :tag => s.version.to_s }

s.platform = :ios, "8.0"
Expand Down
18 changes: 10 additions & 8 deletions Hashids.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct HashidsOptions {
// MARK: Hashids protocol

public protocol HashidsGenerator {
typealias Char
associatedtype Char

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

Expand Down Expand Up @@ -130,8 +130,8 @@ public class Hashids_<T where T:Equatable, T:UnsignedIntegerType>: HashidsGenera

public func encode(values: [Int]) -> 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 @@ -243,7 +243,8 @@ public class Hashids_<T where T:Equatable, T:UnsignedIntegerType>: HashidsGenera
return ret
}

private func _hash(inout hash: [Char], var _ number: Int, _ alphabet: [Char]) {
private func _hash(inout hash: [Char], _ number: Int, _ alphabet: [Char]) {
var number = number
let length = alphabet.count, index = hash.count
repeat {
hash.insert(alphabet[number % length], atIndex: index)
Expand All @@ -261,7 +262,8 @@ public class Hashids_<T where T:Equatable, T:UnsignedIntegerType>: HashidsGenera
value, token in
var tokenValue = 0.0
if let token_index = alphabet.indexOf(token as Char) {
let mul = pow(Double(alphabetLength), Double(--hashLength))
hashLength -= 1
let mul = pow(Double(alphabetLength), Double(hashLength))
tokenValue = Double(token_index) * mul
}
return value + tokenValue
Expand Down Expand Up @@ -299,7 +301,7 @@ internal func transform<T:CollectionType where T.Generator.Element:Equatable>(a:

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

internal 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
( c, a, b, e) in
if contains(b, e) {
c.append(e)
}
Expand All @@ -317,7 +319,7 @@ internal func intersection<T:CollectionType where T.Generator.Element:Equatable>

internal 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
( c, a, b, e) in
if !contains(b, e) {
c.append(e)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/HashidsTests/HashidsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

import XCTest
import hashids
import Hashids_Swift

class HashIdsTests: XCTestCase {

Expand Down

0 comments on commit ff21ffe

Please sign in to comment.