Skip to content

Code improvements in NSDictionary #260

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 3 commits into from
Apr 28, 2016
Merged
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
23 changes: 5 additions & 18 deletions Foundation/NSDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,11 @@ extension Dictionary : _ObjectTypeBridgeable {

if x.dynamicType == NSDictionary.self || x.dynamicType == NSMutableDictionary.self {
x.enumerateKeysAndObjectsUsingBlock { key, value, stop in
if let k = key as? Key {
if let v = value as? Value {
dict[k] = v
} else {
failedConversion = true
stop.memory = true
}
} else {
guard let key = key as? Key, let value = value as? Value else{
failedConversion = true
stop.memory = true
}
dict[key] = value
}
} else if x.dynamicType == _NSCFDictionary.self {
let cf = x._cfObject
Expand All @@ -65,17 +59,11 @@ extension Dictionary : _ObjectTypeBridgeable {
for idx in 0..<cnt {
let key = unsafeBitCast(keys.advancedBy(idx).memory, AnyObject.self)
let value = unsafeBitCast(values.advancedBy(idx).memory, AnyObject.self)
if let k = key as? Key {
if let v = value as? Value {
dict[k] = v
} else {
failedConversion = true
break
}
} else {
guard let k = key as? Key, let v = value as? Value else {
failedConversion = true
break
}
dict[k] = v
}
keys.destroy(cnt)
values.destroy(cnt)
Expand Down Expand Up @@ -255,10 +243,9 @@ public class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCodin
}

public override func isEqual(object: AnyObject?) -> Bool {
guard let otherObject = object where otherObject is NSDictionary else {
guard let otherDictionary = object as? NSDictionary else {
return false
}
let otherDictionary = otherObject as! NSDictionary
return self.isEqualToDictionary(otherDictionary.bridge())
}

Expand Down