如何在swift 4中获取CATextLayer的"string"属性值?

How to get "string" attribute value of CATextLayer in swift 4?

我正在尝试访问 CATextlayer 中的文本值,我可以访问其他值,但无法访问此字符串属性,它甚至没有显示在智能上。还有其他方法可以访问它吗?我是 swift.I 的新手,有如下内容:

let textLayer = CATextLayer()
textLayer.isHidden = true
textLayer.contentsScale = UIScreen.main.scale
textLayer.fontSize = 14
textLayer.font = UIFont(name: "textLayer = CATextLayer()
textLayer.isHidden = true
textLayer.contentsScale = UIScreen.main.scale
textLayer.fontSize = 14
textLayer.font = UIFont(name: "Avenir", size: textLayer.fontSize)
textLayer.alignmentMode = kCAAlignmentCenter", size:textLayer.fontSize)
textLayer.string = "someText"
textLayer.foregroundColor = textColor.cgColor
textLayer.backgroundColor = color.cgColor
textLayer.isHidden = false
textLayer.contentsScale = UIScreen.main.scale
textLayer.name="someText"

我想像

一样访问这个字符串属性值
 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    let touch = touches.first

    guard let point = touch?.location(in: cameraView) else { return }

    print(self.selectedObject = cameraView.layer.sublayers![2].string!)

    self.selectedObject = cameraView.layer.sublayers![2].name!//Textlayer
  // print(cameraView.layer.sublayers![3])//shapelayer


}

sublayers 属性 声明为基础 class [CALayer]

要从特定的 CALayer subclass 中获取值,您必须转换类型

if let textLayer = cameraView.layer.sublayers?[2] as? CATextLayer {
    print(textLayer.string!)
}