[英]Inheritance from non-protocol, non-class type 'CGPoint'
I want to create a custom CGPoint subclass to add some proprieties, but I get this error: 我想创建一个自定义CGPoint子类以添加一些属性,但是出现此错误:
Inheritance from non-protocol, non-class type 'CGPoint'
从非协议,非类类型'CGPoint'继承
I have no idea why this is not possible. 我不知道为什么这不可能。 My class is as simple as this:
我的课程很简单:
import UIKit
class IYAttachPoint: CGPoint {
var holder: String = "No holder"
var unavailable: Bool = false
}
I've tried adding some libraries like CoreGraphics or QuartzCore without success. 我尝试添加一些库,例如CoreGraphics或QuartzCore,但没有成功。 If there are already some questions or solutions to this problem, please point me in the right direction.
如果已经对此问题有任何疑问或解决方案,请指出正确的方向。
This is not possible because you want to inherit a struct from a class. 这是不可能的,因为您要从类继承结构。
CGPoint
is a struct and therefore it does not support inheritance, although it can conform to protocols. CGPoint
是一个结构,因此尽管它可以遵循协议,但它不支持继承。
If you really want to do this, use composition instead of inheritance. 如果您确实要执行此操作,请使用合成代替继承。
class IYAttachPoint {
var point:CGPoint?
var holder: String = "No holder"
var unavailable: Bool = false
}
The error message you are getting is telling you exactly what is wrong. 您收到的错误消息正在告诉您确切的错误。 The only things that can be used as base classes are, well, classes.
可以用作基类的唯一东西就是类。 You can also have your class/struct/enum conform to a protocol but only classes can be used for inheritance.
您也可以使您的类/结构/枚举符合协议,但只能将类用于继承。 Since CGPoint is a struct it can't be used for subclassing purposes.
由于CGPoint是结构,因此不能用于子类化。
You cannot inherit a class from Structure. 您不能从Structure继承类。 Structure does not support Inheritance.
结构不支持继承。 But if you want, you may use extension for structure.
但是,如果您愿意,可以将扩展名用于结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.