UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Problems with CGAffineTransform. 100 Days of SwiftUi

Forums > 100 Days of SwiftUI

Hey everyone!

I'm learning SwiftUI now (100 Days of SwiftUi), day 44, Project 9, part 2. The lesson is called Transforming shapes using CGAffineTransform and even-odd fills.

I have a problem. Can you please help me?

The code that contains the problem:

struct Flower: Shape {

var petalOffset: Double = -20

var petalWidth: Double = 100

func path(in rect: CGRect) -> Path {

    var path = Path()

    for number in stride(from: 0, to: CGFloat.pi * 2, by: CGFloat.pi / 8) {

           let rotation = CGAffineTransform(rotationAngle: number)   // The problem is here

           let position = rotation.concatenating(CGAffineTransform(translationX: rect.width / 2, y: rect.height / 2)) // And here

In let rotation = CGAffineTransform(rotationAngle: number) XCode tells me about the error:

Argument passed to call that takes no arguments

And in let position = ... XCode offers me to remove:

Remove '(translationX: rect.width / 2, y: rect.height / 2)'

I think, maybe this is a bug in XCode, because when i try to open parentheses after CGAffineTransform there is nothing there. I mean no possible methods or variants. I tried to find the possible solution in google, but did not see a similar problem on StackOverFlow and in other forums.

Thank you very much!

2      

Please show the rest of your Flower struct and also your ContentView.

One of the annoying things about SwiftUI is that when errors show up they don't always point to the correct location that is causing the problem. So just because you get errors on those two lines doesn't necessarily mean that's where the troublesome code is located.

FWIW, the code you gave above is exactly the same as Paul's so that's another reason why I think the issue might lie elsewhere.

2      

@roosterboy, thank you very much for your quick answer,

The problem was that for this lesson i created one extra SwiftUI View file, and i named this file CGAffineTransform.

I deleted this file and created another with a different name, and now everything is working well.

The code was so:

struct CGAffineTransform: View { var body: some View { Text("Hello World") } }

struct Flower: Shape { ... }

2      

Yep, that'll do it. Xcode got confused as to which CGAffineTransform you were referring to.

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.