Skip to content

Replace precondition if with guard in NSNumber.encode. #1143

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 31, 2017
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
51 changes: 25 additions & 26 deletions Foundation/NSNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -609,35 +609,34 @@ open class NSNumber : NSValue {
}

open override func encode(with aCoder: NSCoder) {
if !aCoder.allowsKeyedCoding {
NSUnimplemented()
guard aCoder.allowsKeyedCoding else {
preconditionFailure("Unkeyed coding is unsupported.")
}
if let keyedCoder = aCoder as? NSKeyedArchiver {
keyedCoder._encodePropertyList(self)
} else {
if let keyedCoder = aCoder as? NSKeyedArchiver {
keyedCoder._encodePropertyList(self)
if CFGetTypeID(self) == CFBooleanGetTypeID() {
aCoder.encode(boolValue, forKey: "NS.boolval")
} else {
if CFGetTypeID(self) == CFBooleanGetTypeID() {
switch objCType.pointee {
case 0x42:
aCoder.encode(boolValue, forKey: "NS.boolval")
} else {
switch objCType.pointee {
case 0x42:
aCoder.encode(boolValue, forKey: "NS.boolval")
break
case 0x63: fallthrough
case 0x43: fallthrough
case 0x73: fallthrough
case 0x53: fallthrough
case 0x69: fallthrough
case 0x49: fallthrough
case 0x6C: fallthrough
case 0x4C: fallthrough
case 0x71: fallthrough
case 0x51:
aCoder.encode(int64Value, forKey: "NS.intval")
case 0x66: fallthrough
case 0x64:
aCoder.encode(doubleValue, forKey: "NS.dblval")
default: break
}
break
case 0x63: fallthrough
case 0x43: fallthrough
case 0x73: fallthrough
case 0x53: fallthrough
case 0x69: fallthrough
case 0x49: fallthrough
case 0x6C: fallthrough
case 0x4C: fallthrough
case 0x71: fallthrough
case 0x51:
aCoder.encode(int64Value, forKey: "NS.intval")
case 0x66: fallthrough
case 0x64:
aCoder.encode(doubleValue, forKey: "NS.dblval")
default: break
}
}
}
Expand Down