Post

Replies

Boosts

Views

Activity

Reply to User configurable WidgetKit backgrounds ?
Hi, yeah the thing with the battery widget and the forbidden background blur... Well at least for the configurable colors there is a solution. I have seen a few apps implement this feature. The easiest way I think is to use the widget configuration to give the user a list of options, and then storing the picked color. You could then get the color when building the widget, maybe UserDefaults or something like that, and set the background accordingly. The user could use the main app to edit and add colors to their list which is then displayed in the configuration... Even though it is a hacky solution it should work. Take care, David
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’21
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 User configurable WidgetKit backgrounds ?
Hi, yeah the thing with the battery widget and the forbidden background blur... Well at least for the configurable colors there is a solution. I have seen a few apps implement this feature. The easiest way I think is to use the widget configuration to give the user a list of options, and then storing the picked color. You could then get the color when building the widget, maybe UserDefaults or something like that, and set the background accordingly. The user could use the main app to edit and add colors to their list which is then displayed in the configuration... Even though it is a hacky solution it should work. Take care, David
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’21
Reply to Is there a way to pass a ForEach variable out of the loop?
Hi, I'm not quite sure what you mean by "pass out of loop". The "row" variable is obviously only available inside the closure because it gets reused by the loop. But you can declare a swift @State var name: Bool = false (or any other type) and modify that using a button inside the loop. Take care, David
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’21
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:
Replies
Boosts
Views
Activity
Mar ’21
Reply to If navigationBarTitleDisplayMode?
Hi, you could set the display mode like this: swift .navigationBarTitleDisplayMode(active ? .automatic : .inline) hope this helps. Take care, David
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’21
Reply to Xcode 12.5 on macOS 12: Code signing "MyAppExtension.appex" failed.
Same here
Topic: Code Signing SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’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:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Not working on iPad
Hi, when you say it aborts on the line of the Circle view, what does the log say? Could you post the log message when your app terminates? Take care, David
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Aug ’21
Reply to Strange behaviour with SwiftUI in latest iOS beta
Hi, I am experiencing the same issue. The last beta has some weird effect on how the accent color is applied. Hopefully this issue will be fixed in a future release. Take care, David
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
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:
Replies
Boosts
Views
Activity
Sep ’21
Reply to swiftUI Picker closes automatically
Hi, Can you provide your complete view, including the @Binding selection and the parent view? Take care, David
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to SwiftUI: How to implement horizontal automatic scrolling scrollView
Hi, I would start by wrapping your ScrollView in a ScrollViewReader. With this property you can programmatically scroll to positions and even animate them. By giving the last item in your list an id like so .id(topID) you can scroll to this item using .scrollTo(_anchor) Hope this helps, take care David
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’22
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
Replies
Boosts
Views
Activity
Apr ’22