Post

Replies

Boosts

Views

Activity

Reply to Accept CKShare with the SwiftUI lifecycle.
Hi Kevin, Interestingly creating the share and the SharingController wasn't too difficult. Other than that the title of the SharingController sometimes just being "Untitled" it works as expected. No idea why the title configuration is sometimes not filled in correctly. I switched back to UIKit Lifecycle because it is just so frustrating seeing how little the SwiftUI lifecycle can do right now... I hope they will add these methods natively in future releases without the need of DelegateAdaptors. Take care, David
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’21
Reply to Understanding SwiftUI and control flow
Hi, I also had some problems with sheets and a Binding Bool in the past. I would try two things. Are you sure that the tmpEvent you set using showSheet() isn't returning an optional value that might be nil? you can try adding: guard let tmpEvent = Event(context: viewContext) else{ print("found nil") return } and if you see something in the log you know that it contains nil. This also prevents the sheet from being shown while the Event is nil. In general I would avoid having optionals in your views because you always have to deal with optional values, or risking that your app is getting terminated because of force unwrapping. If that doesn't work, try using an default value and see if it later on changes to the correct value. If this is the case, your sheet is presented before the event got an initial value... Take care, David
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to SwiftUI Generic Binding Array
Hi, by looking at the other post I would recommend using a different model structure to achieve what you want. ForEach doesn't know what model you currently have and therefore can't access the values behind them, event if they have the same name. I would create a universal model that has a variable pointing at the type. And based on that type you can decide if you want to show a traffic sign, or a police sign. enum SignType{ case PoliceSign case TrafficSign } struct Sign: Codable, Identifiable{ var id: UUID var type: SignType // use enum to define type var image: String? ... } And by making the struct conform to Identifiable you will always have a unique id. Depending an the type you can then access the corresponding selection and solve the issue with mismatching models. David
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to ForEach error with array of videos
Hi, Based on your error messages you have two separate problems. Multiline "Cannot declare entity named '$reel'; the '$' prefix is reserved for implicitly-synthesized declarations" This happens because $ is for Binding variables and ForEach does not work with Bindings. So you will have to remove the $ in the ForEach and also when declaring the variable inside the closure because you only get a one-way variable from ForEach. That leads to the second problem. the view you have inside the ForEach requires a Binding Variable, which you can only get from @State, or @ObservedObject and because ForEach doesn't work with Bindings (yet) you will have to find a solution without binding the reel to the View. Maybe send the id of the reel into the next view and then fetch the full reel separately. Take care, David
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’21
Reply to @Published properties and the main thread
Hi, you use the @Published wrapper for Observable Object and environment objects. They behave similarly to the @State wrapper, but can be used to get view updates from classes outside the current view, bind multiple views to one value and so on. So the only reason why you would want an @Published property is when you want to take advantage of the automatic view updates. As you already mentioned, if any of your values change in the background you need to push these changes on the main thread. Because how should SwiftUI know that you want an update on your UI if the Object was modified by a background thread. I don't white get why you would "confuse" the user by having the wrong status displayed. If you have a background task that needs to finish before changing the UI, you should use either a completion handler, or if your app targets iOS 15 you could use the async-await pattern...
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to Calling API
Instead of showing a static text you could create a simple animation(like left to right) and display that where the thumbnail would be. This gives the user visual feedback that something is loading and happening and not that your app is frozen or stuck.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to How do I make a new view in Swift Playgrounds App Project in Xcode?
Hi, Technically you could add a new subview to your playground like this: class SecondView: UIView { func loadView() { let label = UILabel() } } //and add this to your main views `loadView()` let sView = SecondView() sView.backgroundColor = .red sView.frame = view.frame sView.loadView() But as soon as you want to use multiple views, windows or even navigate between them I highly recommend creating a sample project in Xcode using SwiftUI, or storyboard. It just is more convenient at this point. Take care David
Apr ’22
Reply to Loading loop preview in Xcode
Hi, it looks like there is more code than is shown in your screenshot. Could you share the entire View you are trying to preview? Alternatively your Mac could struggle building your preview, are any other apps running that could eat up your performance? Take care David
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’22