s3协议和swift协议
The CustomStringConvertible
protocol becomes important when you need something to be printed out in the console. Remember, the print()
function is going to represent the textual form of the object in the console. However, this function has its own limitations and does not always work as you wish.
当您需要在控制台中打印出某些内容时, CustomStringConvertible
协议就变得很重要。 请记住, print()
函数将代表控制台中对象的文本形式。 但是,此功能有其自身的局限性,并不能始终如您所愿。
Let me clarify with an example. If you want to define a Car
class:
让我用一个例子来阐明。 如果要定义Car
类:
You can see the print
statement did not work properly. CustomStringConvertible
may be very useful in this situation, as it has one requi