Inheritance from non-protocol, non-class type 'CGPoint'
Asked Answered
T

3

34

I want to create a custom CGPoint subclass to add some proprieties, but I get this error:

Inheritance from non-protocol, non-class type '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. If there are already some questions or solutions to this problem, please point me in the right direction.

Tanny answered 25/10, 2014 at 17:29 Comment(0)
R
38

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.

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
}
Ratel answered 25/10, 2014 at 17:37 Comment(1)
Thank you a lot, this will help me out :)Eared
F
3

You cannot inherit a class from Structure. Structure does not support Inheritance. But if you want, you may use extension for structure.

Frontpage answered 13/6, 2018 at 10:52 Comment(0)
B
0

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.

Buskined answered 25/10, 2014 at 17:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.