Merge pull request #826 from ikesyo/nsgeometry-operator-static-func
diff --git a/Docs/Status.md b/Docs/Status.md
index 92f3393..d47cabf 100644
--- a/Docs/Status.md
+++ b/Docs/Status.md
@@ -123,7 +123,7 @@
| Entity Name | Status | Test Coverage | Notes |
|-----------------------------|-----------------|---------------|-------------------------------------------------------------------------------|
| `NSJSONSerialization` | Mostly Complete | Substantial | `jsonObject(with:options:)` with streams remains unimplemented |
- | `NSKeyedArchiver` | Mostly Complete | Substantial | `init()` and `encodedData` remain unimplemented |
+ | `NSKeyedArchiver` | Complete | Substantial | |
| `NSKeyedCoderOldStyleArray` | N/A | N/A | For internal use only |
| `NSKeyedUnarchiver` | Mostly Complete | Substantial | `decodingFailurePolicy.set` remains unimplemented |
| `NSKeyedArchiverHelpers` | N/A | N/A | For internal use only |
diff --git a/Foundation/Data.swift b/Foundation/Data.swift
index 842f1ea..5bfdfe3 100644
--- a/Foundation/Data.swift
+++ b/Foundation/Data.swift
@@ -1277,7 +1277,7 @@
/// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`.
@inline(__always)
public mutating func append<SourceType>(_ buffer : UnsafeBufferPointer<SourceType>) {
- if buffer.count == 0 { return }
+ if buffer.isEmpty { return }
if !isKnownUniquelyReferenced(&_backing) {
_backing = _backing.mutableCopy()
}
diff --git a/Foundation/Locale.swift b/Foundation/Locale.swift
index f5b9eab..29b58ba 100644
--- a/Foundation/Locale.swift
+++ b/Foundation/Locale.swift
@@ -428,13 +428,13 @@
return _wrapped.hash
}
}
-}
-public func ==(lhs: Locale, rhs: Locale) -> Bool {
- if lhs._autoupdating || rhs._autoupdating {
- return lhs._autoupdating == rhs._autoupdating
- } else {
- return lhs._wrapped.isEqual(rhs._wrapped)
+ public static func ==(lhs: Locale, rhs: Locale) -> Bool {
+ if lhs._autoupdating || rhs._autoupdating {
+ return lhs._autoupdating == rhs._autoupdating
+ } else {
+ return lhs._wrapped.isEqual(rhs._wrapped)
+ }
}
}
diff --git a/Foundation/NSCFArray.swift b/Foundation/NSCFArray.swift
index 17a13cf..b7ba101 100644
--- a/Foundation/NSCFArray.swift
+++ b/Foundation/NSCFArray.swift
@@ -62,7 +62,7 @@
} else {
let value = _SwiftValue.store(arr.object(at: index))
let container: NSMutableDictionary
- if arr._storage.count == 0 {
+ if arr._storage.isEmpty {
container = NSMutableDictionary()
arr._storage.append(container)
} else {
@@ -84,7 +84,7 @@
let index = idx + range.location
let value = _SwiftValue.store(arr.object(at: index))
let container: NSMutableDictionary
- if arr._storage.count == 0 {
+ if arr._storage.isEmpty {
container = NSMutableDictionary()
arr._storage.append(container)
} else {
diff --git a/Foundation/NSCalendar.swift b/Foundation/NSCalendar.swift
index 3391919..d350d6f 100644
--- a/Foundation/NSCalendar.swift
+++ b/Foundation/NSCalendar.swift
@@ -112,12 +112,14 @@
}
}
-public func ==(_ lhs: NSCalendar.Identifier, _ rhs: NSCalendar.Identifier) -> Bool {
- return lhs.rawValue == rhs.rawValue
-}
+extension NSCalendar.Identifier {
+ public static func ==(_ lhs: NSCalendar.Identifier, _ rhs: NSCalendar.Identifier) -> Bool {
+ return lhs.rawValue == rhs.rawValue
+ }
-public func <(_ lhs: NSCalendar.Identifier, _ rhs: NSCalendar.Identifier) -> Bool {
- return lhs.rawValue < rhs.rawValue
+ public static func <(_ lhs: NSCalendar.Identifier, _ rhs: NSCalendar.Identifier) -> Bool {
+ return lhs.rawValue < rhs.rawValue
+ }
}
open class NSCalendar : NSObject, NSCopying, NSSecureCoding {
@@ -603,8 +605,7 @@
}
return vector.withUnsafeMutableBufferPointer { (vecBuffer: inout UnsafeMutableBufferPointer<UnsafeMutablePointer<Int32>>) in
- _CFCalendarGetComponentDifferenceV(_cfObject, startingDate.timeIntervalSinceReferenceDate, resultDate.timeIntervalSinceReferenceDate, CFOptionFlags(opts.rawValue), compDesc, vecBuffer.baseAddress!, Int32(vector.count))
- return false
+ return _CFCalendarGetComponentDifferenceV(_cfObject, startingDate.timeIntervalSinceReferenceDate, resultDate.timeIntervalSinceReferenceDate, CFOptionFlags(opts.rawValue), compDesc, vecBuffer.baseAddress!, Int32(vector.count))
}
}
if res {
diff --git a/Foundation/NSCompoundPredicate.swift b/Foundation/NSCompoundPredicate.swift
index c7a83ac..0efd6ab 100644
--- a/Foundation/NSCompoundPredicate.swift
+++ b/Foundation/NSCompoundPredicate.swift
@@ -20,7 +20,7 @@
open class NSCompoundPredicate : NSPredicate {
public init(type: LogicalType, subpredicates: [NSPredicate]) {
- if type == .not && subpredicates.count == 0 {
+ if type == .not && subpredicates.isEmpty {
preconditionFailure("Unsupported predicate count of \(subpredicates.count) for \(type)")
}
diff --git a/Foundation/NSData.swift b/Foundation/NSData.swift
index 0d1918b..fe42548 100644
--- a/Foundation/NSData.swift
+++ b/Foundation/NSData.swift
@@ -800,7 +800,7 @@
if options.contains(.endLineWithLineFeed) { separator.append(10) }
//if the kind of line ending to insert is not specified, the default line ending is Carriage Return + Line Feed.
- if separator.count == 0 {separator = [13,10]}
+ if separator.isEmpty { separator = [13,10] }
return (lineLength,separator)
}()
diff --git a/Foundation/NSGeometry.swift b/Foundation/NSGeometry.swift
index 8fc702a..7730764 100644
--- a/Foundation/NSGeometry.swift
+++ b/Foundation/NSGeometry.swift
@@ -321,38 +321,38 @@
}
}
-public struct NSAlignmentOptions : OptionSet {
+public struct AlignmentOptions : OptionSet {
public var rawValue : UInt64
public init(rawValue: UInt64) { self.rawValue = rawValue }
- public static let AlignMinXInward = NSAlignmentOptions(rawValue: 1 << 0)
- public static let AlignMinYInward = NSAlignmentOptions(rawValue: 1 << 1)
- public static let AlignMaxXInward = NSAlignmentOptions(rawValue: 1 << 2)
- public static let AlignMaxYInward = NSAlignmentOptions(rawValue: 1 << 3)
- public static let AlignWidthInward = NSAlignmentOptions(rawValue: 1 << 4)
- public static let AlignHeightInward = NSAlignmentOptions(rawValue: 1 << 5)
+ public static let alignMinXInward = AlignmentOptions(rawValue: 1 << 0)
+ public static let alignMinYInward = AlignmentOptions(rawValue: 1 << 1)
+ public static let alignMaxXInward = AlignmentOptions(rawValue: 1 << 2)
+ public static let alignMaxYInward = AlignmentOptions(rawValue: 1 << 3)
+ public static let alignWidthInward = AlignmentOptions(rawValue: 1 << 4)
+ public static let alignHeightInward = AlignmentOptions(rawValue: 1 << 5)
- public static let AlignMinXOutward = NSAlignmentOptions(rawValue: 1 << 8)
- public static let AlignMinYOutward = NSAlignmentOptions(rawValue: 1 << 9)
- public static let AlignMaxXOutward = NSAlignmentOptions(rawValue: 1 << 10)
- public static let AlignMaxYOutward = NSAlignmentOptions(rawValue: 1 << 11)
- public static let AlignWidthOutward = NSAlignmentOptions(rawValue: 1 << 12)
- public static let AlignHeightOutward = NSAlignmentOptions(rawValue: 1 << 13)
+ public static let alignMinXOutward = AlignmentOptions(rawValue: 1 << 8)
+ public static let alignMinYOutward = AlignmentOptions(rawValue: 1 << 9)
+ public static let alignMaxXOutward = AlignmentOptions(rawValue: 1 << 10)
+ public static let alignMaxYOutward = AlignmentOptions(rawValue: 1 << 11)
+ public static let alignWidthOutward = AlignmentOptions(rawValue: 1 << 12)
+ public static let alignHeightOutward = AlignmentOptions(rawValue: 1 << 13)
- public static let AlignMinXNearest = NSAlignmentOptions(rawValue: 1 << 16)
- public static let AlignMinYNearest = NSAlignmentOptions(rawValue: 1 << 17)
- public static let AlignMaxXNearest = NSAlignmentOptions(rawValue: 1 << 18)
- public static let AlignMaxYNearest = NSAlignmentOptions(rawValue: 1 << 19)
- public static let AlignWidthNearest = NSAlignmentOptions(rawValue: 1 << 20)
- public static let AlignHeightNearest = NSAlignmentOptions(rawValue: 1 << 21)
+ public static let alignMinXNearest = AlignmentOptions(rawValue: 1 << 16)
+ public static let alignMinYNearest = AlignmentOptions(rawValue: 1 << 17)
+ public static let alignMaxXNearest = AlignmentOptions(rawValue: 1 << 18)
+ public static let alignMaxYNearest = AlignmentOptions(rawValue: 1 << 19)
+ public static let alignWidthNearest = AlignmentOptions(rawValue: 1 << 20)
+ public static let alignHeightNearest = AlignmentOptions(rawValue: 1 << 21)
// pass this if the rect is in a flipped coordinate system. This allows 0.5 to be treated in a visually consistent way.
- public static let AlignRectFlipped = NSAlignmentOptions(rawValue: 1 << 63)
+ public static let alignRectFlipped = AlignmentOptions(rawValue: 1 << 63)
// convenience combinations
- public static let AlignAllEdgesInward = [NSAlignmentOptions.AlignMinXInward, NSAlignmentOptions.AlignMaxXInward, NSAlignmentOptions.AlignMinYInward, NSAlignmentOptions.AlignMaxYInward]
- public static let AlignAllEdgesOutward = [NSAlignmentOptions.AlignMinXOutward, NSAlignmentOptions.AlignMaxXOutward, NSAlignmentOptions.AlignMinYOutward, NSAlignmentOptions.AlignMaxYOutward]
- public static let AlignAllEdgesNearest = [NSAlignmentOptions.AlignMinXNearest, NSAlignmentOptions.AlignMaxXNearest, NSAlignmentOptions.AlignMinYNearest, NSAlignmentOptions.AlignMaxYNearest]
+ public static let alignAllEdgesInward: AlignmentOptions = [.alignMinXInward, .alignMaxXInward, .alignMinYInward, .alignMaxYInward]
+ public static let alignAllEdgesOutward: AlignmentOptions = [.alignMinXOutward, .alignMaxXOutward, .alignMinYOutward, .alignMaxYOutward]
+ public static let alignAllEdgesNearest: AlignmentOptions = [.alignMinXNearest, .alignMaxXNearest, .alignMinYNearest, .alignMaxYNearest]
}
public let NSZeroPoint: NSPoint = NSPoint()
@@ -429,12 +429,12 @@
return NSZeroRect
}
- return NSIntegralRectWithOptions(aRect, [.AlignMinXOutward, .AlignMaxXOutward, .AlignMinYOutward, .AlignMaxYOutward])
+ return NSIntegralRectWithOptions(aRect, [.alignMinXOutward, .alignMaxXOutward, .alignMinYOutward, .alignMaxYOutward])
}
-public func NSIntegralRectWithOptions(_ aRect: NSRect, _ opts: NSAlignmentOptions) -> NSRect {
+public func NSIntegralRectWithOptions(_ aRect: NSRect, _ opts: AlignmentOptions) -> NSRect {
let listOfOptionsIsInconsistentErrorMessage = "List of options is inconsistent"
- if opts.contains(.AlignRectFlipped) {
+ if opts.contains(.alignRectFlipped) {
NSUnimplemented()
}
@@ -453,81 +453,81 @@
}
- if opts.contains(.AlignWidthInward) && width != 0 {
+ if opts.contains(.alignWidthInward) && width != 0 {
guard width.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
width = floor(aRect.size.width.native)
}
- if opts.contains(.AlignHeightInward) && height != 0 {
+ if opts.contains(.alignHeightInward) && height != 0 {
guard height.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
height = floor(aRect.size.height.native)
}
- if opts.contains(.AlignWidthOutward) && width != 0 {
+ if opts.contains(.alignWidthOutward) && width != 0 {
guard width.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
width = ceil(aRect.size.width.native)
}
- if opts.contains(.AlignHeightOutward) && height != 0 {
+ if opts.contains(.alignHeightOutward) && height != 0 {
guard height.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
height = ceil(aRect.size.height.native)
}
- if opts.contains(.AlignWidthNearest) && width != 0 {
+ if opts.contains(.alignWidthNearest) && width != 0 {
guard width.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
width = round(aRect.size.width.native)
}
- if opts.contains(.AlignHeightNearest) && height != 0 {
+ if opts.contains(.alignHeightNearest) && height != 0 {
guard height.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
height = round(aRect.size.height.native)
}
- if opts.contains(.AlignMinXInward) {
+ if opts.contains(.alignMinXInward) {
guard minX.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
minX = ceil(aRect.origin.x.native)
}
- if opts.contains(.AlignMinYInward) {
+ if opts.contains(.alignMinYInward) {
guard minY.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
minY = ceil(aRect.origin.y.native)
}
- if opts.contains(.AlignMaxXInward) {
+ if opts.contains(.alignMaxXInward) {
guard maxX.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
maxX = floor(aRect.origin.x.native + aRect.size.width.native)
}
- if opts.contains(.AlignMaxYInward) {
+ if opts.contains(.alignMaxYInward) {
guard maxY.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
maxY = floor(aRect.origin.y.native + aRect.size.height.native)
}
- if opts.contains(.AlignMinXOutward) {
+ if opts.contains(.alignMinXOutward) {
guard minX.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
minX = floor(aRect.origin.x.native)
}
- if opts.contains(.AlignMinYOutward) {
+ if opts.contains(.alignMinYOutward) {
guard minY.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
minY = floor(aRect.origin.y.native)
}
- if opts.contains(.AlignMaxXOutward) {
+ if opts.contains(.alignMaxXOutward) {
guard maxX.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
maxX = ceil(aRect.origin.x.native + aRect.size.width.native)
}
- if opts.contains(.AlignMaxYOutward) {
+ if opts.contains(.alignMaxYOutward) {
guard maxY.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
maxY = ceil(aRect.origin.y.native + aRect.size.height.native)
}
- if opts.contains(.AlignMinXNearest) {
+ if opts.contains(.alignMinXNearest) {
guard minX.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
minX = round(aRect.origin.x.native)
}
- if opts.contains(.AlignMinYNearest) {
+ if opts.contains(.alignMinYNearest) {
guard minY.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
minY = round(aRect.origin.y.native)
}
- if opts.contains(.AlignMaxXNearest) {
+ if opts.contains(.alignMaxXNearest) {
guard maxX.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
maxX = round(aRect.origin.x.native + aRect.size.width.native)
}
- if opts.contains(.AlignMaxYNearest) {
+ if opts.contains(.alignMaxYNearest) {
guard maxY.isNaN else { fatalError(listOfOptionsIsInconsistentErrorMessage) }
maxY = round(aRect.origin.y.native + aRect.size.height.native)
}
diff --git a/Foundation/NSHTTPCookie.swift b/Foundation/NSHTTPCookie.swift
index f78dd5d..73563c7 100644
--- a/Foundation/NSHTTPCookie.swift
+++ b/Foundation/NSHTTPCookie.swift
@@ -255,7 +255,7 @@
_domain = canonicalDomain
if let
- secureString = properties[.secure] as? String, secureString.characters.count > 0
+ secureString = properties[.secure] as? String, !secureString.characters.isEmpty
{
_secure = true
} else {
diff --git a/Foundation/NSIndexSet.swift b/Foundation/NSIndexSet.swift
index 7b0cf52..6c5490d 100644
--- a/Foundation/NSIndexSet.swift
+++ b/Foundation/NSIndexSet.swift
@@ -133,7 +133,7 @@
return _ranges.first?.location ?? NSNotFound
}
open var lastIndex: Int {
- guard _ranges.count > 0 else {
+ guard !_ranges.isEmpty else {
return NSNotFound
}
return NSMaxRange(_ranges.last!) - 1
@@ -557,7 +557,7 @@
internal func _mergeOverlappingRangesStartingAtIndex(_ index: Int) {
var rangeIndex = index
- while _ranges.count > 0 && rangeIndex < _ranges.count - 1 {
+ while !_ranges.isEmpty && rangeIndex < _ranges.count - 1 {
let curRange = _ranges[rangeIndex]
let nextRange = _ranges[rangeIndex + 1]
let curEnd = NSMaxRange(curRange)
diff --git a/Foundation/NSKeyedArchiver.swift b/Foundation/NSKeyedArchiver.swift
index e4298b4..476ca03 100644
--- a/Foundation/NSKeyedArchiver.swift
+++ b/Foundation/NSKeyedArchiver.swift
@@ -126,8 +126,8 @@
return finishedEncoding
}
- public override init() {
- NSUnimplemented()
+ public override convenience init() {
+ self.init(forWritingWith: NSMutableData())
}
private init(output: AnyObject) {
@@ -165,7 +165,12 @@
/// If encoding has not yet finished, then invoking this property will call finishEncoding and return the data. If you initialized the keyed archiver with a specific mutable data instance, then it will be returned from this property after finishEncoding is called.
open var encodedData: Data {
- NSUnimplemented()
+
+ if !_flags.contains(.finishedEncoding) {
+ finishEncoding()
+ }
+
+ return (_stream as! NSData)._swiftObject
}
open func finishEncoding() {
@@ -428,7 +433,7 @@
if let ns = clsv as? NSObject.Type {
let classHints = ns.classFallbacksForKeyedArchiver()
- if classHints.count > 0 {
+ if !classHints.isEmpty {
classDict["$classhints"] = classHints
}
}
diff --git a/Foundation/NSObject.swift b/Foundation/NSObject.swift
index 9bb2e53..df463f3 100644
--- a/Foundation/NSObject.swift
+++ b/Foundation/NSObject.swift
@@ -7,30 +7,78 @@
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
-
import CoreFoundation
-public protocol NSObjectProtocol: class {
+/// The `NSObjectProtocol` groups methods that are fundamental to all Foundation objects.
+///
+/// If an object conforms to this protocol, it can be considered a first-class object.
+///
+/// The Cocoa root class, NSObject, adopts this protocol, so all objects inheriting
+/// from NSObject have the features described by this protocol.
+public protocol NSObjectProtocol : class {
+ /// Returns a Boolean value that indicates whether the instance
+ /// and a given `object` are equal.
+ ///
+ /// This method defines what it means for instances to be equal. For example, a container
+ /// object might define two containers as equal if their corresponding objects all respond
+ /// true to an `isEqual(_:)` request. See the `NSData`, `NSDictionary`, `NSArray`,
+ /// and `NSString` class specifications for examples of the use of this method.
+ ///
+ /// If two objects are equal, they must have the same hash value.
+ /// This last point is particularly important if you define `isEqual(_:)` in a subclass
+ /// and intend to put instances of that subclass into a collection.
+ /// Make sure you also define hash in your subclass.
+ ///
+ /// - Parameter object: The object to be compared to the instance.
+ /// May be `nil`, in which case this method returns `false`.
+ /// - Returns: `true` if the instance and `object` are equal, otherwise `false`.
func isEqual(_ object: Any?) -> Bool
+
+ /// Returns an integer that can be used as a table address in a hash table structure.
+ ///
+ /// If two objects are equal (as determined by the `isEqual(_:)` method),
+ /// they must have the same hash value. This last point is particularly important
+ /// if you define `hash` in a subclass and intend to put instances of that subclass
+ /// into a collection.
+ ///
+ /// If a mutable object is added to a collection that uses hash values to determine
+ /// the object’s position in the collection, the value returned by the `hash` property
+ /// of the object must not change while the object is in the collection. Therefore, either
+ /// the `hash` property must not rely on any of the object’s internal state information
+ /// or you must make sure the object’s internal state information does not change while
+ /// the object is in the collection. Thus, for example, a mutable dictionary can be put
+ /// in a hash table but you must not change it while it is in there.
+ /// (Note that it can be difficult to know whether or not a given object is in a collection.)
var hash: Int { get }
+ /// Returns the instance itself.
+ ///
+ /// - Returns: The instance itself.
func `self`() -> Self
+ /// Returns a Boolean value that indicates whether the instance does not descend from NSObject.
+ ///
+ /// - Returns: `false` if the instance really descends from `NSObject`, otherwise `true`.
func isProxy() -> Bool
+ /// Returns a string that describes the contents of the instance.
var description: String { get }
+ /// Returns a string that describes the contents of the instance for presentation
+ /// in the debugger.
var debugDescription: String { get }
}
extension NSObjectProtocol {
+
public var debugDescription: String {
return description
}
}
public struct NSZone : ExpressibleByNilLiteral {
+
public init() {
}
@@ -40,35 +88,76 @@
}
}
+/// The `NSCopying` protocol declares a method for providing functional copies of an object.
+/// The exact meaning of “copy” can vary from class to class, but a copy must be a functionally
+/// independent object with values identical to the original at the time the copy was made.
+///
+/// NSCopying declares one method, `copy(with:)`, but copying is commonly invoked with the
+/// convenience method `copy`. The copy method is defined for all objects inheriting from NSObject
+/// and simply invokes `copy(with:)` with the `nil` zone.
+///
+/// If a subclass inherits `NSCopying` from its superclass and declares additional instance variables,
+/// the subclass has to override `copy(with:)` to properly handle its own instance variables,
+/// invoking the superclass’s implementation first.
public protocol NSCopying {
+ /// Returns a new instance that’s a copy of the current one.
+ ///
+ /// - Parameter zone: This parameter is ignored. Memory zones are no longer used.
+ /// - Returns: A new instance that’s a copy of the current one.
func copy(with zone: NSZone?) -> Any
}
extension NSCopying {
+
+ /// Returns a new instance that’s a copy of the current one.
+ ///
+ /// - Returns: A new instance that’s a copy of the current one.
public func copy() -> Any {
return copy(with: nil)
}
}
+/// The `NSMutableCopying` protocol declares a method for providing mutable
+/// copies of an object. Only classes that define an “immutable vs. mutable” distinction
+/// should adopt this protocol. Classes that don’t define such a distinction should
+/// adopt `NSCopying` instead.
public protocol NSMutableCopying {
+ /// Returns a new instance that’s a mutable copy of the current one.
+ ///
+ /// - Parameter zone: This parameter is ignored. Memory zones are no longer used.
+ /// - Returns: A new instance that’s a mutable copy of the current one.
func mutableCopy(with zone: NSZone?) -> Any
}
extension NSMutableCopying {
+
+ /// Returns a new instance that’s a mutable copy of the current one.
+ ///
+ /// - Returns: A new instance that’s a mutable copy of the current one.
public func mutableCopy() -> Any {
return mutableCopy(with: nil)
}
}
+/// The root class of most Foundation class hierarchies.
open class NSObject : NSObjectProtocol, Equatable, Hashable {
// Important: add no ivars here. It will subvert the careful layout of subclasses that bridge into CF.
- public init() {
-
- }
+ /// Implemented by subclasses to initialize a new object immediately after memory
+ /// for it has been allocated.
+ public init() {}
+ /// Returns the object returned by `copy(with:)`.
+ ///
+ /// This is a convenience method for classes that adopt the `NSCopying` protocol.
+ /// `NSObject` does not itself support the `NSCopying` protocol.
+ /// Subclasses must support the protocol and implement the `copy(with:)` method.
+ /// A subclass version of the `copy(with:)` method should invoke `super`'s method first,
+ /// to incorporate its implementation, unless the subclass descends directly from `NSObject`.
+ ///
+ /// - Returns: The object returned by the `NSCopying` protocol method `copy(with:)`.
open func copy() -> Any {
if let copyable = self as? NSCopying {
return copyable.copy(with: nil)
@@ -76,6 +165,12 @@
return self
}
+ /// Returns the object returned by `mutableCopy(with:)` where the zone is `nil.`
+ ///
+ /// This is a convenience method for classes that adopt the `NSMutableCopying` protocol.
+ ///
+ /// - Returns: The object returned by the `NSMutableCopying` protocol method
+ /// `mutableCopy(with:)`, where the zone is `nil`.
open func mutableCopy() -> Any {
if let copyable = self as? NSMutableCopying {
return copyable.mutableCopy(with: nil)
@@ -83,6 +178,13 @@
return self
}
+ /// Returns a Boolean value that indicates whether the instance is equal to another given object.
+ ///
+ /// The default implementation for this method provided by `NSObject` returns `true` if
+ /// the objects being compared refer to the same instance.
+ ///
+ /// - Parameter object: The object with which to compare the instance.
+ /// - Returns: `true` if the instance is equal to `object`, otherwise `false`.
open func isEqual(_ object: Any?) -> Bool {
if let obj = object as? NSObject {
return obj === self
@@ -90,22 +192,46 @@
return false
}
+ /// Returns an integer that can be used as a table address in a hash table structure.
+ ///
+ /// If two objects are equal (as determined by the `isEqual(_:)` method),
+ /// they must have the same hash value. This last point is particularly important
+ /// if you define `hash` in a subclass and intend to put instances of that subclass
+ /// into a collection.
+ ///
+ /// If a mutable object is added to a collection that uses hash values to determine
+ /// the object’s position in the collection, the value returned by the `hash` property
+ /// of the object must not change while the object is in the collection. Therefore, either
+ /// the `hash` property must not rely on any of the object’s internal state information
+ /// or you must make sure the object’s internal state information does not change while
+ /// the object is in the collection. Thus, for example, a mutable dictionary can be put
+ /// in a hash table but you must not change it while it is in there.
+ /// (Note that it can be difficult to know whether or not a given object is in a collection.)
open var hash: Int {
return ObjectIdentifier(self).hashValue
}
+ /// Returns the instance itself.
+ ///
+ /// - Returns: The instance itself.
open func `self`() -> Self {
return self
}
+ /// Returns a Boolean value that indicates whether the instance does not descend from NSObject.
+ ///
+ /// - Returns: `false` if the instance really descends from `NSObject`, otherwise `true`.
open func isProxy() -> Bool {
return false
}
+ /// Returns a string that describes the contents of the instance.
open var description: String {
return "<\(type(of: self)): \(Unmanaged.passUnretained(self).toOpaque())>"
}
+ /// Returns a string that describes the contents of the instance for presentation
+ /// in the debugger.
open var debugDescription: String {
return description
}
@@ -114,46 +240,82 @@
return 0
}
- // TODO move these back into extensions once extension methods can be overriden
+ // TODO: move these back into extensions once extension methods can be overriden
+
+ /// Overridden by subclasses to substitute a class other than its own during coding.
+ ///
+ /// This property is needed for `NSCoder`.
+ /// `NSObject`’s implementation returns the instance's class.
+ /// The private subclasses of a class cluster substitute the name of their public
+ /// superclass when being archived.
open var classForCoder: AnyClass {
return type(of: self)
}
+ /// Overridden by subclasses to substitute another object for itself during encoding.
+ ///
+ /// An object might encode itself into an archive, but encode a proxy for itself if
+ /// it’s being encoded for distribution. This method is invoked by `NSCoder`.
+ /// `NSObject`’s implementation returns `self`.
+ ///
+ /// - Parameter aCoder: The coder encoding the instance.
+ /// - Returns: The object encode instead of the instance (if different).
open func replacementObjectForCoder(_ aCoder: NSCoder) -> AnyObject? {
return self
}
- // TODO: Could perhaps be an extension of NSCoding instead. The reason it is an extension of NSObject is the lack of default implementations on protocols in Objective-C.
+ // TODO: Could perhaps be an extension of NSCoding instead.
+ // The reason it is an extension of NSObject is the lack of default
+ // implementations on protocols in Objective-C.
+
+ /// Subclasses to substitute a new class for instances during keyed archiving.
+ ///
+ /// The object will be encoded as if it were a member of the class. This property is
+ /// overridden by the encoder class and instance name to class encoding tables.
+ /// If this property is `nil`, the result of this property is ignored.
open var classForKeyedArchiver: AnyClass? {
return self.classForCoder
}
- // Implemented by classes to substitute a new class for instances during
- // encoding. The object will be encoded as if it were a member of the
- // returned class. The results of this method are overridden by the archiver
- // class and instance name<->class encoding tables. If nil is returned,
- // then the null object is encoded. This method returns the result of
- // [self classForArchiver] by default, NOT -classForCoder as might be
- // expected. This is a concession to source compatibility.
-
+ /// Overridden by subclasses to substitute another object for itself during keyed archiving.
+ ///
+ /// This method is called only if no replacement mapping for the object has been set up
+ /// in the encoder (for example, due to a previous call of `replacementObject(for:)` to that object).
+ ///
+ /// - Parameter archiver: A keyed archiver creating an archive.
+ /// - Returns: The object encode instead of the instance (if different).
open func replacementObjectForKeyedArchiver(_ archiver: NSKeyedArchiver) -> AnyObject? {
return self.replacementObjectForCoder(archiver)
}
- // Implemented by classes to substitute new instances for the receiving
- // instance during encoding. The returned object will be encoded instead
- // of the receiver (if different). This method is called only if no
- // replacement mapping for the object has been set up in the archiver yet
- // (for example, due to a previous call of replacementObjectForKeyedArchiver:
- // to that object). This method returns the result of
- // [self replacementObjectForArchiver:nil] by default, NOT
- // -replacementObjectForCoder: as might be expected. This is a concession
- // to source compatibility.
-
+ /// Overridden to return the names of classes that can be used to decode
+ /// objects if their class is unavailable.
+ ///
+ /// `NSKeyedArchiver` calls this method and stores the result inside the archive.
+ /// If the actual class of an object doesn’t exist at the time of unarchiving,
+ /// `NSKeyedUnarchiver` goes through the stored list of classes and uses the first one
+ /// that does exists as a substitute class for decoding the object.
+ /// The default implementation of this method returns empty array.
+ ///
+ /// You can use this method if you introduce a new class into your application to provide
+ /// some backwards compatibility in case the archive will be read on a system that does not
+ /// have that class. Sometimes there may be another class which may work nearly as well as
+ /// a substitute for the new class, and the archive keys and archived state for the new class
+ /// can be carefully chosen (or compatibility written out) so that the object can be unarchived
+ /// as the substitute class if necessary.
+ ///
+ /// - Returns: An array of strings that specify the names of classes in preferred order for unarchiving.
open class func classFallbacksForKeyedArchiver() -> [String] {
return []
}
+ /// Overridden by subclasses to substitute a new class during keyed unarchiving.
+ ///
+ /// During keyed unarchiving, instances of the class will be decoded as members
+ /// of the returned class. This method overrides the results of the decoder’s class
+ /// and instance name to class encoding tables.
+ ///
+ /// - Returns: The class to substitute for the current class during keyed unarchiving.
open class func classForKeyedUnarchiver() -> AnyClass {
return self
}
@@ -163,6 +325,14 @@
}
}
+/// Returns a Boolean value indicating whether two values are equal.
+///
+/// Equality is the inverse of inequality. For any values `a` and `b`,
+/// `a == b` implies that `a != b` is `false`.
+///
+/// - Parameters:
+/// - lhs: A value to compare.
+/// - rhs: Another value to compare.
public func ==(lhs: NSObject, rhs: NSObject) -> Bool {
return lhs.isEqual(rhs)
}
diff --git a/Foundation/NSOperation.swift b/Foundation/NSOperation.swift
index a9e1058..fcc9b38 100644
--- a/Foundation/NSOperation.swift
+++ b/Foundation/NSOperation.swift
@@ -258,19 +258,19 @@
}
mutating func dequeue() -> Operation? {
- if veryHigh.count > 0 {
+ if !veryHigh.isEmpty {
return veryHigh.remove(at: 0)
}
- if high.count > 0 {
+ if !high.isEmpty {
return high.remove(at: 0)
}
- if normal.count > 0 {
+ if !normal.isEmpty {
return normal.remove(at: 0)
}
- if low.count > 0 {
+ if !low.isEmpty {
return low.remove(at: 0)
}
- if veryLow.count > 0 {
+ if !veryLow.isEmpty {
return veryLow.remove(at: 0)
}
return nil
diff --git a/Foundation/NSPathUtilities.swift b/Foundation/NSPathUtilities.swift
index 95d1f1c..4590787 100644
--- a/Foundation/NSPathUtilities.swift
+++ b/Foundation/NSPathUtilities.swift
@@ -470,7 +470,7 @@
}
internal func _longestCommonPrefix(_ strings: [String], caseSensitive: Bool) -> String? {
- guard strings.count > 0 else {
+ guard !strings.isEmpty else {
return nil
}
diff --git a/Foundation/NSString.swift b/Foundation/NSString.swift
index 34badff..158de3e 100644
--- a/Foundation/NSString.swift
+++ b/Foundation/NSString.swift
@@ -1183,7 +1183,7 @@
}
public convenience init?(data: Data, encoding: UInt) {
- if data.count == 0 {
+ if data.isEmpty {
self.init("")
} else {
guard let cf = data.withUnsafeBytes({ (bytes: UnsafePointer<UInt8>) -> CFString? in
diff --git a/Foundation/NSURLSession/HTTPBodySource.swift b/Foundation/NSURLSession/HTTPBodySource.swift
index 03ebd4c..f732638 100644
--- a/Foundation/NSURLSession/HTTPBodySource.swift
+++ b/Foundation/NSURLSession/HTTPBodySource.swift
@@ -167,7 +167,7 @@
switch (done, data, errno) {
case (true, _, errno) where errno != 0:
self.availableChunk = .errorDetected(Int(errno))
- case (true, .some(let d), 0) where d.count == 0:
+ case (true, .some(let d), 0) where d.isEmpty:
self.append(data: d, endOfFile: true)
case (true, .some(let d), 0):
self.append(data: d, endOfFile: false)
@@ -220,10 +220,10 @@
let l = min(length, data.count)
let (head, tail) = splitData(dispatchData: data, atPosition: l)
- availableChunk = (tail.count == 0) ? .empty : .data(tail)
+ availableChunk = tail.isEmpty ? .empty : .data(tail)
readNextChunk()
- if head.count == 0 {
+ if head.isEmpty {
return .retryLater
} else {
return .data(head)
@@ -231,8 +231,8 @@
case .done(.some(let data)):
let l = min(length, data.count)
let (head, tail) = splitData(dispatchData: data, atPosition: l)
- availableChunk = (tail.count == 0) ? .done(nil) : .done(tail)
- if (head.count == 0) {
+ availableChunk = tail.isEmpty ? .done(nil) : .done(tail)
+ if head.isEmpty {
return .done
} else {
return .data(head)
diff --git a/Foundation/NSXMLElement.swift b/Foundation/NSXMLElement.swift
index 3c3b853..aa12142 100644
--- a/Foundation/NSXMLElement.swift
+++ b/Foundation/NSXMLElement.swift
@@ -109,7 +109,7 @@
result.append(XMLNode._objectNodeForNode(attribute))
nextAttribute = _CFXMLNodeGetNextSibling(attribute)
}
- return result.count > 0 ? result : nil // This appears to be how Darwin does it
+ return !result.isEmpty ? result : nil // This appears to be how Darwin does it
}
set {
diff --git a/Foundation/URL.swift b/Foundation/URL.swift
index e9ace98..8e1dc04 100644
--- a/Foundation/URL.swift
+++ b/Foundation/URL.swift
@@ -489,7 +489,7 @@
///
/// If the data representation is not a legal URL string as ASCII bytes, the URL object may not behave as expected. If the URL cannot be formed then this will return nil.
public init?(dataRepresentation: Data, relativeTo url: URL?, isAbsolute: Bool = false) {
- guard dataRepresentation.count > 0 else { return nil }
+ guard !dataRepresentation.isEmpty else { return nil }
if isAbsolute {
_url = URL._converted(from: NSURL(absoluteURLWithDataRepresentation: dataRepresentation, relativeTo: url))
diff --git a/TestFoundation/TestNSCalendar.swift b/TestFoundation/TestNSCalendar.swift
index 191b212..dde03e6 100644
--- a/TestFoundation/TestNSCalendar.swift
+++ b/TestFoundation/TestNSCalendar.swift
@@ -63,11 +63,29 @@
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = TimeZone(identifier: "UTC")!
- let components = calendar.dateComponents([.year, .month, .day], from: date)
+ let components = calendar.dateComponents([.year, .month, .day], from: date)
XCTAssertEqual(components.year, 2015)
XCTAssertEqual(components.month, 12)
XCTAssertEqual(components.day, 5)
+
+ // Test for problem reported by Malcolm Barclay via swift-corelibs-dev
+ // https://lists.swift.org/pipermail/swift-corelibs-dev/Week-of-Mon-20161128/001031.html
+ let fromDate = Date()
+ let interval = 200
+ let toDate = Date(timeInterval: TimeInterval(interval), since: fromDate)
+ let fromToComponents = calendar.dateComponents([.second], from: fromDate, to: toDate)
+ XCTAssertEqual(fromToComponents.second, interval);
+
+ // Issue with 32-bit CF calendar vector on Linux
+ // Crashes on macOS 10.12.2/Foundation 1349.25
+ // (Possibly related) rdar://24384757
+ /*
+ let interval2 = Int(INT32_MAX) + 1
+ let toDate2 = Date(timeInterval: TimeInterval(interval2), since: fromDate)
+ let fromToComponents2 = calendar.dateComponents([.second], from: fromDate, to: toDate2)
+ XCTAssertEqual(fromToComponents2.second, interval2);
+ */
}
func test_gettingDatesOnISO8601Calendar() {
diff --git a/TestFoundation/TestNSGeometry.swift b/TestFoundation/TestNSGeometry.swift
index 53bcde3..edd9d37 100644
--- a/TestFoundation/TestNSGeometry.swift
+++ b/TestFoundation/TestNSGeometry.swift
@@ -29,9 +29,12 @@
("test_CGPoint_BasicConstruction", test_CGPoint_BasicConstruction),
("test_CGSize_BasicConstruction", test_CGSize_BasicConstruction),
("test_CGRect_BasicConstruction", test_CGRect_BasicConstruction),
+ ("test_NSEdgeInsets_BasicConstruction", test_NSEdgeInsets_BasicConstruction),
+ ("test_NSEdgeInsetsEqual", test_NSEdgeInsetsEqual),
("test_NSMakePoint", test_NSMakePoint),
("test_NSMakeSize", test_NSMakeSize),
("test_NSMakeRect", test_NSMakeRect),
+ ("test_NSEdgeInsetsMake", test_NSEdgeInsetsMake),
("test_NSUnionRect", test_NSUnionRect),
("test_NSIntersectionRect", test_NSIntersectionRect),
("test_NSOffsetRect", test_NSOffsetRect),
@@ -136,6 +139,28 @@
XCTAssertEqual(r2.size.height, s.height)
}
+ func test_NSEdgeInsets_BasicConstruction() {
+ let i1 = NSEdgeInsets()
+ XCTAssertEqual(i1.top, CGFloat(0.0))
+ XCTAssertEqual(i1.left, CGFloat(0.0))
+ XCTAssertEqual(i1.bottom, CGFloat(0.0))
+ XCTAssertEqual(i1.right, CGFloat(0.0))
+
+ let i2 = NSEdgeInsets(top: CGFloat(3.6), left: CGFloat(4.5), bottom: CGFloat(5.0), right: CGFloat(-1.0))
+ XCTAssertEqual(i2.top, CGFloat(3.6))
+ XCTAssertEqual(i2.left, CGFloat(4.5))
+ XCTAssertEqual(i2.bottom, CGFloat(5.0))
+ XCTAssertEqual(i2.right, CGFloat(-1.0))
+ }
+
+ func test_NSEdgeInsetsEqual() {
+ let variant1 = NSEdgeInsets(top: CGFloat(3.6), left: CGFloat(4.5), bottom: CGFloat(5.0), right: CGFloat(-1.0))
+ let variant1Copy = NSEdgeInsets(top: CGFloat(3.6), left: CGFloat(4.5), bottom: CGFloat(5.0), right: CGFloat(-1.0))
+ let variant2 = NSEdgeInsets(top: CGFloat(3.1), left: CGFloat(4.5), bottom: CGFloat(5.0), right: CGFloat(-1.0))
+ XCTAssertTrue(NSEdgeInsetsEqual(variant1, variant1Copy))
+ XCTAssertFalse(NSEdgeInsetsEqual(variant1, variant2))
+ }
+
func test_NSMakePoint() {
let p2 = NSMakePoint(CGFloat(3.6), CGFloat(4.5))
XCTAssertEqual(p2.x, CGFloat(3.6))
@@ -156,6 +181,14 @@
XCTAssertEqual(r2.size.height, CGFloat(5.0))
}
+ func test_NSEdgeInsetsMake() {
+ let i2 = NSEdgeInsetsMake(CGFloat(2.2), CGFloat(3.0), CGFloat(5.0), CGFloat(5.0))
+ XCTAssertEqual(i2.top, CGFloat(2.2))
+ XCTAssertEqual(i2.left, CGFloat(3.0))
+ XCTAssertEqual(i2.bottom, CGFloat(5.0))
+ XCTAssertEqual(i2.right, CGFloat(5.0))
+ }
+
func test_NSUnionRect() {
let r1 = NSMakeRect(CGFloat(1.2), CGFloat(3.1), CGFloat(10.0), CGFloat(10.0))
let r2 = NSMakeRect(CGFloat(10.2), CGFloat(2.5), CGFloat(5.0), CGFloat(5.0))
@@ -275,87 +308,87 @@
let referenceNegativeRect = NSMakeRect(CGFloat(-0.6), CGFloat(-5.4), CGFloat(-105.7), CGFloat(-24.3))
let referenceNegativeOriginRect = NSMakeRect(CGFloat(-0.6), CGFloat(-5.4), CGFloat(105.7), CGFloat(24.3))
- var options: NSAlignmentOptions = [.AlignMinXInward, .AlignMinYInward, .AlignHeightInward, .AlignWidthInward]
+ var options: AlignmentOptions = [.alignMinXInward, .alignMinYInward, .alignHeightInward, .alignWidthInward]
var expectedResult = NSMakeRect(CGFloat(1.0), CGFloat(6.0), CGFloat(105.0), CGFloat(24.0))
var result = NSIntegralRectWithOptions(referenceRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMinXOutward, .AlignMinYOutward, .AlignHeightOutward, .AlignWidthOutward]
+ options = [.alignMinXOutward, .alignMinYOutward, .alignHeightOutward, .alignWidthOutward]
expectedResult = NSMakeRect(CGFloat(0.0), CGFloat(5.0), CGFloat(106.0), CGFloat(25.0))
result = NSIntegralRectWithOptions(referenceRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMinXInward, .AlignMinYInward, .AlignHeightInward, .AlignWidthInward]
+ options = [.alignMinXInward, .alignMinYInward, .alignHeightInward, .alignWidthInward]
expectedResult = NSMakeRect(CGFloat(0.0), CGFloat(-5.0), CGFloat(0.0), CGFloat(0.0))
result = NSIntegralRectWithOptions(referenceNegativeRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMinXInward, .AlignMinYInward, .AlignHeightInward, .AlignWidthInward]
+ options = [.alignMinXInward, .alignMinYInward, .alignHeightInward, .alignWidthInward]
expectedResult = NSMakeRect(CGFloat(0.0), CGFloat(-5.0), CGFloat(105.0), CGFloat(24.0))
result = NSIntegralRectWithOptions(referenceNegativeOriginRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMinXOutward, .AlignMinYOutward, .AlignHeightOutward, .AlignWidthOutward]
+ options = [.alignMinXOutward, .alignMinYOutward, .alignHeightOutward, .alignWidthOutward]
expectedResult = NSMakeRect(CGFloat(-1.0), CGFloat(-6.0), CGFloat(106.0), CGFloat(25.0))
result = NSIntegralRectWithOptions(referenceNegativeOriginRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMaxXOutward, .AlignMaxYOutward, .AlignHeightOutward, .AlignWidthOutward]
+ options = [.alignMaxXOutward, .alignMaxYOutward, .alignHeightOutward, .alignWidthOutward]
expectedResult = NSMakeRect(CGFloat(0.0), CGFloat(-6.0), CGFloat(106.0), CGFloat(25.0))
result = NSIntegralRectWithOptions(referenceNegativeOriginRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMinXOutward, .AlignMaxXOutward, .AlignMinYOutward, .AlignMaxYOutward]
+ options = [.alignMinXOutward, .alignMaxXOutward, .alignMinYOutward, .alignMaxYOutward]
expectedResult = NSMakeRect(CGFloat(-1.0), CGFloat(-6.0), CGFloat(107.0), CGFloat(25.0))
result = NSIntegralRectWithOptions(referenceNegativeOriginRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMaxXOutward, .AlignMaxYOutward, .AlignHeightOutward, .AlignWidthOutward]
+ options = [.alignMaxXOutward, .alignMaxYOutward, .alignHeightOutward, .alignWidthOutward]
expectedResult = NSMakeRect(CGFloat(1.0), CGFloat(5.0), CGFloat(106.0), CGFloat(25.0))
result = NSIntegralRectWithOptions(referenceRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMaxXInward, .AlignMaxYInward, .AlignHeightOutward, .AlignWidthOutward]
+ options = [.alignMaxXInward, .alignMaxYInward, .alignHeightOutward, .alignWidthOutward]
expectedResult = NSMakeRect(CGFloat(-1.0), CGFloat(-7.0), CGFloat(106.0), CGFloat(25.0))
result = NSIntegralRectWithOptions(referenceNegativeOriginRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMaxXInward, .AlignMaxYInward, .AlignHeightOutward, .AlignWidthOutward]
+ options = [.alignMaxXInward, .alignMaxYInward, .alignHeightOutward, .alignWidthOutward]
expectedResult = NSMakeRect(CGFloat(0.0), CGFloat(4.0), CGFloat(106.0), CGFloat(25.0))
result = NSIntegralRectWithOptions(referenceRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMinXNearest, .AlignMinYNearest, .AlignHeightNearest, .AlignWidthNearest]
+ options = [.alignMinXNearest, .alignMinYNearest, .alignHeightNearest, .alignWidthNearest]
expectedResult = NSMakeRect(CGFloat(1.0), CGFloat(5.0), CGFloat(106.0), CGFloat(24.0))
result = NSIntegralRectWithOptions(referenceRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMinXNearest, .AlignMinYNearest, .AlignHeightNearest, .AlignWidthNearest]
+ options = [.alignMinXNearest, .alignMinYNearest, .alignHeightNearest, .alignWidthNearest]
expectedResult = NSMakeRect(CGFloat(-1.0), CGFloat(-5.0), CGFloat(106.0), CGFloat(24.0))
result = NSIntegralRectWithOptions(referenceNegativeOriginRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMaxXNearest, .AlignMaxYNearest, .AlignHeightNearest, .AlignWidthNearest]
+ options = [.alignMaxXNearest, .alignMaxYNearest, .alignHeightNearest, .alignWidthNearest]
expectedResult = NSMakeRect(CGFloat(0.0), CGFloat(6.0), CGFloat(106.0), CGFloat(24.0))
result = NSIntegralRectWithOptions(referenceRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMaxXNearest, .AlignMaxYNearest, .AlignHeightNearest, .AlignWidthNearest]
+ options = [.alignMaxXNearest, .alignMaxYNearest, .alignHeightNearest, .alignWidthNearest]
expectedResult = NSMakeRect(CGFloat(-1.0), CGFloat(-5.0), CGFloat(106.0), CGFloat(24.0))
result = NSIntegralRectWithOptions(referenceNegativeOriginRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMinXInward, .AlignMaxXInward, .AlignMinYInward, .AlignMaxYInward]
+ options = [.alignMinXInward, .alignMaxXInward, .alignMinYInward, .alignMaxYInward]
expectedResult = NSMakeRect(CGFloat(1.0), CGFloat(6.0), CGFloat(105.0), CGFloat(23.0))
result = NSIntegralRectWithOptions(referenceRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMinXInward, .AlignMaxXInward, .AlignMinYInward, .AlignMaxYInward]
+ options = [.alignMinXInward, .alignMaxXInward, .alignMinYInward, .alignMaxYInward]
expectedResult = NSMakeRect(CGFloat(0.0), CGFloat(-5.0), CGFloat(105.0), CGFloat(23.0))
result = NSIntegralRectWithOptions(referenceNegativeOriginRect, options)
XCTAssertEqual(result, expectedResult)
- options = [.AlignMinXNearest, .AlignMaxXInward, .AlignMinYInward, .AlignMaxYNearest]
+ options = [.alignMinXNearest, .alignMaxXInward, .alignMinYInward, .alignMaxYNearest]
expectedResult = NSMakeRect(CGFloat(-1.0), CGFloat(-5.0), CGFloat(106.0), CGFloat(24.0))
result = NSIntegralRectWithOptions(referenceNegativeOriginRect, options)
XCTAssertEqual(result, expectedResult)
diff --git a/TestFoundation/TestNSKeyedArchiver.swift b/TestFoundation/TestNSKeyedArchiver.swift
index 6e6b529..32fd2b6 100644
--- a/TestFoundation/TestNSKeyedArchiver.swift
+++ b/TestFoundation/TestNSKeyedArchiver.swift
@@ -111,6 +111,7 @@
private func test_archive(_ encode: (NSKeyedArchiver) -> Bool,
decode: (NSKeyedUnarchiver) -> Bool) {
+ // Archiving using custom NSMutableData instance
let data = NSMutableData()
let archiver = NSKeyedArchiver(forWritingWith: data)
@@ -119,6 +120,15 @@
let unarchiver = NSKeyedUnarchiver(forReadingWithData: Data._unconditionallyBridgeFromObjectiveC(data))
XCTAssertTrue(decode(unarchiver))
+
+ // Archiving using the default initializer
+ let archiver1 = NSKeyedArchiver()
+
+ XCTAssertTrue(encode(archiver1))
+ let archivedData = archiver1.encodedData
+
+ let unarchiver1 = NSKeyedUnarchiver(forReadingWithData: archivedData)
+ XCTAssertTrue(decode(unarchiver1))
}
private func test_archive(_ object: Any, classes: [AnyClass], allowsSecureCoding: Bool = true, outputFormat: PropertyListSerialization.PropertyListFormat) {