Skip to content

Commit d297a34

Browse files
otaviolimaparkera
authored andcommitted
Remove duplicated code on ByteCounterFormatter convertValue function (#1581)
1 parent 2cdcebd commit d297a34

File tree

1 file changed

+11
-38
lines changed

1 file changed

+11
-38
lines changed

Foundation/ByteCountFormatter.swift

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -127,54 +127,27 @@ open class ByteCountFormatter : Formatter {
127127
let byte = Double(byteCount)
128128
if byte == 0, allowsNonnumericFormatting, allowedUnits == [], includesUnit, includesCount {
129129
return partsToIncludeFor(value: "Zero", unit: .KB)
130-
} else if byte == 1 || byte == -1 {
131-
if allowedUnits.contains(.useAll) || allowedUnits == [] {
130+
} else if allowedUnits.contains(.useAll) || allowedUnits == [] {
131+
if byte == 1 || byte == -1 {
132132
return formatNumberFor(bytes: byte, unit: .byte)
133-
} else {
134-
return valueToUseFor(byteCount: byte, unit: allowedUnits)
135-
}
136-
} else if byte < byteSize[.KB]! && byte > -byteSize[.KB]!{
137-
if allowedUnits.contains(.useAll) || allowedUnits == [] {
133+
} else if byte < byteSize[.KB]! && byte > -byteSize[.KB]! {
138134
return formatNumberFor(bytes: byte, unit: .bytes)
139-
} else {
140-
return valueToUseFor(byteCount: byte, unit: allowedUnits)
141-
}
142-
} else if byte < byteSize[.MB]! && byte > -byteSize[.MB]! {
143-
if allowedUnits.contains(.useAll) || allowedUnits == [] {
135+
} else if byte < byteSize[.MB]! && byte > -byteSize[.MB]! {
144136
return divide(byte, by: byteSize, for: .KB)
145-
}
146-
return valueToUseFor(byteCount: byte, unit: allowedUnits)
147-
148-
} else if byte < byteSize[.GB]! && byte > -byteSize[.GB]! {
149-
if allowedUnits.contains(.useAll) || allowedUnits == [] {
137+
} else if byte < byteSize[.GB]! && byte > -byteSize[.GB]! {
150138
return divide(byte, by: byteSize, for: .MB)
151-
}
152-
return valueToUseFor(byteCount: byte, unit: allowedUnits)
153-
154-
} else if byte < byteSize[.TB]! && byte > -byteSize[.TB]! {
155-
if allowedUnits.contains(.useAll) || allowedUnits == [] {
139+
} else if byte < byteSize[.TB]! && byte > -byteSize[.TB]! {
156140
return divide(byte, by: byteSize, for: .GB)
157-
}
158-
return valueToUseFor(byteCount: byte, unit: allowedUnits)
159-
160-
} else if byte < byteSize[.PB]! && byte > -byteSize[.PB]! {
161-
if allowedUnits.contains(.useAll) || allowedUnits == [] {
141+
} else if byte < byteSize[.PB]! && byte > -byteSize[.PB]! {
162142
return divide(byte, by: byteSize, for: .TB)
163-
}
164-
return valueToUseFor(byteCount: byte, unit: allowedUnits)
165-
166-
} else if byte < byteSize[.EB]! && byte > -byteSize[.EB]! {
167-
if allowedUnits.contains(.useAll) || allowedUnits == [] {
143+
} else if byte < byteSize[.EB]! && byte > -byteSize[.EB]! {
168144
return divide(byte, by: byteSize, for: .PB)
169-
}
170-
return valueToUseFor(byteCount: byte, unit: allowedUnits)
171-
172-
} else {
173-
if allowedUnits.contains(.useAll) || allowedUnits == [] {
145+
} else {
174146
return divide(byte, by: byteSize, for: .EB)
175147
}
176-
return valueToUseFor(byteCount: byte, unit: allowedUnits)
177148
}
149+
150+
return valueToUseFor(byteCount: byte, unit: allowedUnits)
178151
}
179152

180153
/*

0 commit comments

Comments
 (0)