Skip to content

Update for SE-0096 #494

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
Jul 30, 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/Measurement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extension Measurement where UnitType : Dimension {
return Measurement(value: value, unit: otherUnit)
} else {
let valueInTermsOfBase = unit.converter.baseUnitValue(fromValue: value)
if otherUnit.isEqual(unit.dynamicType.baseUnit()) {
if otherUnit.isEqual(type(of: unit).baseUnit()) {
return Measurement(value: valueInTermsOfBase, unit: otherUnit)
} else {
let otherValueFromTermsOfBase = otherUnit.converter.value(fromBaseUnitValue: valueInTermsOfBase)
Expand Down Expand Up @@ -93,7 +93,7 @@ public func +<UnitType : Dimension>(lhs: Measurement<UnitType>, rhs: Measurement
} else {
let lhsValueInTermsOfBase = lhs.unit.converter.baseUnitValue(fromValue: lhs.value)
let rhsValueInTermsOfBase = rhs.unit.converter.baseUnitValue(fromValue: rhs.value)
return Measurement(value: lhsValueInTermsOfBase + rhsValueInTermsOfBase, unit: lhs.unit.dynamicType.baseUnit())
return Measurement(value: lhsValueInTermsOfBase + rhsValueInTermsOfBase, unit: type(of: lhs.unit).baseUnit())
}
}

Expand All @@ -118,7 +118,7 @@ public func -<UnitType : Dimension>(lhs: Measurement<UnitType>, rhs: Measurement
} else {
let lhsValueInTermsOfBase = lhs.unit.converter.baseUnitValue(fromValue: lhs.value)
let rhsValueInTermsOfBase = rhs.unit.converter.baseUnitValue(fromValue: rhs.value)
return Measurement(value: lhsValueInTermsOfBase - rhsValueInTermsOfBase, unit: lhs.unit.dynamicType.baseUnit())
return Measurement(value: lhsValueInTermsOfBase - rhsValueInTermsOfBase, unit: type(of: lhs.unit).baseUnit())
}
}

Expand Down
38 changes: 19 additions & 19 deletions Foundation/NSArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
internal var _storage = [AnyObject]()

public var count: Int {
guard self.dynamicType === NSArray.self || self.dynamicType === NSMutableArray.self else {
guard type(of: self) === NSArray.self || type(of: self) === NSMutableArray.self else {
NSRequiresConcreteImplementation()
}
return _storage.count
}

public func object(at index: Int) -> AnyObject {
guard self.dynamicType === NSArray.self || self.dynamicType === NSMutableArray.self else {
guard type(of: self) === NSArray.self || type(of: self) === NSMutableArray.self else {
NSRequiresConcreteImplementation()
}
return _storage[index]
Expand Down Expand Up @@ -79,7 +79,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
self.init(objects: UnsafePointer<AnyObject?>(objects), count: Int(cnt))
objects.deinitialize(count: Int(cnt))
objects.deallocate(capacity: Int(cnt))
} else if aDecoder.dynamicType == NSKeyedUnarchiver.self || aDecoder.containsValue(forKey: "NS.objects") {
} else if type(of: aDecoder) == NSKeyedUnarchiver.self || aDecoder.containsValue(forKey: "NS.objects") {
let objects = aDecoder._decodeArrayOfObjectsForKey("NS.objects")
self.init(array: objects)
} else {
Expand Down Expand Up @@ -114,10 +114,10 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
}

public func copy(with zone: NSZone? = nil) -> AnyObject {
if self.dynamicType === NSArray.self {
if type(of: self) === NSArray.self {
// return self for immutable type
return self
} else if self.dynamicType === NSMutableArray.self {
} else if type(of: self) === NSMutableArray.self {
let array = NSArray()
array._storage = self._storage
return array
Expand All @@ -130,7 +130,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
}

public func mutableCopy(with zone: NSZone? = nil) -> AnyObject {
if self.dynamicType === NSArray.self || self.dynamicType === NSMutableArray.self {
if type(of: self) === NSArray.self || type(of: self) === NSMutableArray.self {
// always create and return an NSMutableArray
let mutableArray = NSMutableArray()
mutableArray._storage = self._storage
Expand Down Expand Up @@ -178,7 +178,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
}

internal var allObjects: [AnyObject] {
if self.dynamicType === NSArray.self || self.dynamicType === NSMutableArray.self {
if type(of: self) === NSArray.self || type(of: self) === NSMutableArray.self {
return _storage
} else {
return (0..<count).map { idx in
Expand Down Expand Up @@ -261,7 +261,7 @@ public class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NS
internal func getObjects(_ objects: inout [AnyObject], range: NSRange) {
objects.reserveCapacity(objects.count + range.length)

if self.dynamicType === NSArray.self || self.dynamicType === NSMutableArray.self {
if type(of: self) === NSArray.self || type(of: self) === NSMutableArray.self {
objects += _storage[range.toRange()!]
return
}
Expand Down Expand Up @@ -646,7 +646,7 @@ public class NSMutableArray : NSArray {
}

public func insert(_ anObject: AnyObject, at index: Int) {
guard self.dynamicType === NSMutableArray.self else {
guard type(of: self) === NSMutableArray.self else {
NSRequiresConcreteImplementation()
}
_storage.insert(anObject, at: index)
Expand All @@ -659,14 +659,14 @@ public class NSMutableArray : NSArray {
}

public func removeObject(at index: Int) {
guard self.dynamicType === NSMutableArray.self else {
guard type(of: self) === NSMutableArray.self else {
NSRequiresConcreteImplementation()
}
_storage.remove(at: index)
}

public func replaceObject(at index: Int, with anObject: AnyObject) {
guard self.dynamicType === NSMutableArray.self else {
guard type(of: self) === NSMutableArray.self else {
NSRequiresConcreteImplementation()
}
let min = index
Expand All @@ -681,7 +681,7 @@ public class NSMutableArray : NSArray {
public init(capacity numItems: Int) {
super.init(objects: [], count: 0)

if self.dynamicType === NSMutableArray.self {
if type(of: self) === NSMutableArray.self {
_storage.reserveCapacity(numItems)
}
}
Expand All @@ -703,7 +703,7 @@ public class NSMutableArray : NSArray {
}

public func addObjectsFromArray(_ otherArray: [AnyObject]) {
if self.dynamicType === NSMutableArray.self {
if type(of: self) === NSMutableArray.self {
_storage += otherArray
} else {
for obj in otherArray {
Expand All @@ -713,15 +713,15 @@ public class NSMutableArray : NSArray {
}

public func exchangeObject(at idx1: Int, withObjectAt idx2: Int) {
if self.dynamicType === NSMutableArray.self {
if type(of: self) === NSMutableArray.self {
swap(&_storage[idx1], &_storage[idx2])
} else {
NSUnimplemented()
}
}

public func removeAllObjects() {
if self.dynamicType === NSMutableArray.self {
if type(of: self) === NSMutableArray.self {
_storage.removeAll()
} else {
while count > 0 {
Expand Down Expand Up @@ -768,7 +768,7 @@ public class NSMutableArray : NSArray {
}

public func removeObjects(in range: NSRange) {
if self.dynamicType === NSMutableArray.self {
if type(of: self) === NSMutableArray.self {
_storage.removeSubrange(range.toRange()!)
} else {
for idx in range.toRange()!.reversed() {
Expand All @@ -783,7 +783,7 @@ public class NSMutableArray : NSArray {
}

public func replaceObjectsInRange(_ range: NSRange, withObjectsFromArray otherArray: [AnyObject]) {
if self.dynamicType === NSMutableArray.self {
if type(of: self) === NSMutableArray.self {
_storage.reserveCapacity(count - range.length + otherArray.count)
for idx in 0..<range.length {
_storage[idx + range.location] = otherArray[idx]
Expand All @@ -797,7 +797,7 @@ public class NSMutableArray : NSArray {
}

public func setArray(_ otherArray: [AnyObject]) {
if self.dynamicType === NSMutableArray.self {
if type(of: self) === NSMutableArray.self {
_storage = otherArray
} else {
replaceObjectsInRange(NSMakeRange(0, count), withObjectsFromArray: otherArray)
Expand All @@ -807,7 +807,7 @@ public class NSMutableArray : NSArray {
public func insertObjects(_ objects: [AnyObject], atIndexes indexes: IndexSet) {
precondition(objects.count == indexes.count)

if self.dynamicType === NSMutableArray.self {
if type(of: self) === NSMutableArray.self {
_storage.reserveCapacity(count + indexes.count)
}

Expand Down
12 changes: 6 additions & 6 deletions Foundation/NSCharacterSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ public class NSCharacterSet : NSObject, NSCopying, NSMutableCopying, NSCoding {
}

public func longCharacterIsMember(_ theLongChar: UInt32) -> Bool {
if self.dynamicType == NSCharacterSet.self || self.dynamicType == NSMutableCharacterSet.self {
if type(of: self) == NSCharacterSet.self || type(of: self) == NSMutableCharacterSet.self {
return _CFCharacterSetIsLongCharacterMember(unsafeBitCast(self, to: CFType.self), theLongChar)
} else if self.dynamicType == _NSCFCharacterSet.self {
} else if type(of: self) == _NSCFCharacterSet.self {
return CFCharacterSetIsLongCharacterMember(_cfObject, theLongChar)
} else {
NSRequiresConcreteImplementation()
Expand All @@ -195,9 +195,9 @@ public class NSCharacterSet : NSObject, NSCopying, NSMutableCopying, NSCoding {
}

public func copy(with zone: NSZone? = nil) -> AnyObject {
if self.dynamicType == NSCharacterSet.self || self.dynamicType == NSMutableCharacterSet.self {
if type(of: self) == NSCharacterSet.self || type(of: self) == NSMutableCharacterSet.self {
return _CFCharacterSetCreateCopy(kCFAllocatorSystemDefault, self._cfObject)
} else if self.dynamicType == _NSCFCharacterSet.self {
} else if type(of: self) == _NSCFCharacterSet.self {
return CFCharacterSetCreateCopy(kCFAllocatorSystemDefault, self._cfObject)
} else {
NSRequiresConcreteImplementation()
Expand All @@ -209,9 +209,9 @@ public class NSCharacterSet : NSObject, NSCopying, NSMutableCopying, NSCoding {
}

public func mutableCopy(with zone: NSZone? = nil) -> AnyObject {
if self.dynamicType == NSCharacterSet.self || self.dynamicType == NSMutableCharacterSet.self {
if type(of: self) == NSCharacterSet.self || type(of: self) == NSMutableCharacterSet.self {
return _CFCharacterSetCreateMutableCopy(kCFAllocatorSystemDefault, _cfObject)._nsObject
} else if self.dynamicType == _NSCFCharacterSet.self {
} else if type(of: self) == _NSCFCharacterSet.self {
return CFCharacterSetCreateMutableCopy(kCFAllocatorSystemDefault, _cfObject)._nsObject
} else {
NSRequiresConcreteImplementation()
Expand Down
8 changes: 4 additions & 4 deletions Foundation/NSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
private var _bytes: UnsafeMutablePointer<UInt8>? = nil

internal var _cfObject: CFType {
if self.dynamicType === NSData.self || self.dynamicType === NSMutableData.self {
if type(of: self) === NSData.self || type(of: self) === NSMutableData.self {
return unsafeBitCast(self, to: CFType.self)
} else {
let bytePtr = self.bytes.bindMemory(to: UInt8.self, capacity: self.length)
Expand Down Expand Up @@ -111,14 +111,14 @@ public class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
if let allocatedBytes = _bytes {
_deallocHandler?.handler(allocatedBytes, _length)
}
if self.dynamicType === NSData.self || self.dynamicType === NSMutableData.self {
if type(of: self) === NSData.self || type(of: self) === NSMutableData.self {
_CFDeinit(self._cfObject)
}
}

internal init(bytes: UnsafeMutableRawPointer?, length: Int, copy: Bool, deallocator: ((UnsafeMutableRawPointer, Int) -> Void)?) {
super.init()
let options : CFOptionFlags = (self.dynamicType == NSMutableData.self) ? __kCFMutable | __kCFGrowable : 0x0
let options : CFOptionFlags = (type(of: self) == NSMutableData.self) ? __kCFMutable | __kCFGrowable : 0x0
let bytePtr = bytes?.bindMemory(to: UInt8.self, capacity: length)
if copy {
_CFDataInit(unsafeBitCast(self, to: CFMutableData.self), options, length, bytePtr, length, false)
Expand Down Expand Up @@ -174,7 +174,7 @@ public class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
} else {
return nil
}
} else if aDecoder.dynamicType == NSKeyedUnarchiver.self || aDecoder.containsValue(forKey: "NS.data") {
} else if type(of: aDecoder) == NSKeyedUnarchiver.self || aDecoder.containsValue(forKey: "NS.data") {
guard let data = aDecoder._decodePropertyListForKey("NS.data") as? NSData else {
return nil
}
Expand Down
Loading