Use of unresolved identifier 'CATextLayerAlignmentMode'

I am getting this error in xcode after migrating to swift 4.2. Please how can i resolve this

This isn’t a Swift change but an SDK change.

In older SDKs the alignmentMode property of CATextLayer was stringly-typed. That is, alignmentMode was declared to be of type String and the various alignment constants (kCAAlignmentNatural and so on) were also declared as strings.

This has changed in the new SDKs that come with Xcode 10.0 beta (which includes Swift 4.2). The alignmentMode property now has an enum type, CATextLayerAlignmentMode, and that enum has values that represent the various alignment options (.center and so on).

It’s hard to say how this results in an unresolved identifier error. If you can’t fix this based on the above, please post back with more details. Specifically:

  • What version of Xcode are you using?

  • What does the failed code look like?

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple