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.

enter image description here


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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -