Skip to content

Commit

Permalink
Add Swift 4 support (#20)
Browse files Browse the repository at this point in the history
Add Swift 4 support
  • Loading branch information
quanvo87 authored and youming-lin committed Sep 25, 2017
1 parent 8d778fe commit 312fd9a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 15 deletions.
47 changes: 47 additions & 0 deletions Package@swift-4.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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: "Kitura-WebSocket",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "Kitura-WebSocket",
targets: ["KituraWebSocket"]),
],
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/Kitura-net.git", .upToNextMinor(from: "1.7.0")),
.package(url: "https://github.com/IBM-Swift/BlueCryptor.git", .upToNextMinor(from: "0.8.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: "KituraWebSocket",
dependencies: ["KituraNet", "Cryptor"]),
.testTarget(
name: "KituraWebSocketTests",
dependencies: ["KituraWebSocket"]),
]
)
6 changes: 5 additions & 1 deletion Tests/KituraWebSocketTests/PrintLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public class PrintLogger: Logger {
guard let range = path.range(of: "/", options: .backwards) else {
return path
}
return path.substring(from: range.upperBound)
#if swift(>=3.2)
return String(path[range.upperBound...])
#else
return path.substring(from: range.upperBound)
#endif
}
}
2 changes: 1 addition & 1 deletion Tests/KituraWebSocketTests/TestLinuxSafeguard.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 TestLinuxSafeguard: XCTestCase {
Expand Down
42 changes: 29 additions & 13 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,40 @@

import XCTest
import Glibc

@testable import KituraWebSocketTests

// 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 }

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])
#if swift(>=3.2)
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

0 comments on commit 312fd9a

Please sign in to comment.