I have done lesson 4 of Your Second iOS & SwiftUI App. I have an issue with my UIImage
view is not in the scope because of that it give me compile error. I comment out my code to be able to compile the code but I could not figure out why UIImage
is out of the scope
this is my BookView
import SwiftUI
extension Book {
struct Image: View {
let title: String
var body: some View {
let symbol =
SwiftUI.Image(title: title)
?? .init(systemName: "book")
symbol
.resizable()
.scaledToFit()
.frame(width: 80, height: 80)
.font(Font.title.weight(.light))
.foregroundColor(.secondary.opacity(0.5))
}
}
}
extension Image {
init?(title: String) {
guard
let character = title.first,
case let symbolName = "\(character.lowercased()).square"
,UIImage(systemName: symbolName) != nil <-- Cannot find 'UIImage' in scope
else {
return nil
}
self.init(systemName: symbolName)
}
}
struct Book_Previews: PreviewProvider {
static var previews: some View {
VStack {
Book.Image(title: Book().title)
Book.Image(title: "")
Book.Image(title: "📖")
}
}
}