Xcode 7.0.1: Class Mutibility in Initializer

Originator:ThaneGill
Number:rdar://23224354 Date Originated:22-Oct-2015 01:42 PM
Status:Duplicate/<20395708> Resolved:
Product:Developer Tools Product Version:Xcode 7.0.1 (7A1001)
Classification:Enhancement Reproducible:Always
 
Summary:
Enable mutability in initializer 

Steps to Reproduce:
See example code in “MutableInitializer.playground”

Expected Results:
Able to assign self in initializer.

Actual Results:
Unable to assign self in initializer.

Comments

Duplicate of 20395708 (Open)

Twitter Conversation with Chris Lattner

https://storify.com/thanegill/conversation-with-thanegill-and-clattner-llvm

Contents of MutableInitializer.playground

import Foundation

class SomeClass: RawRepresentable { typealias RawValue = Int

var rawValue: Int

static var allValues: [SomeClass] = []

required init?(rawValue: Int) {
    // Set self to object if object for rawValue exists in allValues else initialize and append to allValues
    if let object = SomeClass.allValues.filter({ $0.rawValue == rawValue }).first {
        // Cannot assing to value: 'self' is immutable
        self = object
    } else {
        self.rawValue = rawValue
        SomeClass.allValues.append(self)
    }
}

}


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!