This is a companion discussion topic for the original entry at https://www.raywenderlich.com/15234721-your-second-ios-and-swiftui-app/lessons/12
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/15234721-your-second-ios-and-swiftui-app/lessons/12
This Image Binding tutorial will not work with the current XCode 12.1 (even though the tutorial came out after this version of XCode).
The class Library needs to become an ObservableObject and uiImages needs to be marked with @Published:
final class Library: ObservableObject {
ā¦
@Published var uiImages: [Book: UIImage] = [:]
}
Then the library variable in ContentView in ContentView.swift needs to be changed from @State to @StateObject
struct ContentView: View {
@StateObject var library = Library()
ā¦
Your list in ContentView and DetailView will then update with the image that has been selected.
I just tested the uploaded materials again, with no problems. What youāve shown here doesnāt solve any problem that exists at this point in the course. Please upload your version of the project without using a model object, and Iāll have a look!
(My guess is that your Library is a class, instead of a struct.)
You are correct that I was using a class-not a struct-which was causing the problem. If you skip ahead to your supplied Starter and Final projects for 12-image-binding your version of Library uses a struct and the project works fine.
Unfortunately, I have worked through your projects in order and have carefully built my project from scratch with the exception of Library.swift which we added in 05-lists: in both the Starter and Final projects there, you have supplied a final class rather than a struct. Furthermore, your video actually shows Library.swift with a final class rather than a struct:
[Uploading: Library.swift screenshot.png.pngā¦]
Hence the problemā¦
Thanks for letting me know. Iāve updated the downloadable materials and added an Author Note for Episode 5.
I went through this tutorial a week or so ago, and was unable to get images from the picker to show up on the detail view or list view.
I went through it AGAIN tonight (from scratch) to make sure i hadnāt mistyped anything and Iām having the exact same issue.
Iām on xcode 12.2. I copy/pasted the library file contents into my project but otherwise started from scratch.
Hi!
Please upload your project and Iāll have a look.
And the way I will make a comparison to the downloadable final project is by using Git. Highly recommended learning!
Hmm, itās saying new user cannot upload attachments
Iād recommend pushing it to GitHub, or using Dropbox.
You are also using a class instead of a struct, as described earlier in this thread.
Thanks, same problem for me )
Hello,
Iām trying to follow this course but in my simulator the Image arenāt saved.
this is the response of the console
2021-03-28 21:51:49.411365+0200 LeggiMi2021[12526:4401792] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you donāt want.
Try this:
(1) look at each constraint and try to figure out which you donāt expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
ā<NSLayoutConstraint:0x600001664280 āBIB_Trailing_CB_Leadingā H:[_UIModernBarButton:0x14ce1e080]-(6)-[_UIModernBarButton:0x14ce1caf0āLa Mia Libreriaā] (active)>ā,
ā<NSLayoutConstraint:0x6000016642d0 āCB_Trailing_Trailingā _UIModernBarButton:0x14ce1caf0āLa Mia Libreriaā.trailing <= _UIButtonBarButton:0x14ce1bc70.trailing (active)>ā,
ā<NSLayoutConstraint:0x600001665040 āUINav_static_button_horiz_positionā _UIModernBarButton:0x14ce1e080.leading == UILayoutGuide:0x600000c55340āUIViewLayoutMarginsGuideā.leading (active)>ā,
ā<NSLayoutConstraint:0x600001665090 āUINavItemContentGuide-leadingā H:[_UIButtonBarButton:0x14ce1bc70]-(0)-[UILayoutGuide:0x600000c55260āUINavigationBarItemContentLayoutGuideā] (active)>ā,
ā<NSLayoutConstraint:0x60000164f4d0 āUINavItemContentGuide-trailingā UILayoutGuide:0x600000c55260āUINavigationBarItemContentLayoutGuideā.trailing == _UINavigationBarContentView:0x14cf0f8f0.trailing (active)>ā,
ā<NSLayoutConstraint:0x600001665810 āUIView-Encapsulated-Layout-Widthā _UINavigationBarContentView:0x14cf0f8f0.width == 0 (active)>ā,
ā<NSLayoutConstraint:0x60000164f890 āUIView-leftMargin-guide-constraintā H:|-(0)-UILayoutGuide:0x600000c55340āUIViewLayoutMarginsGuideā (active, names: ā|ā:_UINavigationBarContentView:0x14cf0f8f0 )>ā
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600001664280 āBIB_Trailing_CB_Leadingā H:[_UIModernBarButton:0x14ce1e080]-(6)-[_UIModernBarButton:0x14ce1caf0āLa Mia Libreriaā] (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.