Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBezierPath Init() doesnt expect byRoundingCorners parameter

Can't seem to use the typical init for UIBezierPath that contains the parameter byRoundingCorners parameter:

    var maskPath = UIBezierPath(roundedRect: headerView.bounds, byRoundingCorners: (UIRectCorner.TopLeft | UIRectCorner.TopRight), cornerRadii: 5.0)

Gives the error "Extra argument 'byRoundingCorners in call"

Is this a Swift bug?

like image 990
Jonah Katz Avatar asked Jul 23 '14 01:07

Jonah Katz


1 Answers

It is a Swift bug in so far as the error message is quite misleading. The real error is that the cornerRadii parameter has the type CGSize, but you are passing a floating point number (compare Why is cornerRadii parameter of CGSize type in -[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]?).

This should work (Swift 1.2):

var maskPath = UIBezierPath(roundedRect: headerView.bounds,
            byRoundingCorners: .TopLeft | .TopRight,
            cornerRadii: CGSize(width: 5.0, height: 5.0))

Note that in Swift 2, the type of byRoundingCorners argument was changed to OptionSetType:

var maskPath = UIBezierPath(roundedRect: headerView.bounds,
            byRoundingCorners: [.TopLeft, .TopRight],
            cornerRadii: CGSize(width: 5.0, height: 5.0))
like image 108
Martin R Avatar answered Nov 09 '22 03:11

Martin R