Home > Mobile >  Error while passing object to variable in Swift struct
Error while passing object to variable in Swift struct

Time:04-22

enter image description hereI am trying to pass an object while creating the struct in Swift, but the compiler is showing an error.

struct Car {
    var make: String
    var year: Int
    var color: Color
    var topSpeed: Int
}

I am having an error next to the "var color: Color" (Cannot find type 'Color' in scope)

I am reading this from an official but old Swift book. Is there any change to Swift recently?

CodePudding user response:

Add import SwiftUI to your file

  • Related