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

SOLVED: Project 9 Simple Question

Forums > 100 Days of SwiftUI

In project 9 we define struct for many different types of shapes. If I wanted to define each shape in it's own separate file, so that they are not all crammed into ContentView.swift, what would I need to import into each file?

I tried import CoreGraphics but it still says that Shape is not defined in the current scope.

I can use import SwiftUI to make it work, but I'm not sure if that would be the correct way, or if there is a smaller library/framework that I should be importing instead?

Here is an example of one of the struct definitions:

struct Triangle: Shape {
    func path(in rect: CGRect) -> Path {
        var path = Path()

        path.move(to: CGPoint(x: rect.midX, y: rect.minY))
        path.addLine(to: CGPoint(x: rect.minX, y: rect.maxY))
        path.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))
        path.addLine(to: CGPoint(x: rect.midX, y: rect.minY))

        return path
    }
}

2      

Shape is part of the SwiftUI framework, so that's the correct import.

2      

Thank you!

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.