swiftlang/swift

[SR-1283] RawRepresentable extension for Self:NSCoding breaks implicit RawRepresentable implementation for enums

Open

#43.891 aberto em 21 de abr. de 2016

Ver no GitHub
 (2 comments) (0 reactions) (0 assignees)Swift (10.719 forks)batch import
bugcompilergood first issue

Métricas do repositório

Stars
 (69.989 stars)
Métricas de merge de PR
 (Mesclagem média 8d 17h) (510 fundiu PRs em 30d)

Description

Previous ID SR-1283
Radar None
Original Reporter josh (JIRA User)
Type Bug

Apple Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29)

Votes 0
Component/s Compiler
Labels Bug, StarterBug
Assignee None
Priority Medium

md5: ebcb1594c186768ea99ccc914c314b25

Issue Description:

Copy + paste attached sample code into a Playground.

import Foundation

enum Status: Int {
    case Good
    case Bad
}

extension RawRepresentable where Self: NSCoding {
    init?(rawValue: NSData) {
        if let instance = NSKeyedUnarchiver.unarchiveObjectWithData(rawValue) as? Self {
            self = instance
        } else {
            return nil
        }
    }
    
    var rawValue: NSData {
        get {
            return NSKeyedArchiver.archivedDataWithRootObject(self)
        }
    }
}

Guia do colaborador