TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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      

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.