Skip to content

Commit d834a1c

Browse files
compnerdparkera
authored andcommitted
Foundation: address a number of warnings (#449)
This is a mechanical change addressing a number of "warning: expected 'let' in conditional" warnings from the current compiler. NFC.
1 parent 1aa6581 commit d834a1c

File tree

6 files changed

+47
-35
lines changed

6 files changed

+47
-35
lines changed

Foundation/NSFileManager.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,13 +755,12 @@ public class FileManager: NSObject {
755755
}
756756

757757
internal func _pathIsSymbolicLink(_ path: String) -> Bool {
758-
guard let
759-
attrs = try? attributesOfItem(atPath: path),
760-
fileType = attrs[NSFileType] as? String
758+
guard
759+
let attrs = try? attributesOfItem(atPath: path),
760+
let fileType = attrs[NSFileType] as? String
761761
else {
762762
return false
763763
}
764-
765764
return fileType == NSFileTypeSymbolicLink
766765
}
767766
}
@@ -999,7 +998,7 @@ extension FileManager {
999998
}
1000999

10011000
override func skipDescendants() {
1002-
if let stream = _stream, current = _current {
1001+
if let stream = _stream, let current = _current {
10031002
fts_set(stream, current, FTS_SKIP)
10041003
}
10051004
}

Foundation/NSHTTPCookie.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,31 +200,31 @@ public class HTTPCookie : NSObject {
200200
/// - Experiment: This is a draft API currently under consideration for official import into Foundation as a suitable alternative
201201
/// - Note: Since this API is under consideration it may be either removed or revised in the near future
202202
public init?(properties: [String : Any]) {
203-
guard let
204-
path = properties[NSHTTPCookiePath] as? String,
205-
name = properties[NSHTTPCookieName] as? String,
206-
value = properties[NSHTTPCookieValue] as? String
203+
guard
204+
let path = properties[NSHTTPCookiePath] as? String,
205+
let name = properties[NSHTTPCookieName] as? String,
206+
let value = properties[NSHTTPCookieValue] as? String
207207
else {
208208
return nil
209209
}
210-
210+
211211
let canonicalDomain: String
212212
if let domain = properties[NSHTTPCookieDomain] as? String {
213213
canonicalDomain = domain
214-
} else if let
215-
originURL = properties[NSHTTPCookieOriginURL] as? URL,
216-
host = originURL.host
214+
} else if
215+
let originURL = properties[NSHTTPCookieOriginURL] as? URL,
216+
let host = originURL.host
217217
{
218218
canonicalDomain = host
219219
} else {
220220
return nil
221221
}
222-
222+
223223
_path = path
224224
_name = name
225225
_value = value
226226
_domain = canonicalDomain
227-
227+
228228
if let
229229
secureString = properties[NSHTTPCookieSecure] as? String
230230
where secureString.characters.count > 0
@@ -269,9 +269,9 @@ public class HTTPCookie : NSObject {
269269
} else {
270270
_expiresDate = nil
271271
}
272-
} else if let
273-
maximumAge = properties[NSHTTPCookieMaximumAge] as? String,
274-
secondsFromNow = Int(maximumAge)
272+
} else if
273+
let maximumAge = properties[NSHTTPCookieMaximumAge] as? String,
274+
let secondsFromNow = Int(maximumAge)
275275
where _version == 1 {
276276
_expiresDate = Date(timeIntervalSinceNow: Double(secondsFromNow))
277277
} else {

Foundation/NSOrderedSet.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ public class NSMutableOrderedSet : NSOrderedSet {
351351
fatalError("\(self): Index out of bounds")
352352
}
353353

354-
if let objectToReplace = objectAtIndex(idx) as? NSObject, object = object as? NSObject {
354+
if let objectToReplace = objectAtIndex(idx) as? NSObject,
355+
let object = object as? NSObject {
355356
_orderedStorage[idx] = object
356357
_storage.remove(objectToReplace)
357358
_storage.insert(object)
@@ -401,7 +402,8 @@ extension NSMutableOrderedSet {
401402
fatalError("\(self): Index out of bounds")
402403
}
403404

404-
if let object1 = objectAtIndex(idx1) as? NSObject, object2 = objectAtIndex(idx2) as? NSObject {
405+
if let object1 = objectAtIndex(idx1) as? NSObject,
406+
let object2 = objectAtIndex(idx2) as? NSObject {
405407
_orderedStorage[idx1] = object2
406408
_orderedStorage[idx2] = object1
407409
}

Foundation/NSURL.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,8 @@ extension NSURL {
692692
public func appendingPathComponent(_ pathComponent: String) -> URL? {
693693
var result : URL? = appendingPathComponent(pathComponent, isDirectory: false)
694694
if !pathComponent.hasSuffix("/") && isFileURL {
695-
if let urlWithoutDirectory = result, path = urlWithoutDirectory.path {
695+
if let urlWithoutDirectory = result,
696+
let path = urlWithoutDirectory.path {
696697
var isDir : Bool = false
697698
if FileManager.default().fileExists(atPath: path, isDirectory: &isDir) && isDir {
698699
result = self.appendingPathComponent(pathComponent, isDirectory: true)

Foundation/NSUserDefaults.swift

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,22 @@ public class UserDefaults: NSObject {
102102
}
103103

104104
public func stringForKey(_ defaultName: String) -> String? {
105-
guard let aVal = objectForKey(defaultName), bVal = aVal as? NSString else {
105+
guard let aVal = objectForKey(defaultName),
106+
let bVal = aVal as? NSString else {
106107
return nil
107108
}
108109
return bVal._swiftObject
109110
}
110111
public func arrayForKey(_ defaultName: String) -> [AnyObject]? {
111-
guard let aVal = objectForKey(defaultName), bVal = aVal as? NSArray else {
112+
guard let aVal = objectForKey(defaultName),
113+
let bVal = aVal as? NSArray else {
112114
return nil
113115
}
114116
return bVal._swiftObject
115117
}
116118
public func dictionaryForKey(_ defaultName: String) -> [String : AnyObject]? {
117-
guard let aVal = objectForKey(defaultName), bVal = aVal as? NSDictionary else {
119+
guard let aVal = objectForKey(defaultName),
120+
let bVal = aVal as? NSDictionary else {
118121
return nil
119122
}
120123
//This got out of hand fast...
@@ -141,37 +144,43 @@ public class UserDefaults: NSObject {
141144
return nil
142145
}
143146
public func dataForKey(_ defaultName: String) -> Data? {
144-
guard let aVal = objectForKey(defaultName), bVal = aVal as? Data else {
147+
guard let aVal = objectForKey(defaultName),
148+
let bVal = aVal as? Data else {
145149
return nil
146150
}
147151
return bVal
148152
}
149153
public func stringArrayForKey(_ defaultName: String) -> [String]? {
150-
guard let aVal = objectForKey(defaultName), bVal = aVal as? NSArray else {
154+
guard let aVal = objectForKey(defaultName),
155+
let bVal = aVal as? NSArray else {
151156
return nil
152157
}
153158
return _expensivePropertyListConversion(bVal) as? [String]
154159
}
155160
public func integerForKey(_ defaultName: String) -> Int {
156-
guard let aVal = objectForKey(defaultName), bVal = aVal as? NSNumber else {
161+
guard let aVal = objectForKey(defaultName),
162+
let bVal = aVal as? NSNumber else {
157163
return 0
158164
}
159165
return bVal.intValue
160166
}
161167
public func floatForKey(_ defaultName: String) -> Float {
162-
guard let aVal = objectForKey(defaultName), bVal = aVal as? NSNumber else {
168+
guard let aVal = objectForKey(defaultName),
169+
let bVal = aVal as? NSNumber else {
163170
return 0
164171
}
165172
return bVal.floatValue
166173
}
167174
public func doubleForKey(_ defaultName: String) -> Double {
168-
guard let aVal = objectForKey(defaultName), bVal = aVal as? NSNumber else {
175+
guard let aVal = objectForKey(defaultName),
176+
let bVal = aVal as? NSNumber else {
169177
return 0
170178
}
171179
return bVal.doubleValue
172180
}
173181
public func boolForKey(_ defaultName: String) -> Bool {
174-
guard let aVal = objectForKey(defaultName), bVal = aVal as? NSNumber else {
182+
guard let aVal = objectForKey(defaultName),
183+
let bVal = aVal as? NSNumber else {
175184
return false
176185
}
177186
return bVal.boolValue

Foundation/NSXMLParser.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,22 @@ internal func _NSXMLParserExternalEntityWithURL(_ interface: _CFXMLInterface, ur
9090
guard let aUrl = a else { break }
9191

9292
var matches: Bool
93-
if let aHost = aUrl.host, host = url.host {
93+
if let aHost = aUrl.host, let host = url.host {
9494
matches = host == aHost
9595
} else {
9696
return nil
9797
}
9898

9999
if matches {
100-
if let aPort = aUrl.port, port = url.port {
100+
if let aPort = aUrl.port, let port = url.port {
101101
matches = port == aPort
102102
} else {
103103
return nil
104104
}
105105
}
106106

107107
if matches {
108-
if let aScheme = aUrl.scheme, scheme = url.scheme {
108+
if let aScheme = aUrl.scheme, let scheme = url.scheme {
109109
matches = scheme == aScheme
110110
} else {
111111
return nil
@@ -266,12 +266,13 @@ internal func _NSXMLParserStartElementNs(_ ctx: _CFXMLInterface, localname: Unsa
266266
}
267267
let namespaceValueString = namespaces[idx + 1] != nil ? UTF8STRING(namespaces[idx + 1]!) : ""
268268
if reportNamespaces {
269-
if let k = namespaceNameString, v = namespaceValueString {
269+
if let k = namespaceNameString, let v = namespaceValueString {
270270
nsDict[k] = v
271271
}
272272
}
273273
if !reportQNameURI {
274-
if let k = asAttrNamespaceNameString, v = namespaceValueString {
274+
if let k = asAttrNamespaceNameString,
275+
let v = namespaceValueString {
275276
attrDict[k] = v
276277
}
277278
}

0 commit comments

Comments
 (0)