Skip to content

id as Any conversion of NSCopying and NSMutableCopying #515

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
Aug 10, 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
4 changes: 2 additions & 2 deletions Foundation/Boxing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal protocol _SwiftNativeFoundationType : class {
init(unmanagedImmutableObject: Unmanaged<ImmutableType>)
init(unmanagedMutableObject: Unmanaged<MutableType>)

func mutableCopy(with zone : NSZone) -> AnyObject
func mutableCopy(with zone : NSZone) -> Any

var hashValue: Int { get }
var description: String { get }
Expand Down Expand Up @@ -113,7 +113,7 @@ extension _SwiftNativeFoundationType {
}
}

func mutableCopy(with zone : NSZone) -> AnyObject {
func mutableCopy(with zone : NSZone) -> Any {
return _mapUnmanaged { ($0 as NSObject).mutableCopy() }
}

Expand Down
2 changes: 1 addition & 1 deletion Foundation/CharacterSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public struct CharacterSet : ReferenceConvertible, Equatable, Hashable, SetAlgeb

internal init(_bridged characterSet: NSCharacterSet) {
// We must copy the input because it might be mutable; just like storing a value type in ObjC
_wrapped = _SwiftNSCharacterSet(immutableObject: characterSet.copy())
_wrapped = _SwiftNSCharacterSet(immutableObject: characterSet.copy() as! NSObject)
}

/// Initialize an empty instance.
Expand Down
2 changes: 1 addition & 1 deletion Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H

internal init(_bridged data: NSData) {
// We must copy the input because it might be mutable; just like storing a value type in ObjC
_wrapped = _SwiftNSData(immutableObject: data.copy())
_wrapped = _SwiftNSData(immutableObject: data.copy() as! NSObject)
}

// -----------------------------------
Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSAffineTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ open class NSAffineTransform : NSObject, NSCopying, NSSecureCoding {
open func encode(with aCoder: NSCoder) {
NSUnimplemented()
}
open func copy(with zone: NSZone? = nil) -> AnyObject {
open func copy(with zone: NSZone? = nil) -> Any {
return NSAffineTransform(transform: self)
}
// Necessary because `NSObject.copy()` returns `self`.
open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}
public required init?(coder aDecoder: NSCoder) {
Expand Down
10 changes: 5 additions & 5 deletions Foundation/NSArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
return true
}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

open func copy(with zone: NSZone? = nil) -> AnyObject {
open func copy(with zone: NSZone? = nil) -> Any {
if type(of: self) === NSArray.self {
// return self for immutable type
return self
Expand All @@ -125,11 +125,11 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
return NSArray(array: self.allObjects)
}

open override func mutableCopy() -> AnyObject {
open override func mutableCopy() -> Any {
return mutableCopy(with: nil)
}

open func mutableCopy(with zone: NSZone? = nil) -> AnyObject {
open func mutableCopy(with zone: NSZone? = nil) -> Any {
if type(of: self) === NSArray.self || type(of: self) === NSMutableArray.self {
// always create and return an NSMutableArray
let mutableArray = NSMutableArray()
Expand All @@ -150,7 +150,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
public convenience init(array: [AnyObject], copyItems: Bool) {
let optionalArray : [AnyObject?] =
copyItems ?
array.map { return Optional<AnyObject>(($0 as! NSObject).copy()) } :
array.map { return Optional<AnyObject>(($0 as! NSObject).copy() as! NSObject) } :
array.map { return Optional<AnyObject>($0) }

// This would have been nice, but "initializer delegation cannot be nested in another expression"
Expand Down
8 changes: 4 additions & 4 deletions Foundation/NSAttributedString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ open class AttributedString: NSObject, NSCopying, NSMutableCopying, NSSecureCodi
return true
}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

open func copy(with zone: NSZone? = nil) -> AnyObject {
open func copy(with zone: NSZone? = nil) -> Any {
NSUnimplemented()
}

open override func mutableCopy() -> AnyObject {
open override func mutableCopy() -> Any {
return mutableCopy(with: nil)
}

open func mutableCopy(with zone: NSZone? = nil) -> AnyObject {
open func mutableCopy(with zone: NSZone? = nil) -> Any {
NSUnimplemented()
}

Expand Down
6 changes: 3 additions & 3 deletions Foundation/NSCFCharacterSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ internal class _NSCFCharacterSet : NSMutableCharacterSet {
return CFCharacterSetHasMemberInPlane(_cfObject, CFIndex(plane))
}

override func copy() -> AnyObject {
override func copy() -> Any {
return copy(with: nil)
}

override func copy(with zone: NSZone? = nil) -> AnyObject {
override func copy(with zone: NSZone? = nil) -> Any {
return CFCharacterSetCreateCopy(kCFAllocatorSystemDefault, self._cfObject)
}

override func mutableCopy(with zone: NSZone? = nil) -> AnyObject {
override func mutableCopy(with zone: NSZone? = nil) -> Any {
return CFCharacterSetCreateMutableCopy(kCFAllocatorSystemDefault, _cfObject)._nsObject
}

Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSCFString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ internal func _CFSwiftStringCreateWithSubstring(_ str: AnyObject, range: CFRange


internal func _CFSwiftStringCreateCopy(_ str: AnyObject) -> Unmanaged<AnyObject> {
return Unmanaged<AnyObject>.passRetained((str as! NSString).copy(with: nil))
return Unmanaged<AnyObject>.passRetained((str as! NSString).copy() as! NSObject)
}

internal func _CFSwiftStringCreateMutableCopy(_ str: AnyObject) -> Unmanaged<AnyObject> {
return Unmanaged<AnyObject>.passRetained((str as! NSString).mutableCopy(with: nil))
return Unmanaged<AnyObject>.passRetained((str as! NSString).mutableCopy() as! NSObject)
}

internal func _CFSwiftStringFastCStringContents(_ str: AnyObject) -> UnsafePointer<Int8>? {
Expand Down
8 changes: 4 additions & 4 deletions Foundation/NSCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ open class NSCalendar: NSObject, NSCopying, NSSecureCoding {
return true
}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

open func copy(with zone: NSZone? = nil) -> AnyObject {
open func copy(with zone: NSZone? = nil) -> Any {
let copy = NSCalendar(identifier: calendarIdentifier)!
copy.locale = locale
copy.timeZone = timeZone
Expand Down Expand Up @@ -1418,11 +1418,11 @@ open class NSDateComponents : NSObject, NSCopying, NSSecureCoding {
return true
}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

open func copy(with zone: NSZone? = nil) -> AnyObject {
open func copy(with zone: NSZone? = nil) -> Any {
NSUnimplemented()
}

Expand Down
8 changes: 4 additions & 4 deletions Foundation/NSCharacterSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ open class NSCharacterSet : NSObject, NSCopying, NSMutableCopying, NSCoding {
return CFCharacterSetHasMemberInPlane(_cfObject, CFIndex(plane))
}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

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

open override func mutableCopy() -> AnyObject {
open override func mutableCopy() -> Any {
return mutableCopy(with: nil)
}

open func mutableCopy(with zone: NSZone? = nil) -> AnyObject {
open func mutableCopy(with zone: NSZone? = nil) -> Any {
if type(of: self) == NSCharacterSet.self || type(of: self) == NSMutableCharacterSet.self {
return _CFCharacterSetCreateMutableCopy(kCFAllocatorSystemDefault, _cfObject)._nsObject
} else if type(of: self) == _NSCFCharacterSet.self {
Expand Down
10 changes: 5 additions & 5 deletions Foundation/NSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,19 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
return UnsafeRawPointer(CFDataGetBytePtr(_cfObject))
}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

open func copy(with zone: NSZone? = nil) -> AnyObject {
open func copy(with zone: NSZone? = nil) -> Any {
return self
}

open override func mutableCopy() -> AnyObject {
open override func mutableCopy() -> Any {
return mutableCopy(with: nil)
}

open func mutableCopy(with zone: NSZone? = nil) -> AnyObject {
open func mutableCopy(with zone: NSZone? = nil) -> Any {
return NSMutableData(bytes: UnsafeMutableRawPointer(mutating: bytes), length: length, copy: true, deallocator: nil)
}

Expand Down Expand Up @@ -634,7 +634,7 @@ open class NSMutableData : NSData {
}
}

open override func copy(with zone: NSZone? = nil) -> AnyObject {
open override func copy(with zone: NSZone? = nil) -> Any {
return NSData(bytes: bytes, length: length)
}
}
Expand Down
6 changes: 3 additions & 3 deletions Foundation/NSDate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ open class NSDate : NSObject, NSCopying, NSSecureCoding, NSCoding {
}
}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

open func copy(with zone: NSZone? = nil) -> AnyObject {
open func copy(with zone: NSZone? = nil) -> Any {
return self
}

Expand Down Expand Up @@ -300,7 +300,7 @@ open class NSDateInterval : NSObject, NSCopying, NSSecureCoding {
self.init(start: startDate, duration: endDate.timeIntervalSince(startDate))
}

open func copy(with zone: NSZone?) -> AnyObject {
open func copy(with zone: NSZone?) -> Any {
return NSDateInterval(start: startDate, duration: duration)
}

Expand Down
8 changes: 4 additions & 4 deletions Foundation/NSDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
return true
}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

open func copy(with zone: NSZone? = nil) -> AnyObject {
open func copy(with zone: NSZone? = nil) -> Any {
if type(of: self) === NSDictionary.self {
// return self for immutable type
return self
Expand All @@ -187,11 +187,11 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
return NSDictionary(objects: self.allValues, forKeys: self.allKeys.map({ $0 as! NSObject}))
}

open override func mutableCopy() -> AnyObject {
open override func mutableCopy() -> Any {
return mutableCopy(with: nil)
}

open func mutableCopy(with zone: NSZone? = nil) -> AnyObject {
open func mutableCopy(with zone: NSZone? = nil) -> Any {
if type(of: self) === NSDictionary.self || type(of: self) === NSMutableDictionary.self {
// always create and return an NSMutableDictionary
let mutableDictionary = NSMutableDictionary()
Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
}
}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

open func copy(with zone: NSZone? = nil) -> AnyObject {
open func copy(with zone: NSZone? = nil) -> Any {
return self
}

Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSExpression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ open class NSExpression : NSObject, NSSecureCoding, NSCopying {
NSUnimplemented()
}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

open func copy(with zone: NSZone? = nil) -> AnyObject {
open func copy(with zone: NSZone? = nil) -> Any {
NSUnimplemented()
}

Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ open class Formatter : NSObject, NSCopying, NSCoding {

}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

open func copy(with zone: NSZone? = nil) -> AnyObject {
open func copy(with zone: NSZone? = nil) -> Any {
return self
}

Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSIndexPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ open class NSIndexPath: NSObject, NSCopying, NSSecureCoding {
_indexes = indexes
}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

open func copy(with zone: NSZone? = nil) -> AnyObject { NSUnimplemented() }
open func copy(with zone: NSZone? = nil) -> Any { NSUnimplemented() }
public convenience init(index: Int) {
self.init(indexes: [index])
}
Expand Down
8 changes: 4 additions & 4 deletions Foundation/NSIndexSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ open class NSIndexSet: NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
_count = indexSet.count
}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

open func copy(with zone: NSZone? = nil) -> AnyObject { NSUnimplemented() }
open func copy(with zone: NSZone? = nil) -> Any { NSUnimplemented() }

open override func mutableCopy() -> AnyObject {
open override func mutableCopy() -> Any {
return mutableCopy(with: nil)
}

open func mutableCopy(with zone: NSZone? = nil) -> AnyObject {
open func mutableCopy(with zone: NSZone? = nil) -> Any {
let set = NSMutableIndexSet()
enumerateRanges([]) {
set.add(in: $0.0)
Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSKeyedCoderOldStyleArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ internal final class _NSKeyedCoderOldStyleArray : NSObject, NSCopying, NSSecureC
}
}

override func copy() -> AnyObject {
override func copy() -> Any {
return copy(with: nil)
}

func copy(with zone: NSZone? = nil) -> AnyObject {
func copy(with zone: NSZone? = nil) -> Any {
return self
}
}
4 changes: 2 additions & 2 deletions Foundation/NSLocale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ open class NSLocale: NSObject, NSCopying, NSSecureCoding {
}
}

open override func copy() -> AnyObject {
open override func copy() -> Any {
return copy(with: nil)
}

open func copy(with zone: NSZone? = nil) -> AnyObject {
open func copy(with zone: NSZone? = nil) -> Any {
return self
}

Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSMeasurement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open class NSMeasurement : NSObject, NSCopying, NSSecureCoding {

open func subtracting(_ measurement: Measurement<Unit>) -> Measurement<Unit> { NSUnimplemented() }

open func copy(with zone: NSZone? = nil) -> AnyObject { NSUnimplemented() }
open func copy(with zone: NSZone? = nil) -> Any { NSUnimplemented() }

open class func supportsSecureCoding() -> Bool { return true }

Expand Down
Loading