Arbitur
Arbitur

Reputation: 39091

Return CGPoint from extension

Im trying to return a CGPoint from a CGPoint extension.

I have this extension:

extension CGPoint {
    func Multiply(factor:Int) {
        return self.x*factor, self.y*factor
    }
}

Now, no matter how I change the return line I get a different error. Ive tried to put {},[],() around it, Ive tried {1,2},[1,2],(1,2)

And CGPointMake() isnt allowed.

And like I could in Obj-C {.x = 1, .y = 2}

Nothing seems to work and I get a different error for each.

Upvotes: 1

Views: 471

Answers (1)

Atomix
Atomix

Reputation: 13862

You forgot to declare the return type (CGPoint):

extension CGPoint {
    func Multiply(factor:CGFloat) -> CGPoint {
        return CGPoint(x: self.x*factor, y:self.y*factor)
    }
}

That should compile.

Upvotes: 3

Related Questions