I\'m having an issue when using a Generic as the type constraint on a property. Here is a very simple example:
import UIKit
class TSSignal
This is NOT an "answer" (it is my own question), but I thought it worth noting what I did in this case to move passed this situation, for the time being.
import UIKit
class TSSignal {
var message: AnyObject?
init() {
}
}
Lame, but I am sure it's only temporary.
There is a workaround without type erasure (works as of Xcode6-Beta2):
import UIKit
class TSSignal<MessageType> {
var _message: [MessageType] = []
func getMessage() -> MessageType? {
if _message.count > 0 {
return _message[0]
} else {
return nil
}
}
func setMessage(maybeMessage: MessageType?) {
if let message = maybeMessage {
_message = [message]
} else {
_message = []
}
}
init() {
}
}
EDIT EDIT:
This is definitely a bug in the compiler.
I tried to 'outsmart' the compiler by using the following:
class TSSignal<TMessage>
{
var messageType : Optional<TMessage> = nil
init() { }
}
Same issue.