It's my first program in Swift. The function returns two random locations (CGPoints) which are points on the perimeter of a circle of radius = variable (passed in by the calling program). The two CGPoints must also be greater than degreesApart around the perimeter of the circle. I have written the following code:
func returnPerimeterPoints (radius: Int, degreesApart: Int) -> (CGPoint, CGPoint) {
var perimeterPoint1 = CGPoint(x:Int(arc4random()%radius),y:Int(arc4random()%radius))
var perimeterPoint2 = CGPoint(x:Int(arc4random()%radius),y:Int(arc4random()%radius))
return (perimeterPoint1, perimeterPoint2)
}
print(returnPerimeterPoints(20, 24))
I have received the following errors:
cannot find 'CGPoint' in scope
cannot find 'arc4random' in scope
What libraries do i need to include and what can i do to get the CGPoints like i mentioned in the first paragraph?
CGPointis defined inCoreGraphics, but will also be imported by default when importing a UI library likeUIKitorSwiftUI.arc4randomin part ofDarwin(the kernel) but, again, will be imported automatically when you import an Apple framework that depends on it, likeFoundationor evenCoreGraphicsas well.