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

Bookworm Issue - Lesson: Creating books with Core Data

Forums > 100 Days of SwiftUI

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() } }

3      

Have you removed the first . from this line? I think this is a typo and should be without the .

3      

Thank you @Hatsushira! One period/fullstop can cost a day's searching. I must have looked at it 50 times.

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.