SwiftUI · Using Bindings to Build a Settings Page | raywenderlich.com

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4001741-swiftui/lessons/32

When finishing the PetReplacementRow, I noticed that the preview works when looking at PetReplacementRow by itself. When opening SettingsView, I get the following error:

PotentialCrashError: P04E04-Complete.app may have crashed

P04E04-Complete.app may have crashed. Check ~/Library/Logs/DiagnosticReports for any crash logs from your application.


| Error Domain=com.apple.dt.ultraviolet.service Code=12 “Rendering service was interrupted” UserInfo={NSLocalizedDescription=Rendering service was interrupted}

When opening ContentView, the Preview for MewsListView works just fine, but the SettingsView crashes too.

Works on a Device (iPhone 11 Pro) and Simulators. In Device and Simulators though, when tapping the “Replace Pet” Picker, the CatMaskImage appears without content inside. Don’t know if this is related to the above crash.

Xcode version 11.2.1
OS 10.15.1

If anyone found the same error:

From the logs found out that the EnvironmentObject petPreferences in SettingsView was not being set when trying to preview SettingsView or ContentView. Solved this by adding:

static let petPreferences = PetPreferences()

static var previews: some View {

inside SettingView. Doing the same environment in ContentView. That way the previews can be used without crashing. Correct me if I’m wrong, but SceneDelegate is providing the EnvironmentObject only when running on simulator or a device.

Still can’t get the images to show when tapping the picker, though.

1 Like

When running on the simulator, I do not see the images when drilled into the picker either. Some quality control issues with this class for sure.

Hey Im sorry you’ve had issues with this class. We’re doing a review just now and will fix all the little issues we possibly can. Thanks so much for reporting it and it will probably be a silly mistake I made somewhere. Have a nice day :smiley:

yes, you need to pass .environmentObject() to every Previews

Seems like many photos were missing?
Like the Profile pictures folder

I tried to add the pictures but keep getting this black profiles

Assets are missed for profile images!

Maybe something’s wrong

I get fatal error: Index out of range when moving the slider!

Hey @jawad14 - an update is about to be published with all the assets included. They’re in the ‘completed’ folder if you need them. Laurie.

1 Like

@jawad14 in regards to your ‘out of range’ exception, can you show me the code you’ve got? I’ve just double-checked the project and code and everything is working fine. Thanks so much. Laurie.

Thanks @isaacmendez I’ve tested the code in end folder and it works with no crashes unlike the code I’ve added in Begin folder which means this app crash caused by me ^^.

Let me take this chance to say Thanks so much for all efforts
you’ve put in this course also I liked your smiles in the videos :grinning:.

@jawad14 Do you still have issues with this?

I’ve come back to this one after trying out some stuff on my own app to get some more experience in, and I’m curious: what’s the difference between using $settings.desiredTemperature.wrappedValue or just settings.desiredTemperature ? They both seem to do the same thing. Is this just some syntax that has been added in the latest Swift version since this lesson was created, or is there’re a functional difference that I’m missing?

Hey Bill - I don’t think there is much of a difference. The wrapped value property was a requirement for the particular version of Xcode we used and I couldn’t find any documentation on it at the time. I believe it is simply a safe way to access the property but if you find out any more let me know! Laurie

When I try to select a pet then no image is rendered. I checked all images are available in Assets. See these screen shots. Same issue if I run the project in “end” folder where I haven’t made any change. So doesn’t look like my coding/typing has any issue.

When I do select a Pet and comeback to settings screen then image get displayed.

See second post as for new user single image is allowed

Can you suggest what is the issue here?

I am on Xcode 11.5/macOS 10.15.4

This is in continuation of my above post.

Hey @ishwar_jindal - this course specifies a specific version of Xcode and SwiftUI at the beginning that it supports. I believe the issue you’re getting might be due to a recent change and I’ll need to investigate it. Thanks for flagging this for future updates. Laurie