Skip to content

Foundation: clear up some unused return value warnings #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Foundation/NSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -392,20 +392,20 @@ extension NSData {
}
return NSData(bytes: bytes.advanced(by: range.location), length: range.length)
}

internal func makeTemporaryFileInDirectory(_ dirPath: String) throws -> (Int32, String) {
let template = dirPath._nsObject.stringByAppendingPathComponent("tmp.XXXXXX")
let maxLength = Int(PATH_MAX) + 1
var buf = [Int8](repeating: 0, count: maxLength)
template._nsObject.getFileSystemRepresentation(&buf, maxLength: maxLength)
let _ = template._nsObject.getFileSystemRepresentation(&buf, maxLength: maxLength)
let fd = mkstemp(&buf)
if fd == -1 {
throw _NSErrorWithErrno(errno, reading: false, path: dirPath)
}
let pathResult = NSFileManager.defaultManager().string(withFileSystemRepresentation:buf, length: Int(strlen(buf)))
return (fd, pathResult)
}

internal class func writeToFileDescriptor(_ fd: Int32, path: String? = nil, buf: UnsafePointer<Void>, length: Int) throws {
var bytesRemaining = length
while bytesRemaining > 0 {
Expand Down
6 changes: 3 additions & 3 deletions Foundation/NSDate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ public class NSDate : NSObject, NSCopying, NSSecureCoding, NSCoding {
public var timeIntervalSinceReferenceDate: NSTimeInterval {
return _timeIntervalSinceReferenceDate
}

public convenience override init() {
var tv = timeval()
withUnsafeMutablePointer(&tv) { t in
let _ = withUnsafeMutablePointer(&tv) { t in
gettimeofday(t, nil)
}
var timestamp = NSTimeInterval(tv.tv_sec) - NSTimeIntervalSince1970
timestamp += NSTimeInterval(tv.tv_usec) / 1000000.0
self.init(timeIntervalSinceReferenceDate: timestamp)
}

public required init(timeIntervalSinceReferenceDate ti: NSTimeInterval) {
_timeIntervalSinceReferenceDate = ti
}
Expand Down
12 changes: 6 additions & 6 deletions Foundation/NSFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public class NSFileManager : NSObject {
}
}
}

public func removeItem(atPath path: String) throws {
if rmdir(path) == 0 {
return
Expand All @@ -471,12 +471,12 @@ public class NSFileManager : NSObject {
let stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR, nil)
ps.deinitialize(count: 2)
ps.deallocateCapacity(2)

if stream != nil {
defer {
fts_close(stream)
}

var current = fts_read(stream)
while current != nil {
switch Int32(current!.pointee.fts_info) {
Expand All @@ -496,7 +496,7 @@ public class NSFileManager : NSObject {
current = fts_read(stream)
}
} else {
_NSErrorWithErrno(ENOTEMPTY, reading: false, path: path)
let _ = _NSErrorWithErrno(ENOTEMPTY, reading: false, path: path)
}
// TODO: Error handling if fts_read fails.

Expand All @@ -506,7 +506,7 @@ public class NSFileManager : NSObject {
throw _NSErrorWithErrno(errno, reading: false, path: path)
}
}

public func copyItem(at srcURL: NSURL, to dstURL: NSURL) throws {
guard srcURL.fileURL else {
throw NSError(domain: NSCocoaErrorDomain, code: NSCocoaError.FileWriteUnsupportedSchemeError.rawValue, userInfo: [NSURLErrorKey : srcURL])
Expand Down Expand Up @@ -607,7 +607,7 @@ public class NSFileManager : NSObject {
return true
}
// chase the link; too bad if it is a slink to /Net/foo
stat(path, &s) >= 0
stat(path, &s)
}
} else {
return false
Expand Down
8 changes: 4 additions & 4 deletions Foundation/NSGeometry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -786,16 +786,16 @@ private func _scanDoublesFromString(_ aString: String, number: Int) -> [Double]
digitSet.addCharacters(in: "-")
var result = [Double](repeating: 0.0, count: number)
var index = 0
scanner.scanUpToCharactersFromSet(digitSet)

let _ = scanner.scanUpToCharactersFromSet(digitSet)
while !scanner.atEnd && index < number {
if let num = scanner.scanDouble() {
result[index] = num
}
scanner.scanUpToCharactersFromSet(digitSet)
let _ = scanner.scanUpToCharactersFromSet(digitSet)
index += 1
}

return result
}

Expand Down
20 changes: 9 additions & 11 deletions Foundation/NSIndexSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,17 @@ public class NSIndexSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding

return result
}

public func enumerateIndexesUsingBlock(_ block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
enumerateIndexesWithOptions([], usingBlock: block)
}
public func enumerateIndexesWithOptions(_ opts: NSEnumerationOptions, usingBlock block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
_enumerateWithOptions(opts, range: NSMakeRange(0, Int.max), paramType: Int.self, returnType: Void.self, block: block)
let _ = _enumerateWithOptions(opts, range: NSMakeRange(0, Int.max), paramType: Int.self, returnType: Void.self, block: block)
}
public func enumerateIndexesInRange(_ range: NSRange, options opts: NSEnumerationOptions, usingBlock block: (Int, UnsafeMutablePointer<ObjCBool>) -> Void) {
_enumerateWithOptions(opts, range: range, paramType: Int.self, returnType: Void.self, block: block)
let _ = _enumerateWithOptions(opts, range: range, paramType: Int.self, returnType: Void.self, block: block)
}

public func indexPassingTest(_ predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int {
return indexWithOptions([], passingTest: predicate)
}
Expand All @@ -417,30 +417,28 @@ public class NSIndexSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding
}
public func indexesInRange(_ range: NSRange, options opts: NSEnumerationOptions, passingTest predicate: (Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet {
let result = NSMutableIndexSet()
_enumerateWithOptions(opts, range: range, paramType: Int.self, returnType: Void.self) { idx, stop in
let _ = _enumerateWithOptions(opts, range: range, paramType: Int.self, returnType: Void.self) { idx, stop in
if predicate(idx, stop) {
result.addIndex(idx)
}
}
return result
}

/*
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.

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.
*/
public func enumerateRangesUsingBlock(_ block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
enumerateRangesWithOptions([], usingBlock: block)
}
public func enumerateRangesWithOptions(_ opts: NSEnumerationOptions, usingBlock block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
_enumerateWithOptions(opts, range: NSMakeRange(0, Int.max), paramType: NSRange.self, returnType: Void.self, block: block)
let _ = _enumerateWithOptions(opts, range: NSMakeRange(0, Int.max), paramType: NSRange.self, returnType: Void.self, block: block)
}
public func enumerateRangesInRange(_ range: NSRange, options opts: NSEnumerationOptions, usingBlock block: (NSRange, UnsafeMutablePointer<ObjCBool>) -> Void) {
_enumerateWithOptions(opts, range: range, paramType: NSRange.self, returnType: Void.self, block: block)
let _ = _enumerateWithOptions(opts, range: range, paramType: NSRange.self, returnType: Void.self, block: block)
}


}

extension NSIndexSet : Sequence {
Expand Down
36 changes: 18 additions & 18 deletions Foundation/NSKeyedArchiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,26 +202,26 @@ public class NSKeyedArchiver : NSCoder {
private func _writeBinaryData(_ plist : NSDictionary) -> Bool {
return __CFBinaryPlistWriteToStream(plist, self._stream) > 0
}

public func finishEncoding() {
if _flags.contains(ArchiverFlags.FinishedEncoding) {
return
}

var plist = Dictionary<String, Any>()
var success : Bool

plist["$archiver"] = NSStringFromClass(self.dynamicType)
plist["$version"] = NSKeyedArchivePlistVersion
plist["$objects"] = self._objects
plist["$top"] = self._containers[0].dict

if let unwrappedDelegate = self.delegate {
unwrappedDelegate.archiverWillFinish(self)
}

let nsPlist = plist.bridge()

if self.outputFormat == NSPropertyListFormat.XMLFormat_v1_0 {
success = _writeXMLData(nsPlist)
} else {
Expand All @@ -233,10 +233,10 @@ public class NSKeyedArchiver : NSCoder {
}

if success {
self._flags.insert(ArchiverFlags.FinishedEncoding)
let _ = self._flags.insert(ArchiverFlags.FinishedEncoding)
}
}

public class func setClassName(_ codedName: String?, forClass cls: AnyClass) {
let clsName = String(cls.dynamicType)
_classNameMapLock.synchronized {
Expand Down Expand Up @@ -555,8 +555,8 @@ public class NSKeyedArchiver : NSCoder {
var objectRef : CFKeyedArchiverUID? // encoded object reference
let haveVisited : Bool

_validateStillEncoding()
let _ = _validateStillEncoding()

haveVisited = _haveVisited(objv)
object = _replacementObject(objv)

Expand All @@ -565,9 +565,9 @@ public class NSKeyedArchiver : NSCoder {
// we can return nil if the object is being conditionally encoded
return nil
}

_validateObjectSupportsSecureCoding(object)

if !haveVisited {
var encodedObject : Any

Expand All @@ -578,7 +578,7 @@ public class NSKeyedArchiver : NSCoder {

let innerEncodingContext = EncodingContext()
var cls : AnyClass?

_pushEncodingContext(innerEncodingContext)
codable.encodeWithCoder(self)

Expand All @@ -587,17 +587,17 @@ public class NSKeyedArchiver : NSCoder {
if cls == nil {
cls = object!.dynamicType
}

_setObjectInCurrentEncodingContext(_classReference(cls!), forKey: "$class", escape: false)
_popEncodingContext()
encodedObject = innerEncodingContext.dict
} else {
encodedObject = object!
}

_setObject(encodedObject, forReference: unwrappedObjectRef)
}

if let unwrappedDelegate = self.delegate {
unwrappedDelegate.archiver(self, didEncodeObject: object)
}
Expand Down Expand Up @@ -643,12 +643,12 @@ public class NSKeyedArchiver : NSCoder {
}
encodeObject(aPropertyList, forKey: key)
}

public func _encodePropertyList(_ aPropertyList: AnyObject, forKey key: String? = nil) {
_validateStillEncoding()
let _ = _validateStillEncoding()
_setObjectInCurrentEncodingContext(aPropertyList, forKey: key)
}

internal func _encodeValue<T: NSObject where T: NSCoding>(_ objv: T, forKey key: String? = nil) {
_encodePropertyList(objv, forKey: key)
}
Expand Down Expand Up @@ -808,7 +808,7 @@ public class NSKeyedArchiver : NSCoder {
}
set {
if newValue {
_flags.insert(ArchiverFlags.RequiresSecureCoding)
let _ = _flags.insert(ArchiverFlags.RequiresSecureCoding)
} else {
_flags.remove(ArchiverFlags.RequiresSecureCoding)
}
Expand Down
Loading