swift - NSTextAlignment can not be represented in Objective-C -
in swift class, exposed variable objective c defining
@objc var textalignment: nstextalignment? { didset { if textalignment != nil { label.textalignment = textalignment! } } }
and wrong! because compiler complains not type can represented in objective-c.
but followings right
var textalignment: nstextalignment? { didset { label.textalignment = textalignment! } }
or
@objc var textalignment: nstextalignment { didset { label.textalignment = textalignment } }
so looks if expose method objective-c, can not optional value. if use internally, can! because scalar value in objective-c have no way represent nil?
my intention want make not compulsory.
nstextalignment
enum, not class - textalignment
variable can't mapped optional objective c because require pointer object type.
try:
@objc var textalignment: nstextalignment { ... }
or, if need optional, expose objective c nsnumber
, wrapping textalignment.rawvalue
or setting nil when no value needed.
Comments
Post a Comment