Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Commit 9415e23

Browse files
committed
Updated for Swift 3.0
29-07-2016
1 parent 6e29f53 commit 9415e23

File tree

10 files changed

+37
-30
lines changed

10 files changed

+37
-30
lines changed

Sources/SwiftFoundation/BitMaskOption.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public protocol BitMaskOption: RawRepresentable {
1414

1515
public extension BitMaskOption where Self.RawValue: Integer {
1616

17-
static func bitmask<S: Sequence where S.Iterator.Element == Self>(options: S) -> Self.RawValue {
17+
static func bitmask<S: Sequence>(options: S) -> Self.RawValue where S.Iterator.Element == Self {
1818
return options.reduce(0) { mask, option in
1919
mask | option.rawValue
2020
}

Sources/SwiftFoundation/ByteValue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public protocol ByteValue: Equatable {
2222

2323
// MARK: - Equatable
2424

25-
public func == <T: ByteValue where T.ByteValue: Equatable> (lhs: T, rhs: T) -> Bool {
25+
public func == <T: ByteValue> (lhs: T, rhs: T) -> Bool where T.ByteValue: Equatable {
2626

2727
return lhs.bytes == rhs.bytes
2828
}

Sources/SwiftFoundation/Data.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
// MARK: - Properties
2626

27-
private var _bytes: ContiguousArray<Byte>
27+
fileprivate var _bytes: ContiguousArray<Byte>
2828

2929
public var bytes: [Byte] {
3030

Sources/SwiftFoundation/JSONExtensions.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ public extension Collection where Iterator.Element: JSONEncodable {
100100
}
101101
}
102102

103-
public extension Dictionary where Value: JSONEncodable, Key: ExpressibleByStringLiteral {
103+
public extension Collection where Index == DictionaryIndex<String, JSONEncodable>, Iterator.Element == (key: String, value: JSONEncodable) {
104104

105105
/// Encodes the reciever into JSON.
106106
func toJSON() -> JSON.Value {
107107

108-
var jsonObject = JSON.Object(minimumCapacity: self.count)
108+
var jsonObject = JSON.Object(minimumCapacity: numericCast(self.count))
109109

110110
for (key, value) in self {
111111

112112
let jsonValue = value.toJSON()
113113

114-
let keyString = String(key)
114+
let keyString: String = key
115115

116116
jsonObject[keyString] = jsonValue
117117
}

Sources/SwiftFoundation/Lock.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
public init() {
137137

138138
var attrib = pthread_mutexattr_t()
139-
withUnsafeMutablePointer(&attrib) { attrs in
139+
withUnsafeMutablePointer(to: &attrib) { attrs in
140140
pthread_mutexattr_settype(attrs, Int32(PTHREAD_MUTEX_RECURSIVE))
141141
pthread_mutex_init(mutex, attrs)
142142
}
@@ -203,12 +203,12 @@
203203
ts.tv_sec = Int(floor(ti))
204204
ts.tv_nsec = Int((ti - Double(ts.tv_sec)) * 1000000000.0)
205205
var tv = timeval()
206-
withUnsafeMutablePointer(&tv) { t in
206+
withUnsafeMutablePointer(to: &tv) { t in
207207
gettimeofday(t, nil)
208208
ts.tv_sec += t.pointee.tv_sec
209209
ts.tv_nsec += Int((t.pointee.tv_usec * 1000000) / 1000000000)
210210
}
211-
let retVal: Int32 = withUnsafePointer(&ts) { t in
211+
let retVal: Int32 = withUnsafePointer(to: &ts) { t in
212212
return pthread_cond_timedwait(cond, mutex, t)
213213
}
214214

Sources/SwiftFoundation/RawRepresentable.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ public extension RawRepresentable {
5151

5252
// MARK: Comparable
5353

54-
public func < <T where T: RawRepresentable, T.RawValue: Comparable>(lhs: T, rhs: T) -> Bool {
54+
public func < <T>(lhs: T, rhs: T) -> Bool where T: RawRepresentable, T.RawValue: Comparable {
5555

5656
return lhs.rawValue < rhs.rawValue
5757
}
5858

59-
public func <= <T where T: RawRepresentable, T.RawValue: Comparable>(lhs: T, rhs: T) -> Bool {
59+
public func <= <T>(lhs: T, rhs: T) -> Bool where T: RawRepresentable, T.RawValue: Comparable {
6060

6161
return lhs.rawValue <= rhs.rawValue
6262
}
6363

64-
public func >= <T where T: RawRepresentable, T.RawValue: Comparable>(lhs: T, rhs: T) -> Bool {
64+
public func >= <T>(lhs: T, rhs: T) -> Bool where T: RawRepresentable, T.RawValue: Comparable {
6565

6666
return lhs.rawValue >= rhs.rawValue
6767
}
6868

69-
public func > <T where T: RawRepresentable, T.RawValue: Comparable>(lhs: T, rhs: T) -> Bool {
69+
public func > <T>(lhs: T, rhs: T) -> Bool where T: RawRepresentable, T.RawValue: Comparable {
7070

7171
return lhs.rawValue > rhs.rawValue
7272
}

Sources/SwiftFoundation/String.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public extension String {
2424

2525
case let .scalarValue(scalar):
2626

27-
string.append(scalar)
27+
let scalarString = String(scalar)
28+
29+
string.append(scalarString)
2830

2931
case .emptyInput:
3032

Sources/SwiftFoundation/Thread.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public final class Thread {
2525

2626
let holder = Unmanaged.passRetained(Closure(closure: closure))
2727

28-
let pointer = UnsafeMutablePointer<Void>(holder.toOpaque())
28+
let pointer = holder.toOpaque()
2929

3030
#if os(Linux)
3131

@@ -82,7 +82,7 @@ public final class Thread {
8282

8383
#if os(Linux)
8484

85-
private func ThreadPrivateMainLinux(arg: UnsafeMutablePointer<Void>?) -> UnsafeMutablePointer<Void>? {
85+
private func ThreadPrivateMainLinux(arg: UnsafeMutableRawPointer?) -> UnsafeMutableRawPointer? {
8686

8787
let unmanaged = Unmanaged<Thread.Closure>.fromOpaque(arg!)
8888

@@ -97,7 +97,7 @@ public final class Thread {
9797

9898
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
9999

100-
private func ThreadPrivateMainDarwin(arg: UnsafeMutablePointer<Void>) -> UnsafeMutablePointer<Void>? {
100+
private func ThreadPrivateMainDarwin(arg: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer? {
101101

102102
let unmanaged = Unmanaged<Thread.Closure>.fromOpaque(arg)
103103

@@ -110,9 +110,9 @@ public final class Thread {
110110

111111
#endif
112112

113-
private extension Thread {
113+
fileprivate extension Thread {
114114

115-
private final class Closure {
115+
final class Closure {
116116

117117
let closure: () -> ()
118118

Sources/SwiftFoundation/UUID.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
var uuid = uuid_t(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
4040

41-
withUnsafeMutablePointer(&uuid, { (valuePointer: UnsafeMutablePointer<uuid_t>) in
41+
withUnsafeMutablePointer(to: &uuid, { (valuePointer: UnsafeMutablePointer<uuid_t>) in
4242

4343
uuid_generate(unsafeBitCast(valuePointer, to: UnsafeMutablePointer<UInt8>.self))
4444
})
@@ -74,17 +74,22 @@
7474
var uuidCopy = bytes
7575

7676
var uuidString = POSIXUUIDStringType(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
77+
78+
// withUnsafeMutablePointer(&uuidCopy, &uuidString) { (uuidPointer: UnsafeMutablePointer<uuid_t>, uuidStringPointer: UnsafeMutablePointer<POSIXUUIDStringType>) -> Void in
7779

78-
withUnsafeMutablePointers(&uuidCopy, &uuidString) { (uuidPointer: UnsafeMutablePointer<uuid_t>, uuidStringPointer: UnsafeMutablePointer<POSIXUUIDStringType>) -> Void in
79-
80-
let stringBuffer = unsafeBitCast(uuidStringPointer, to: UnsafeMutablePointer<Int8>.self)
81-
82-
let uuidBuffer = unsafeBitCast(uuidPointer, to: UnsafeMutablePointer<UInt8>.self)
83-
84-
uuid_unparse(unsafeBitCast(uuidBuffer, to: UnsafePointer<UInt8>.self), stringBuffer)
80+
withUnsafeMutablePointer(to: &uuidCopy) { (uuidPointer: UnsafeMutablePointer<uuid_t>) in
81+
82+
withUnsafeMutablePointer(to: &uuidString) { (uuidStringPointer: UnsafeMutablePointer<POSIXUUIDStringType>) in
83+
84+
let stringBuffer = unsafeBitCast(uuidStringPointer, to: UnsafeMutablePointer<Int8>.self)
85+
86+
let uuidBuffer = unsafeBitCast(uuidPointer, to: UnsafeMutablePointer<UInt8>.self)
87+
88+
uuid_unparse(unsafeBitCast(uuidBuffer, to: UnsafePointer<UInt8>.self), stringBuffer)
89+
}
8590
}
8691

87-
return withUnsafeMutablePointer(&uuidString, { (valuePointer: UnsafeMutablePointer<POSIXUUIDStringType>) -> String in
92+
return withUnsafeMutablePointer(to: &uuidString, { (valuePointer: UnsafeMutablePointer<POSIXUUIDStringType>) -> String in
8893

8994
let buffer = unsafeBitCast(valuePointer, to: UnsafeMutablePointer<CChar>.self)
9095

Xcode/SwiftFoundation.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
/* Begin PBXBuildFile section */
1010
1AE78F671B96774100CDEF17 /* SwiftFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E30BA101B40F543009B1B49 /* SwiftFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; };
1111
1AE78FBF1B96774300CDEF17 /* SwiftFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E30BA101B40F543009B1B49 /* SwiftFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; };
12-
6E04074E1CB3E07500BE3A79 /* Thread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E04074D1CB3E07500BE3A79 /* Thread.swift */; };
1312
6E04074F1CB3E2E400BE3A79 /* Thread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E04074D1CB3E07500BE3A79 /* Thread.swift */; };
1413
6E0407501CB3E2E500BE3A79 /* Thread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E04074D1CB3E07500BE3A79 /* Thread.swift */; };
1514
6E041D3D1CB404CD004E080B /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B461C20F6EB00B2C995 /* String.swift */; };
1615
6E08F85D1BBE7DE900548B1E /* SwiftFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1AE78F6C1B96774100CDEF17 /* SwiftFoundation.framework */; };
16+
6E102F3B1D4D504C0046128B /* Thread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E04074D1CB3E07500BE3A79 /* Thread.swift */; };
1717
6E1ACD4B1C435822005775FD /* DataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E1ACD4A1C435822005775FD /* DataTests.swift */; };
1818
6E1ACD4C1C435822005775FD /* DataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E1ACD4A1C435822005775FD /* DataTests.swift */; };
1919
6E2C2B7B1C20F76600B2C995 /* Base64.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E2C2B1C1C20F6EB00B2C995 /* Base64.swift */; };
@@ -793,7 +793,6 @@
793793
6E8474CD1D24FCFE009CA7DB /* ComparisonResult.swift in Sources */,
794794
6EFF9A1B1CAD0C6B00917CB3 /* Range.swift in Sources */,
795795
6E2C2BFD1C20F76700B2C995 /* Null.swift in Sources */,
796-
6E04074E1CB3E07500BE3A79 /* Thread.swift in Sources */,
797796
6E2C2BE41C20F76700B2C995 /* BitMaskOption.swift in Sources */,
798797
6E82FD721CBA06C10049CD1B /* Lock.swift in Sources */,
799798
6E2C2C091C20F76700B2C995 /* RegularExpressionCompileOption.swift in Sources */,
@@ -807,6 +806,7 @@
807806
6E2C2C0F1C20F76700B2C995 /* Transformer.swift in Sources */,
808807
6E2C2C081C20F76700B2C995 /* RegularExpressionCompileError.swift in Sources */,
809808
6E2C2C0B1C20F76700B2C995 /* SemanticVersion.swift in Sources */,
809+
6E102F3B1D4D504C0046128B /* Thread.swift in Sources */,
810810
6E2C2BF11C20F76700B2C995 /* FilePermission.swift in Sources */,
811811
6E2C2C071C20F76700B2C995 /* RegularExpression.swift in Sources */,
812812
6E957C2B1C43AA55003F3C51 /* JSONSerialization.swift in Sources */,

0 commit comments

Comments
 (0)