Skip to content

Commit da6a830

Browse files
authored
Merge pull request #1541 from otaviolima/use-dot-syntax
2 parents b465691 + f3a63a2 commit da6a830

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+593
-593
lines changed

Foundation/ByteCountFormatter.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,44 +126,44 @@ open class ByteCountFormatter : Formatter {
126126
private func convertValue(fromByteCount byteCount: Int64, for byteSize: [Unit: Double]) -> String {
127127
let byte = Double(byteCount)
128128
if byte == 0, allowsNonnumericFormatting, allowedUnits == [], includesUnit, includesCount {
129-
return partsToIncludeFor(value: "Zero", unit: Unit.KB)
129+
return partsToIncludeFor(value: "Zero", unit: .KB)
130130
} else if byte == 1 || byte == -1 {
131131
if allowedUnits.contains(.useAll) || allowedUnits == [] {
132-
return formatNumberFor(bytes: byte, unit: Unit.byte)
132+
return formatNumberFor(bytes: byte, unit: .byte)
133133
} else {
134134
return valueToUseFor(byteCount: byte, unit: allowedUnits)
135135
}
136-
} else if byte < byteSize[Unit.KB]! && byte > -byteSize[Unit.KB]!{
136+
} else if byte < byteSize[.KB]! && byte > -byteSize[.KB]!{
137137
if allowedUnits.contains(.useAll) || allowedUnits == [] {
138-
return formatNumberFor(bytes: byte, unit: Unit.bytes)
138+
return formatNumberFor(bytes: byte, unit: .bytes)
139139
} else {
140140
return valueToUseFor(byteCount: byte, unit: allowedUnits)
141141
}
142-
} else if byte < byteSize[Unit.MB]! && byte > -byteSize[Unit.MB]! {
142+
} else if byte < byteSize[.MB]! && byte > -byteSize[.MB]! {
143143
if allowedUnits.contains(.useAll) || allowedUnits == [] {
144144
return divide(byte, by: byteSize, for: .KB)
145145
}
146146
return valueToUseFor(byteCount: byte, unit: allowedUnits)
147147

148-
} else if byte < byteSize[Unit.GB]! && byte > -byteSize[Unit.GB]! {
148+
} else if byte < byteSize[.GB]! && byte > -byteSize[.GB]! {
149149
if allowedUnits.contains(.useAll) || allowedUnits == [] {
150150
return divide(byte, by: byteSize, for: .MB)
151151
}
152152
return valueToUseFor(byteCount: byte, unit: allowedUnits)
153153

154-
} else if byte < byteSize[Unit.TB]! && byte > -byteSize[Unit.TB]! {
154+
} else if byte < byteSize[.TB]! && byte > -byteSize[.TB]! {
155155
if allowedUnits.contains(.useAll) || allowedUnits == [] {
156156
return divide(byte, by: byteSize, for: .GB)
157157
}
158158
return valueToUseFor(byteCount: byte, unit: allowedUnits)
159159

160-
} else if byte < byteSize[Unit.PB]! && byte > -byteSize[Unit.PB]! {
160+
} else if byte < byteSize[.PB]! && byte > -byteSize[.PB]! {
161161
if allowedUnits.contains(.useAll) || allowedUnits == [] {
162162
return divide(byte, by: byteSize, for: .TB)
163163
}
164164
return valueToUseFor(byteCount: byte, unit: allowedUnits)
165165

166-
} else if byte < byteSize[Unit.EB]! && byte > -byteSize[Unit.EB]! {
166+
} else if byte < byteSize[.EB]! && byte > -byteSize[.EB]! {
167167
if allowedUnits.contains(.useAll) || allowedUnits == [] {
168168
return divide(byte, by: byteSize, for: .PB)
169169
}
@@ -191,19 +191,19 @@ open class ByteCountFormatter : Formatter {
191191
byteSize = binaryByteSize
192192
}
193193
if byteCount == 0, allowsNonnumericFormatting, includesCount, includesUnit {
194-
return partsToIncludeFor(value: "Zero", unit: Unit.KB)
194+
return partsToIncludeFor(value: "Zero", unit: .KB)
195195
}
196196
//Handles the cases where allowedUnits is set to a specific individual value. e.g. allowedUnits = .useTB
197197
switch allowedUnits {
198-
case Units.useBytes: return partsToIncludeFor(value: actualBytes, unit: Unit.bytes)
199-
case Units.useKB: return divide(byteCount, by: byteSize, for: .KB)
200-
case Units.useMB: return divide(byteCount, by: byteSize, for: .MB)
201-
case Units.useGB: return divide(byteCount, by: byteSize, for: .GB)
202-
case Units.useTB: return divide(byteCount, by: byteSize, for: .TB)
203-
case Units.usePB: return divide(byteCount, by: byteSize, for: .PB)
204-
case Units.useEB: return divide(byteCount, by: byteSize, for: .EB)
205-
case Units.useZB: return divide(byteCount, by: byteSize, for: .ZB)
206-
case Units.useYBOrHigher: return divide(byteCount, by: byteSize, for: .YB)
198+
case .useBytes: return partsToIncludeFor(value: actualBytes, unit: .bytes)
199+
case .useKB: return divide(byteCount, by: byteSize, for: .KB)
200+
case .useMB: return divide(byteCount, by: byteSize, for: .MB)
201+
case .useGB: return divide(byteCount, by: byteSize, for: .GB)
202+
case .useTB: return divide(byteCount, by: byteSize, for: .TB)
203+
case .usePB: return divide(byteCount, by: byteSize, for: .PB)
204+
case .useEB: return divide(byteCount, by: byteSize, for: .EB)
205+
case .useZB: return divide(byteCount, by: byteSize, for: .ZB)
206+
case .useYBOrHigher: return divide(byteCount, by: byteSize, for: .YB)
207207
default: break
208208
}
209209

Foundation/Calendar.swift

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -944,38 +944,38 @@ public struct Calendar : Hashable, Equatable, ReferenceConvertible, _MutableBoxi
944944

945945
internal static func _fromCalendarUnit(_ unit: NSCalendar.Unit) -> Component {
946946
switch unit {
947-
case NSCalendar.Unit.era:
948-
return Component.era
949-
case NSCalendar.Unit.year:
950-
return Component.year
951-
case NSCalendar.Unit.month:
952-
return Component.month
953-
case NSCalendar.Unit.day:
954-
return Component.day
955-
case NSCalendar.Unit.hour:
956-
return Component.hour
957-
case NSCalendar.Unit.minute:
958-
return Component.minute
959-
case NSCalendar.Unit.second:
960-
return Component.second
961-
case NSCalendar.Unit.weekday:
962-
return Component.weekday
963-
case NSCalendar.Unit.weekdayOrdinal:
964-
return Component.weekdayOrdinal
965-
case NSCalendar.Unit.quarter:
966-
return Component.quarter
967-
case NSCalendar.Unit.weekOfMonth:
968-
return Component.weekOfMonth
969-
case NSCalendar.Unit.weekOfYear:
970-
return Component.weekOfYear
971-
case NSCalendar.Unit.yearForWeekOfYear:
972-
return Component.yearForWeekOfYear
973-
case NSCalendar.Unit.nanosecond:
974-
return Component.nanosecond
975-
case NSCalendar.Unit.calendar:
976-
return Component.calendar
977-
case NSCalendar.Unit.timeZone:
978-
return Component.timeZone
947+
case .era:
948+
return .era
949+
case .year:
950+
return .year
951+
case .month:
952+
return .month
953+
case .day:
954+
return .day
955+
case .hour:
956+
return .hour
957+
case .minute:
958+
return .minute
959+
case .second:
960+
return .second
961+
case .weekday:
962+
return .weekday
963+
case .weekdayOrdinal:
964+
return .weekdayOrdinal
965+
case .quarter:
966+
return .quarter
967+
case .weekOfMonth:
968+
return .weekOfMonth
969+
case .weekOfYear:
970+
return .weekOfYear
971+
case .yearForWeekOfYear:
972+
return .yearForWeekOfYear
973+
case .nanosecond:
974+
return .nanosecond
975+
case .calendar:
976+
return .calendar
977+
case .timeZone:
978+
return .timeZone
979979
default:
980980
fatalError()
981981
}
@@ -1159,7 +1159,7 @@ extension Calendar : CustomDebugStringConvertible, CustomStringConvertible, Cust
11591159
(label: "firstWeekday", value: firstWeekday),
11601160
(label: "minimumDaysInFirstWeek", value: minimumDaysInFirstWeek)
11611161
]
1162-
return Mirror(self, children: children, displayStyle: Mirror.DisplayStyle.struct)
1162+
return Mirror(self, children: children, displayStyle: .struct)
11631163
}
11641164
}
11651165

Foundation/Data.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ extension Data : CustomStringConvertible, CustomDebugStringConvertible, CustomRe
18781878
children.append((label: "bytes", value: Array(self[startIndex..<Swift.min(nBytes + startIndex, endIndex)])))
18791879
}
18801880

