Skip to content

Commit 8bb98e5

Browse files
authored
Merge pull request #1143 from oc243/if-to-guard
2 parents 11ecbaf + 87466c4 commit 8bb98e5

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

Foundation/NSNumber.swift

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -609,35 +609,34 @@ open class NSNumber : NSValue {
609609
}
610610

611611
open override func encode(with aCoder: NSCoder) {
612-
if !aCoder.allowsKeyedCoding {
613-
NSUnimplemented()
612+
guard aCoder.allowsKeyedCoding else {
613+
preconditionFailure("Unkeyed coding is unsupported.")
614+
}
615+
if let keyedCoder = aCoder as? NSKeyedArchiver {
616+
keyedCoder._encodePropertyList(self)
614617
} else {
615-
if let keyedCoder = aCoder as? NSKeyedArchiver {
616-
keyedCoder._encodePropertyList(self)
618+
if CFGetTypeID(self) == CFBooleanGetTypeID() {
619+
aCoder.encode(boolValue, forKey: "NS.boolval")
617620
} else {
618-
if CFGetTypeID(self) == CFBooleanGetTypeID() {
621+
switch objCType.pointee {
622+
case 0x42:
619623
aCoder.encode(boolValue, forKey: "NS.boolval")
620-
} else {
621-
switch objCType.pointee {
622-
case 0x42:
623-
aCoder.encode(boolValue, forKey: "NS.boolval")
624-
break
625-
case 0x63: fallthrough
626-
case 0x43: fallthrough
627-
case 0x73: fallthrough
628-
case 0x53: fallthrough
629-
case 0x69: fallthrough
630-
case 0x49: fallthrough
631-
case 0x6C: fallthrough
632-
case 0x4C: fallthrough
633-
case 0x71: fallthrough
634-
case 0x51:
635-
aCoder.encode(int64Value, forKey: "NS.intval")
636-
case 0x66: fallthrough
637-
case 0x64:
638-
aCoder.encode(doubleValue, forKey: "NS.dblval")
639-
default: break
640-
}
624+
break
625+
case 0x63: fallthrough
626+
case 0x43: fallthrough
627+
case 0x73: fallthrough
628+
case 0x53: fallthrough
629+
case 0x69: fallthrough
630+
case 0x49: fallthrough
631+
case 0x6C: fallthrough
632+
case 0x4C: fallthrough
633+
case 0x71: fallthrough
634+
case 0x51:
635+
aCoder.encode(int64Value, forKey: "NS.intval")
636+
case 0x66: fallthrough
637+
case 0x64:
638+
aCoder.encode(doubleValue, forKey: "NS.dblval")
639+
default: break
641640
}
642641
}
643642
}

0 commit comments

Comments
 (0)