I tried both Xcode 11.5.6 & 12 beta 5 with the same result:
The vary last line of this lesson
.self.presentationMode.wrappedValue.dismiss()
produces a a compile error - "Value of tupletype '()' has no member 'presentationMode'
Any ideas please. AddBookView code below:
import SwiftUI
struct AddBookView: View {
// MARK: - PROPERTIES
@Environment(\.managedObjectContext) var moc
@Environment(\.presentationMode) var presentationMode
@State private var title = ""
@State private var author = ""
@State private var rating = 3
@State private var genre = ""
@State private var review = ""
let genres = ["Fantasy", "Horror", "Kids", "Mystery", "Poetry", "Romance", "Thriller", "Spy"]
// MARK: - BODY
var body: some View {
NavigationView {
Form {
// MARK: _ SECTION 1
Section {
TextField("Name of Book", text: $title)
TextField("Author's name", text: $author)
Picker("Genre", selection: $genre) {
ForEach(genres, id: \.self) {
Text($0)
}
}//: PICKER
}//: SECTION 1
// MARK: _ SECTION 2
Section {
Picker("Rating", selection: $rating) {
ForEach(0..<6) {
Text("\($0)")
}
}
TextField("Write a Review", text: $review)
}//: SECTION 2
// MARK: _ SECTION 3
Section {
Button("Save") {
let newBook = Book(context: self.moc)
newBook.title = self.title
newBook.author = self.author
newBook.rating = Int16(self.rating)
newBook.genre = self.genre
newBook.review = self.review
try? self.moc.save()
.self.presentationMode.wrappedValue.dismiss()
}
}//: SECTION 3
} //: FORM
.navigationBarTitle("Add Book")
}//: NAVIGATION
}//: VIEW
}//: STRUCT
// MARK: - PREVIEW
struct AddBookView_Previews: PreviewProvider {
static var previews: some View {
AddBookView()
}
}