SwiftBySundell | Code samples from the Swift by Sundell website & podcast | Audio Utils library
kandi X-RAY | SwiftBySundell Summary
kandi X-RAY | SwiftBySundell Summary
Code samples from the Swift by Sundell website & podcast.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of SwiftBySundell
SwiftBySundell Key Features
SwiftBySundell Examples and Code Snippets
Community Discussions
Trending Discussions on SwiftBySundell
QUESTION
I would appreciate help with SwiftUI bindable lists. I read the following article and tried it on my app but I'm getting errors. https://www.swiftbysundell.com/articles/bindable-swiftui-list-elements/
First, the following View including the non-bindable ordinary ForEach list works fine without any errors
...ANSWER
Answered 2022-Apr-04 at 08:33ForEach($notificationsViewModel.notifications?.notificationsDetails ?? [NotificationsDetail]()
QUESTION
I am adding the possibility to swipe in order to update a barchart. What I want to show is statistics for different station. To view different station I want the user to be able to swipe between the stations. I can see that the swiping works and each time I swipe I get the correct data from my controller. The problem is that my view is not redrawn properly.
I found this guide, but cannot make it work.
Say I swipe right from station 0 with data [100, 100, 100]
to station 2, the retrieved data from my controller is [0.0, 100.0, 0.0]
. The view I have still is for [
100, 100, 100]`.
The station number is correctly updated, so I suspect it needs some state somehow.
Here is the code:
...ANSWER
Answered 2022-Jan-23 at 10:43I don’t use SwiftUICharts so I can’t test it, but the least you can try is manually set the id to the view
QUESTION
I am trying to acquaint myself with unit testing some view models in SwiftUI. The view model currently has two @Published
boolean values that publish changes when an underlying UserDefaults
property changes. For my unit tests, I have followed this guide on how to setup UserDefaults
for testing so my production values are not modified. I am able to test the default value as such:
ANSWER
Answered 2022-Jan-22 at 16:07Let's say you store a flag in UserDefaults
to know whether the user has completed onboarding:
QUESTION
I have a container view defined like this (according to https://www.swiftbysundell.com/tips/creating-custom-swiftui-container-views/):
...ANSWER
Answered 2021-Sep-08 at 11:38Here are possible variants of initializers
QUESTION
I have an AsyncContentView
that handles the loading of data when the view appears and handles the switching of a loading view and the content (Taken from here swiftbysundell):
ANSWER
Answered 2021-Aug-17 at 12:06You can do it in onAppear
of generated content, but I suppose it is better to do it not directly but via binding (which is like a reference to state's external storage), like
QUESTION
Based off of this question: SwiftUI - Drawing (curved) paths between views
I draw the needed views and paths using the GeometryReader
. The problem is, now it becomes too long for the screen to show it all (there are 15 such views but you can only see 6 here):
So ... I add a ScrollView
to the whole thing. Outside the GeometryReader
because otherwise all views are misplaced. Here is the code:
ANSWER
Answered 2021-Aug-23 at 13:21I suggest you going out of GeometryReader
at this point, and try just use some constants.
Here I'm using UIScreen.main.bounds.size
which is device size. And my relative center y
is not limited to 0..1
anymore: because we have more items than one screen. Not sure if you need that in your app or you could just use static values for y
distance.
Now to the size calculations. Path
doesn't act like any other view, it not taking space of its content(in this case points to draw), because you may draw points with location less than zero and more that you need to actually draw.
To apply height
modifier to Path
I've created heightToFit
extension: it receives method which will draw Path
(stroke/fill/etc), and after drawing applying height
modifier equal to boundingRect.maxY
which is bottom point of drawn path
QUESTION
I am trying to create a list view and a detailed screen like this:
...ANSWER
Answered 2021-Aug-07 at 10:18I think you should think about a minor restructure of your code, and use only 1 @StateObject/ObservableObject. Here is a cut down version of your code using only one StateObject source of truth:
Note: AFAIK Binding is meant to be used in View struct not "ordinary" classes.
PS: what is identifiableIndicies?
QUESTION
I'm building an app which makes graphs and calculates some basic stuff. On the main screen, I have a ForEach loop inside a List that shows the saved charts. When entering the NavigationLink inside the List, the destination view does not correspond with the label shown (video below).
I had to use a custom ForEach extension to deal with the bindings https://www.swiftbysundell.com/articles/bindable-swiftui-list-elements/ (Apple announced that on iOS 15 ForEach will accept bindings, but I'm developing for iOS 14).
The code of the List:
...ANSWER
Answered 2021-Jun-30 at 08:54remove
QUESTION
The following Swift by Sundell article points out that in some cases is enough to make a explicit capture of a property inside the class to break the references retain cycle. This is the exact example:
...ANSWER
Answered 2021-Jun-04 at 15:42[cache] capture is still a strong reference to the ImageLoader property but doesn't retain self. And that prolongs the lifetime of just the cache object while a strong reference to cache is held by that request(url) callback block - self can be dealloced even before the callback block is done, and cache can hang around a bit longer.
You only get a retain cycle if there is a loop of strong references A->B and B->A, or A->B->C and C->A etc. Here we have A->Cache and some block that A created but then hands off to url session retains Cache. so that's not a cycle A->Cache and request(url) completion handler also -> Cache. A is free to be dealloced, meaning Cache reference count would go from 2 to 1 and still be around while the url session downloads.
QUESTION
I'm testing a class that depends on an instance of UserDefaults. In following this sample code found here, I create and setup the instance like so:
...ANSWER
Answered 2021-May-18 at 20:29Ideally, instead of passing in an actual instance of UserDefaults
, you would instead pass a different type of object that doesn't require that cleanup. A simple example would be something like:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install SwiftBySundell
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page