1881-
let m = Mirror(self, children:children, displayStyle: Mirror.DisplayStyle.struct)
1881+
let m = Mirror(self, children:children, displayStyle: .struct)
18821882
return m
18831883
}
18841884
}

Foundation/Date.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ extension Date : CustomDebugStringConvertible, CustomStringConvertible, CustomRe
226226
public var customMirror: Mirror {
227227
var c: [(label: String?, value: Any)] = []
228228
c.append((label: "timeIntervalSinceReferenceDate", value: timeIntervalSinceReferenceDate))
229-
return Mirror(self, children: c, displayStyle: Mirror.DisplayStyle.struct)
229+
return Mirror(self, children: c, displayStyle: .struct)
230230
}
231231
}
232232

Foundation/DateComponents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ extension DateComponents : CustomStringConvertible, CustomDebugStringConvertible
346346
if let r = weekOfYear { c.append((label: "weekOfYear", value: r)) }
347347
if let r = yearForWeekOfYear { c.append((label: "yearForWeekOfYear", value: r)) }
348348
if let r = isLeapMonth { c.append((label: "isLeapMonth", value: r)) }
349-
return Mirror(self, children: c, displayStyle: Mirror.DisplayStyle.struct)
349+
return Mirror(self, children: c, displayStyle: .struct)
350350
}
351351
}
352352

