如何在swift中重写计算属性

如何在swift中重写计算属性,swift,properties,overriding,Swift,Properties,Overriding,我只是尝试一下swift的新功能 但它会引起编译器错误: Playground execution failed: super.init called multiple times in initializerinteger overflows when converted from 'Builtin.Int32' to 'Builtin.Int8' 您报告的特定错误来自重写init(),因为您为c提供了不同的默认值。尝试显式地编写初始化器。无论如何,在我看来,didSet重载在操场上不能

我只是尝试一下swift的新功能

但它会引起编译器错误:

Playground execution failed: super.init called 
multiple times in initializerinteger overflows 
when converted from 'Builtin.Int32' to 'Builtin.Int8'

您报告的特定错误来自重写
init()
,因为您为
c
提供了不同的默认值。尝试显式地编写初始化器。无论如何,在我看来,
didSet
重载在操场上不能正常工作:-/如果你删除
=9
部分,它就会工作。原始代码无法编译,因为无法使用存储属性重写继承的属性。您必须使用计算属性重写一个。
Playground execution failed: super.init called 
multiple times in initializerinteger overflows 
when converted from 'Builtin.Int32' to 'Builtin.Int8'