Jonah Katz
Jonah Katz

Reputation: 5288

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?

Upvotes: 7

Views: 2604

Answers (1)

Martin R
Martin R

Reputation: 539805

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))

Upvotes: 20

Related Questions