Foundation/DateInterval.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ extension DateInterval : CustomStringConvertible, CustomDebugStringConvertible,
183183
c.append((label: "start", value: start))
184184
c.append((label: "end", value: end))
185185
c.append((label: "duration", value: duration))
186-
return Mirror(self, children: c, displayStyle: Mirror.DisplayStyle.struct)
186+
return Mirror(self, children: c, displayStyle: .struct)
187187
}
188188
}
189189

Foundation/EnergyFormatter.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ extension EnergyFormatter {
1919
fileprivate var unitEnergy: UnitEnergy {
2020
switch self {
2121
case .joule:
22-
return UnitEnergy.joules
22+
return .joules
2323
case .kilojoule:
24-
return UnitEnergy.kilojoules
24+
return .kilojoules
2525
case .calorie:
26-
return UnitEnergy.calories
26+
return .calories
2727
case .kilocalorie:
28-
return UnitEnergy.kilocalories
28+
return .kilocalories
2929
}
3030
}
3131

@@ -88,7 +88,7 @@ open class EnergyFormatter: Formatter {
8888
fatalError("Cannot format \(value) as string")
8989
}
9090

91-
let separator = unitStyle == EnergyFormatter.UnitStyle.short ? "" : " "
91+
let separator = unitStyle == .short ? "" : " "
9292
return "\(formattedValue)\(separator)\(unitString(fromValue: value, unit: unit))"
9393
}
9494

