Skip to content

Commit 182d5c9

Browse files
compnerdphausler
authored andcommitted
Foundation: clear up some unused return value warnings (#366)
This just cleans up a set of unused-return-value warnings in the Foundation implementation. NFC.
1 parent 3fe5b24 commit 182d5c9

15 files changed

+132
-134
lines changed

Foundation/NSData.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,20 +392,20 @@ extension NSData {
392392
}
393393
return NSData(bytes: bytes.advanced(by: range.location), length: range.length)
394394
}
395-
395+
396396
internal func makeTemporaryFileInDirectory(_ dirPath: String) throws -> (Int32, String) {
397397
let template = dirPath._nsObject.stringByAppendingPathComponent("tmp.XXXXXX")
398398
let maxLength = Int(PATH_MAX) + 1
399399
var buf = [Int8](repeating: 0, count: maxLength)
400-
template._nsObject.getFileSystemRepresentation(&buf, maxLength: maxLength)
400+
let _ = template._nsObject.getFileSystemRepresentation(&buf, maxLength: maxLength)
401401
let fd = mkstemp(&buf)
402402
if fd == -1 {
403403
throw _NSErrorWithErrno(errno, reading: false, path: dirPath)
404404
}
405405
let pathResult = NSFileManager.defaultManager().string(withFileSystemRepresentation:buf, length: Int(strlen(buf)))
406406
return (fd, pathResult)
407407
}
408-
408+
409409
internal class func writeToFileDescriptor(_ fd: Int32, path: String? = nil, buf: UnsafePointer<Void>, length: Int) throws {
410410
var bytesRemaining = length
411411
while bytesRemaining > 0 {

Foundation/NSDate.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ public class NSDate : NSObject, NSCopying, NSSecureCoding, NSCoding {
5050
public var timeIntervalSinceReferenceDate: NSTimeInterval {
5151
return _timeIntervalSinceReferenceDate
5252
}
53-
53+
5454
public convenience override init() {
5555
var tv = timeval()
56-
withUnsafeMutablePointer(&tv) { t in
56+
let _ = withUnsafeMutablePointer(&tv) { t in
5757
gettimeofday(t, nil)
5858
}
5959
var timestamp = NSTimeInterval(tv.tv_sec) - NSTimeIntervalSince1970
6060
timestamp += NSTimeInterval(tv.tv_usec) / 1000000.0
6161
self.init(timeIntervalSinceReferenceDate: timestamp)
6262
}
63-
63+
6464
public required init(timeIntervalSinceReferenceDate ti: NSTimeInterval) {
6565
_timeIntervalSinceReferenceDate = ti
6666
}

Foundation/NSFileManager.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public class NSFileManager : NSObject {
458458
}
459459
}
460460
}
461-
461+
462462
public func removeItem(atPath path: String) throws {
463463
if rmdir(path) == 0 {
464464
return
@@ -471,12 +471,12 @@ public class NSFileManager : NSObject {
471471
let stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil)
472472
ps.deinitialize(count: 2)
473473
ps.deallocateCapacity(2)
474-
474+
475475
if stream != nil {
476476
defer {
477477
fts_close(stream)
478478
}
479-
479+
480480
var current = fts_read(stream)
481481
while current != nil {
482482
switch Int32(current!.pointee.fts_info) {
@@ -496,7 +496,7 @@ public class NSFileManager : NSObject {
496496
current = fts_read(stream)
497497
}
498498
} else {
499-
_NSErrorWithErrno(ENOTEMPTY, reading: false, path: path)
499+
let _ = _NSErrorWithErrno(ENOTEMPTY, reading: false, path: path)
500500
}
501501
// TODO: Error handling if fts_read fails.
502502

@@ -506,7 +506,7 @@ public class NSFileManager : NSObject {
506506
throw _NSErrorWithErrno(errno, reading: false, path: path)
507507
}
508508
}
509-
509+
510510
public func copyItem(at srcURL: NSURL, to dstURL: NSURL) throws {
511511
guard srcURL.fileURL else {
512512
throw NSError(domain: NSCocoaErrorDomain, code: NSCocoaError.FileWriteUnsupportedSchemeError.rawValue, userInfo: [NSURLErrorKey : srcURL])
@@ -607,7 +607,7 @@ public class NSFileManager : NSObject {
607607
return true
608608
}
609609
// chase the link; too bad if it is a slink to /Net/foo
610-
stat(path, &s) >= 0
610+
stat(path, &s)
611611
}
612612
} else {
613613
return false

Foundation/NSGeometry.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -786,16 +786,16 @@ private func _scanDoublesFromString(_ aString: String, number: Int) -> [Double]
786786
digitSet.addCharacters(in: "-")
787787
var result = [Double](repeating: 0.0, count: number)
788788
var index = 0
789-
790-
scanner.scanUpToCharactersFromSet(digitSet)
789+
790+
let _ = scanner.scanUpToCharactersFromSet(digitSet)
791791
while !scanner.atEnd && index < number {
792792
if let num = scanner.scanDouble() {
793793
result[index] = num
794794
}
795-
scanner.scanUpToCharactersFromSet(digitSet)
795+
let _ = scanner.scanUpToCharactersFromSet(digitSet)
796796
index += 1
797797
}
798-
798+
799799
return result
800800
}
801801

Foundation/NSIndexSet.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -388,17 +388,17 @@ public class NSIndexSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding
388388

389389
return result
390390
}
391-
391+
392392
public func enumerateIndexesUsingBlock(_ block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
393393
enumerateIndexesWithOptions([], usingBlock: block)
394394
}
395395
public func enumerateIndexesWithOptions(_ opts: NSEnumerationOptions, usingBlock block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
396-
_enumerateWithOptions(opts, range: NSMakeRange(0, Int.max), paramType: Int.self, returnType: Void.self, block: block)
396+
let _ = _enumerateWithOptions(opts, range: NSMakeRange(0, Int.max), paramType: Int.self, returnType: Void.self, block: block)
397397
}
398398
public func enumerateIndexesInRange(_ range: NSRange, options opts: NSEnumerationOptions, usingBlock block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
399-
_enumerateWithOptions(opts, range: range, paramType: Int.self, returnType: Void.self, block: block)
399+
let _ = _enumerateWithOptions(opts, range: range, paramType: Int.self, returnType: Void.self, block: block)
400400
}
401-
401+
402402
public func indexPassingTest(_ predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
403403
return indexWithOptions([], passingTest: predicate)
404404
}
@@ -417,30 +417,28 @@ public class NSIndexSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding
417417
}
418418
public func indexesInRange(_ range: NSRange, options opts: NSEnumerationOptions, passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
419419
let result = NSMutableIndexSet()
420-
_enumerateWithOptions(opts, range: range, paramType: Int.self, returnType: Void.self) { idx, stop in
420+
let _ = _enumerateWithOptions(opts, range: range, paramType: Int.self, returnType: Void.self) { idx, stop in
421421
if predicate(idx, stop) {
422422
result.addIndex(idx)
423423
}
424424
}
425425
return result
426426
}
427-
427+
428428
/*
429429
The following three convenience methods allow you to enumerate the indexes in the receiver by ranges of contiguous indexes. The performance of these methods is not guaranteed to be any better than if they were implemented with enumerateIndexesInRange:options:usingBlock:. However, depending on the receiver's implementation, they may perform better than that.
430-
430+
431431
If the specified range for enumeration intersects a range of contiguous indexes in the receiver, then the block will be invoked with the intersection of those two ranges.
432432
*/
433433
public func enumerateRangesUsingBlock(_ block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
434434
enumerateRangesWithOptions([], usingBlock: block)
435435
}
436436
public func enumerateRangesWithOptions(_ opts: NSEnumerationOptions, usingBlock block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
437-
_enumerateWithOptions(opts, range: NSMakeRange(0, Int.max), paramType: NSRange.self, returnType: Void.self, block: block)
437+
let _ = _enumerateWithOptions(opts, range: NSMakeRange(0, Int.max), paramType: NSRange.self, returnType: Void.self, block: block)
438438
}
439439
public func enumerateRangesInRange(_ range: NSRange, options opts: NSEnumerationOptions, usingBlock block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
440-
_enumerateWithOptions(opts, range: range, paramType: NSRange.self, returnType: Void.self, block: block)
440+
let _ = _enumerateWithOptions(opts, range: range, paramType: NSRange.self, returnType: Void.self, block: block)
441441
}
442-
443-
444442
}
445443

446444
extension NSIndexSet : Sequence {

Foundation/NSKeyedArchiver.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -202,26 +202,26 @@ public class NSKeyedArchiver : NSCoder {
202202
private func _writeBinaryData(_ plist : NSDictionary) -> Bool {
203203
return __CFBinaryPlistWriteToStream(plist, self._stream) > 0
204204
}
205-
205+
206206
public func finishEncoding() {
207207
if _flags.contains(ArchiverFlags.FinishedEncoding) {
208208
return
209209
}
210210

211211
var plist = Dictionary<String, Any>()
212212
var success : Bool
213-
213+
214214
plist["$archiver"] = NSStringFromClass(self.dynamicType)
215215
plist["$version"] = NSKeyedArchivePlistVersion
216216
plist["$objects"] = self._objects
217217
plist["$top"] = self._containers[0].dict
218-
218+
219219
if let unwrappedDelegate = self.delegate {
220220
unwrappedDelegate.archiverWillFinish(self)
221221
}
222222

223223
let nsPlist = plist.bridge()
224-
224+
225225
if self.outputFormat == NSPropertyListFormat.XMLFormat_v1_0 {
226226
success = _writeXMLData(nsPlist)
227227
} else {
@@ -233,10 +233,10 @@ public class NSKeyedArchiver : NSCoder {
233233
}
234234

235235
if success {
236-
self._flags.insert(ArchiverFlags.FinishedEncoding)
236+
let _ = self._flags.insert(ArchiverFlags.FinishedEncoding)
237237
}
238238
}
239-
239+
240240
public class func setClassName(_ codedName: String?, forClass cls: AnyClass) {
241241
let clsName = String(cls.dynamicType)
242242
_classNameMapLock.synchronized {
@@ -556,8 +556,8 @@ public class NSKeyedArchiver : NSCoder {
556556
var objectRef : CFKeyedArchiverUID? // encoded object reference
557557
let haveVisited : Bool
558558

559-
_validateStillEncoding()
560-
559+
let _ = _validateStillEncoding()
560+
561561
haveVisited = _haveVisited(objv)
562562
object = _replacementObject(objv)
563563

@@ -566,9 +566,9 @@ public class NSKeyedArchiver : NSCoder {
566566
// we can return nil if the object is being conditionally encoded
567567
return nil
568568
}
569-
569+
570570
_validateObjectSupportsSecureCoding(object)
571-
571+
572572
if !haveVisited {
573573
var encodedObject : Any
574574

@@ -579,7 +579,7 @@ public class NSKeyedArchiver : NSCoder {
579579

580580
let innerEncodingContext = EncodingContext()
581581
var cls : AnyClass?
582-
582+
583583
_pushEncodingContext(innerEncodingContext)
584584
codable.encodeWithCoder(self)
585585

@@ -588,17 +588,17 @@ public class NSKeyedArchiver : NSCoder {
588588
if cls == nil {
589589
cls = object!.dynamicType
590590
}
591-
591+
592592
_setObjectInCurrentEncodingContext(_classReference(cls!), forKey: "$class", escape: false)
593593
_popEncodingContext()
594594
encodedObject = innerEncodingContext.dict
595595
} else {
596596
encodedObject = object!
597597
}
598-
598+
599599
_setObject(encodedObject, forReference: unwrappedObjectRef)
600600
}
601-
601+
602602
if let unwrappedDelegate = self.delegate {
603603
unwrappedDelegate.archiver(self, didEncodeObject: object)
604604
}
@@ -644,12 +644,12 @@ public class NSKeyedArchiver : NSCoder {
644644
}
645645
encodeObject(aPropertyList, forKey: key)
646646
}
647-
647+
648648
public func _encodePropertyList(_ aPropertyList: AnyObject, forKey key: String? = nil) {
649-
_validateStillEncoding()
649+
let _ = _validateStillEncoding()
650650
_setObjectInCurrentEncodingContext(aPropertyList, forKey: key)
651651
}
652-
652+
653653
internal func _encodeValue<T: NSObject where T: NSCoding>(_ objv: T, forKey key: String? = nil) {
654654
_encodePropertyList(objv, forKey: key)
655655
}
@@ -809,7 +809,7 @@ public class NSKeyedArchiver : NSCoder {
809809
}
810810
set {
811811
if newValue {
812-
_flags.insert(ArchiverFlags.RequiresSecureCoding)
812+
let _ = _flags.insert(ArchiverFlags.RequiresSecureCoding)
813813
} else {
814814
_flags.remove(ArchiverFlags.RequiresSecureCoding)
815815
}

0 commit comments

Comments
 (0)