Skip to content

Commit

Permalink
Merge pull request #60 from IBM-Swift/swift4
Browse files Browse the repository at this point in the history
Swift4
  • Loading branch information
quanvo87 authored Sep 11, 2017
2 parents 0441c97 + 5cff24e commit d6626c0
Show file tree
Hide file tree
Showing 22 changed files with 90 additions and 16 deletions.
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.build/
Packages/
/SwiftRedis.xcodeproj
*.DS_Store
*.pkg
.build
/SwiftRedis.xcodeproj
Package.resolved
Packages
build
45 changes: 45 additions & 0 deletions Package@swift-4.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

/**
* Copyright IBM Corporation 2016, 2017
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

import PackageDescription

let package = Package(
name: "SwiftRedis",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "SwiftRedis",
targets: ["SwiftRedis"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/IBM-Swift/BlueSocket.git", from: "0.12.0")
],
targets: [
// Targets are the basic building blocks of a package. A target defines a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "SwiftRedis",
dependencies: ["Socket"]),
.testTarget(
name: "SwiftRedisTests",
dependencies: ["SwiftRedis"]),
]
)
1 change: 1 addition & 0 deletions Sources/.swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.1.1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
49 changes: 37 additions & 12 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,47 @@ import XCTest
import Glibc
@testable import SwiftRedisTests

srand(UInt32(time(nil)))

// http://stackoverflow.com/questions/24026510/how-do-i-shuffle-an-array-in-swift
extension MutableCollection where Indices.Iterator.Element == Index {
mutating func shuffle() {
let c = count
guard c > 1 else { return }

for (firstUnshuffled, unshuffledCount) in zip(indices, stride(from: c, to: 1, by: -1)) {
let d: IndexDistance = numericCast(random() % numericCast(unshuffledCount))
guard d != 0 else { continue }
let i = index(firstUnshuffled, offsetBy: d)
swap(&self[firstUnshuffled], &self[i])
#if swift(>=4)

extension MutableCollection {
mutating func shuffle() {
let c = count

guard c > 1 else { return }

srand(UInt32(time(nil)))

for (firstUnshuffled, unshuffledCount) in zip(indices, stride(from: c, to: 1, by: -1)) {
let d: IndexDistance = numericCast(random() % numericCast(unshuffledCount))
guard d != 0 else { continue }
let i = index(firstUnshuffled, offsetBy: d)
swapAt(firstUnshuffled, i)
}
}
}
}

#else

extension MutableCollection where Indices.Iterator.Element == Index {
mutating func shuffle() {
let c = count

guard c > 1 else { return }

srand(UInt32(time(nil)))

for (firstUnshuffled, unshuffledCount) in zip(indices, stride(from: c, to: 1, by: -1)) {
let d: IndexDistance = numericCast(random() % numericCast(unshuffledCount))
guard d != 0 else { continue }
let i = index(firstUnshuffled, offsetBy: d)
swap(&self[firstUnshuffled], &self[i])
}
}
}

#endif

extension Sequence {
func shuffled() -> [Iterator.Element] {
Expand Down
2 changes: 1 addition & 1 deletion Tests/SwiftRedisTests/VerifyLinuxTestCount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
**/

#if os(OSX)
#if os(OSX) && !swift(>=3.2)
import XCTest

class VerifyLinuxTestCount: XCTestCase {
Expand Down

0 comments on commit d6626c0

Please # to comment.