“得到"是什么意思?在协议的属性声明中是什么意思?

编程入门 行业动态 更新时间:2024-10-26 06:26:54
本文介绍了“得到"是什么意思?在协议的属性声明中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在查看自动布局库中的一些代码.其中有一个UIView采用的协议:

I'm looking at some code from an auto layout library. In it, there is a protocol adopted by UIView:

extension UIView: Constrainable {} extension UILayoutGuide: Constrainable { // LayoutGuide doesn't have baseline anchors, so just use the bottom anchor public var firstBaselineAnchor: NSLayoutYAxisAnchor { return bottomAnchor } public var lastBaselineAnchor: NSLayoutYAxisAnchor { return bottomAnchor } } public protocol Constrainable { var topAnchor: NSLayoutYAxisAnchor { get } var bottomAnchor: NSLayoutYAxisAnchor { get } var leftAnchor: NSLayoutXAxisAnchor { get } var rightAnchor: NSLayoutXAxisAnchor { get } var leadingAnchor: NSLayoutXAxisAnchor { get } var trailingAnchor: NSLayoutXAxisAnchor { get } var centerXAnchor: NSLayoutXAxisAnchor { get } var centerYAnchor: NSLayoutYAxisAnchor { get } var widthAnchor: NSLayoutDimension { get } var heightAnchor: NSLayoutDimension { get } var firstBaselineAnchor : NSLayoutYAxisAnchor { get } var lastBaselineAnchor : NSLayoutYAxisAnchor { get } }

空的 { get } 有什么作用?

推荐答案

这些是采用协议的类必须为其提供 getter 的属性.该协议没有指定有关 setter 的任何内容,因此类可以提供计算属性而不是存储属性.

These are properties for which the classes that adopt the protocol must supply a getter. The protocol does not specify anything about the setter, so classes could supply a computed property instead of a stored one.

例如,一个采用Constrainable的类可以通过添加

For example, a class that adopts Constrainable could satisfy a requirement of having topAnchor by adding

var topAnchor: NSLayoutYAxisAnchor

或通过添加

var topAnchor: NSLayoutYAxisAnchor { ... return ... }

更多推荐

“得到"是什么意思?在协议的属性声明中是什么意思?

本文发布于:2023-11-03 01:16:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1553889.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   声明   协议   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!