Foundation/FoundationErrors.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,21 +174,21 @@ internal func _NSErrorWithErrno(_ posixErrno : Int32, reading : Bool, path : Str
174174
var cocoaError : CocoaError.Code
175175
if reading {
176176
switch posixErrno {
177-
case EFBIG: cocoaError = CocoaError.fileReadTooLarge
178-
case ENOENT: cocoaError = CocoaError.fileReadNoSuchFile
179-
case EPERM, EACCES: cocoaError = CocoaError.fileReadNoPermission
180-
case ENAMETOOLONG: cocoaError = CocoaError.fileReadUnknown
181-
default: cocoaError = CocoaError.fileReadUnknown
177+
case EFBIG: cocoaError = .fileReadTooLarge
178+
case ENOENT: cocoaError = .fileReadNoSuchFile
179+
case EPERM, EACCES: cocoaError = .fileReadNoPermission
180+
case ENAMETOOLONG: cocoaError = .fileReadUnknown
181+
default: cocoaError = .fileReadUnknown
182182
}
183183
} else {
184184
switch posixErrno {
185-
case ENOENT: cocoaError = CocoaError.fileNoSuchFile
186-
case EPERM, EACCES: cocoaError = CocoaError.fileWriteNoPermission
187-
case ENAMETOOLONG: cocoaError = CocoaError.fileWriteInvalidFileName
188-
case EDQUOT, ENOSPC: cocoaError = CocoaError.fileWriteOutOfSpace
189-
case EROFS: cocoaError = CocoaError.fileWriteVolumeReadOnly
190-
case EEXIST: cocoaError = CocoaError.fileWriteFileExists
191-
default: cocoaError = CocoaError.fileWriteUnknown
185+
case ENOENT: cocoaError = .fileNoSuchFile
186+
case EPERM, EACCES: cocoaError = .fileWriteNoPermission
187+
case ENAMETOOLONG: cocoaError = .fileWriteInvalidFileName
188+
case EDQUOT, ENOSPC: cocoaError = .fileWriteOutOfSpace
189+
case EROFS: cocoaError = .fileWriteVolumeReadOnly
190+
case EEXIST: cocoaError = .fileWriteFileExists
191+
default: cocoaError = .fileWriteUnknown
192192
}
193193
}
194194

Foundation/HTTPCookie.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ open class HTTPCookie : NSObject {
615615
//utils for cookie parsing
616616
fileprivate extension String {
617617
func trim() -> String {
618-
return self.trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines)
618+
return self.trimmingCharacters(in: .whitespacesAndNewlines)
619619
}
620620

621621
func removeCommas() -> String {

Foundation/HTTPCookieStorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ open class HTTPCookieStorage: NSObject {
6868
super.init()
6969
let bundlePath = Bundle.main.bundlePath
7070
var bundleName = bundlePath.components(separatedBy: "/").last!
71-
if let range = bundleName.range(of: ".", options: String.CompareOptions.backwards, range: nil, locale: nil) {
71+
if let range = bundleName.range(of: ".", options: .backwards, range: nil, locale: nil) {
7272
bundleName = String(bundleName[..<range.lowerBound])
7373
}
7474
let cookieFolderPath = _CFXDGCreateDataHomePath()._swiftObject + "/" + bundleName

Foundation/IndexPath.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,21 +742,21 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
742742
}
743743

744744
public static func <(lhs: IndexPath, rhs: IndexPath) -> Bool {
745-
return lhs.compare(rhs) == ComparisonResult.orderedAscending
745+
return lhs.compare(rhs) == .orderedAscending
746746
}
747747

748748
public static func <=(lhs: IndexPath, rhs: IndexPath) -> Bool {
749749
let order = lhs.compare(rhs)
750-
return order == ComparisonResult.orderedAscending || order == ComparisonResult.orderedSame
750+
return order == .orderedAscending || order == .orderedSame
751751
}
752752

753753
public static func >(lhs: IndexPath, rhs: IndexPath) -> Bool {
754-
return lhs.compare(rhs) == ComparisonResult.orderedDescending
754+
return lhs.compare(rhs) == .orderedDescending
755755
}
756756

757757
public static func >=(lhs: IndexPath, rhs: IndexPath) -> Bool {
758758
let order = lhs.compare(rhs)
759-
return order == ComparisonResult.orderedDescending || order == ComparisonResult.orderedSame
759+
return order == .orderedDescending || order == .orderedSame
760760
}
761761
}
762762

Foundation/IndexSet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ extension IndexSet : CustomStringConvertible, CustomDebugStringConvertible, Cust
712712
public var customMirror: Mirror {
713713
var c: [(label: String?, value: Any)] = []
714714
c.append((label: "ranges", value: Array(rangeView)))
715-
return Mirror(self, children: c, displayStyle: Mirror.DisplayStyle.struct)
715+
return Mirror(self, children: c, displayStyle: .struct)
716716
}
717717
}
718718

Foundation/JSONSerialization.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,11 @@ private struct JSONReader {
604604

605605
self.step = {
606606
switch encoding {
607-
case String.Encoding.utf8:
607+
case .utf8:
608608
return 1
609-
case String.Encoding.utf16BigEndian, String.Encoding.utf16LittleEndian:
609+
case .utf16BigEndian, .utf16LittleEndian:
610610
return 2
611-
case String.Encoding.utf32BigEndian, String.Encoding.utf32LittleEndian:
611+
case .utf32BigEndian, .utf32LittleEndian:
612612
return 4
613613
default:
614614
return 1
@@ -623,15 +623,15 @@ private struct JSONReader {
623623

624624
let index: Int
625625
switch encoding {
626-
case String.Encoding.utf8:
626+
case .utf8:
627627
index = input
628-
case String.Encoding.utf16BigEndian where buffer[input] == 0:
628+
case .utf16BigEndian where buffer[input] == 0:
629629
index = input + 1
630-
case String.Encoding.utf32BigEndian where buffer[input] == 0 && buffer[input+1] == 0 && buffer[input+2] == 0:
630+
case .utf32BigEndian where buffer[input] == 0 && buffer[input+1] == 0 && buffer[input+2] == 0:
631631
index = input + 3
632-
case String.Encoding.utf16LittleEndian where buffer[input+1] == 0:
632+
case .utf16LittleEndian where buffer[input+1] == 0:
633633
index = input
634-
case String.Encoding.utf32LittleEndian where buffer[input+1] == 0 && buffer[input+2] == 0 && buffer[input+3] == 0:
634+
case .utf32LittleEndian where buffer[input+1] == 0 && buffer[input+2] == 0 && buffer[input+3] == 0:
635635
index = input
636636
default:
637637
return nil
@@ -852,7 +852,7 @@ private struct JSONReader {
852852
}
853853
}
854854

855-
if source.encoding == String.Encoding.utf8 {
855+
if source.encoding == .utf8 {
856856

857857
return parseTypedNumber(source.buffer.baseAddress!.advanced(by: input), count: source.buffer.count - input).map { return ($0.0, input + $0.1) }
858858
}

Foundation/LengthFormatter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ open class LengthFormatter : Formatter {
4848
guard let formattedValue = numberFormatter.string(from:NSNumber(value: value)) else {
4949
fatalError("Cannot format \(value) as string")
5050
}
51-
let separator = unitStyle == LengthFormatter.UnitStyle.short ? "" : " "
51+
let separator = unitStyle == .short ? "" : " "
5252
return "\(formattedValue)\(separator)\(unitString(fromValue: value, unit: unit))"
5353
}
5454

Foundation/MassFormatter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ open class MassFormatter : Formatter {
5454
return stoneString
5555
} else {
5656
let poundsString = string(fromValue: pounds, unit: .pound)
57-
let separator = unitStyle == MassFormatter.UnitStyle.short ? " " : ", "
57+
let separator = unitStyle == .short ? " " : ", "
5858

5959
return ("\(stoneString)\(separator)\(poundsString)")
6060
}
@@ -166,7 +166,7 @@ open class MassFormatter : Formatter {
166166
fatalError("Cannot format \(value) as string")
167167
}
168168

169-
let separator = unitStyle == MassFormatter.UnitStyle.short ? "" : " "
169+
let separator = unitStyle == .short ? "" : " "
170170

171171
return "\(formattedValue)\(separator)\(unitStringDisplayedAdjacent(toValue: value, unit: unit))"
172172
}

Foundation/Measurement.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extension Measurement : CustomStringConvertible, CustomDebugStringConvertible, C
5555
var c: [(label: String?, value: Any)] = []
5656
c.append((label: "value", value: value))
5757
c.append((label: "unit", value: unit.symbol))
58-
return Mirror(self, children: c, displayStyle: Mirror.DisplayStyle.struct)
58+
return Mirror(self, children: c, displayStyle: .struct)
5959
}
6060
}
6161

0 commit comments

Comments
 (0)