Dual Purpose Form and FocusState in SwiftUI

  Рет қаралды 2,687

Stewart Lynch

Stewart Lynch

Күн бұрын

Пікірлер: 34
@Chris_Viarengo
@Chris_Viarengo Ай бұрын
You mentioned that you follow the accounts of several developers on X (Twitter) that are "a lot smarter" than you. Stewart, I don't think you give yourself enough credit. You're an incredibly knowledgeable developer and an outstanding teacher. Thank you for all you do for the community!
@mhfs61
@mhfs61 2 жыл бұрын
I didn’t know that one can conditionally call a function in a button. I’d defined two computed properties displaying a button an then conditionally displayed either one of them. Your solution is more compact. Love it.
@miketurner7152
@miketurner7152 2 жыл бұрын
Perfect timing. I am currently working on a project with forms and I was trying to figure out the best way to display new and update views to modify my record. I will definitely use what I learned from your video in my project. Thanks Stewart!
@StewartLynch
@StewartLynch 2 жыл бұрын
Glad it can help you Mike.
@brucknerdevilliers
@brucknerdevilliers Жыл бұрын
Clever stuff! I couldn't get the keyboard SF symbol to display, except by deleting the Spacer in FormView. Not sure why. Updated the code for the deprecated NavigationView for NavigationStack by changing the Minimum Deployment to iOS16.2. With these two small changes you have a new iOS 16 video!
@erdogancete
@erdogancete Жыл бұрын
Another great video. thank you for putting effort to record such informative videos.
@kenturnbull9679
@kenturnbull9679 2 жыл бұрын
Very informative and useful tutorial. Can't wait to give it a workout.
@kenturnbull9679
@kenturnbull9679 3 ай бұрын
Just tried it again and swapped out the Edit Button for .onTapGesture ; seems to work fine. Any concerns or cautions about the change??
@gakkieNL
@gakkieNL Жыл бұрын
Like this approach ! Thanks!
@StewartLynch
@StewartLynch Жыл бұрын
You are welcome!
@jordibruin
@jordibruin 2 жыл бұрын
Great video Stewart, thanks for the clear instructions!
@StewartLynch
@StewartLynch 2 жыл бұрын
Thanks Jordan.
@w0mblemania
@w0mblemania 2 жыл бұрын
Excellent video Stewart, thanks. Question: in FormView, shouldn't 'viewModel' be an @ObservedObject, instead of a @StateObject,? (Because the FormView does not instantiate the 'viewModel'). Cheers.
@StewartLynch
@StewartLynch 2 жыл бұрын
You know, I think you are correct here. The enum instantiates the viewModel so it should be an ObservedObject in FormView. Good catch
@chrisstromberg6527
@chrisstromberg6527 Жыл бұрын
Another awesome video! Stuart could you do a series on working with SwiftRealm and MVVM?
@StewartLynch
@StewartLynch Жыл бұрын
I do have videos on using Realm and I believe that I use a modified MVVM pattern on the last video. Have you seen those videos Chris? Thanks for the boost?
@chrisstromberg6527
@chrisstromberg6527 Жыл бұрын
@@StewartLynch I totally missed that you had videos on realm. I'm currently working on developing an app using RealmSwift and the Atlas App Sync feature. Thanks again for all of the great content and excellent explanations!
@paulberghege
@paulberghege Жыл бұрын
Ooh, me likey this generic solution :) Nice. Thx
@StewartLynch
@StewartLynch Жыл бұрын
Glad you like it!
@SentimentalMo
@SentimentalMo Жыл бұрын
It's no longer necessary to delay to focus assignment on appear. You can now assign focus in onAppear immediately
@tsbob7847
@tsbob7847 2 жыл бұрын
Very helpful. Somewhat related topic suggestion: app structure for separate view models per view and view model(s) for each model (store). Trying to move beyond a single view model for the whole app. Feel like your FormViewModel with injected Store is on the path but I don’t see the overall picture. Thanks again.
@StewartLynch
@StewartLynch 2 жыл бұрын
I don’t necessarily feel that every view needs a view model but I get what you are saying. I am not a strict MVVM guy.
@tsbob7847
@tsbob7847 2 жыл бұрын
@@StewartLynch Agree, extremes are rarely a good choice (in life as well). But when appropriate, what is the recommended approach? I’ve seen a few videos and articles on this but usually for API calls rather than a local store that needs to be handed down to child views where properties will be changed. Can’t create another instance of the store and Singletons are cautioned against. The articles assume you know how to do the dependency injection but injecting into StateObject, Binding, etc. isn’t explained. Perhaps too specific but seems like a next level type topic that I’ve found so helpful from you. Anyway, thanks for all you’ve done and enjoy WWDC!
@StewartLynch
@StewartLynch 2 жыл бұрын
@@tsbob7847 EnvironmentObject are ObservableObjects and great for those cases where you need to have code available in multiple views. No need to do injections from one view to another. You can have more than one EnvironmentObject
@tsbob7847
@tsbob7847 2 жыл бұрын
@@StewartLynch I can create a model store class at the app level and place into the environment. That is easily available in all the views but isn’t available when the child view goes to create its own view model. The view model class doesn’t appear to have access to the environment. So how does the child view’s view model get the model store? Most MVVM tutorials stop at one real view so they just create and hold the store in the single VM but how do you get access to that store further down the view chain? I’ve created the child view model in the parent and injected the store there just before calling the child view but that seems awkward. Sorry for the long question and the awkward MVVM terms but I’ve done a fair amount of searching without finding a solid answer.
@StewartLynch
@StewartLynch 2 жыл бұрын
When working with an environmentObject I create an optional property in the ObservableObject viewModel class of the type that is what my Environment Object is. I then create a function that is called setup with an argument of that type and then assign the argument received to that optional property in the function body. In the view that is using that viewModel,, in onAppear, I call the viewModel’s setupFunction and pass in the environment object so that my viewModel now has access to all of the environment objects properties and functions.
@holycrosscv
@holycrosscv 2 жыл бұрын
Another VERY fine video! The FormType selection is brilliant! IntersIntersting with Xcode 14, a Spacer() in the HStack with the Keyboard dismiss button hides the butThe code Code still runs, but nothing on the screen. Remove the Spacer, and there it is! Weird. I created a test project to replicate the behavior, something. It must be a bug. Thanks Again!
@StewartLynch
@StewartLynch 2 жыл бұрын
I noticed this too Mark. Just remove the HStack and you should be fine too. I have reported it as a bug, but it maybe a feature :)
@omidrostami2208
@omidrostami2208 2 жыл бұрын
I know that you made a good video about creating status bar menus and icon for macOS app in SwiftUI, like putting app icon in macOS title, but I cannot find that video! could you show the link of that video? thanks
@StewartLynch
@StewartLynch 2 жыл бұрын
I did that for the Code With Chris Channel. kzbin.info/www/bejne/eaawfaOkn7WlaLs
@judy8821
@judy8821 2 жыл бұрын
Awesome
@mhfs61
@mhfs61 2 жыл бұрын
👍🏼👍🏼👍🏼
@ColeDano
@ColeDano 2 жыл бұрын
Your videos have been incredibly helpful Stewart. It looks like .onAppear with FocusState is working now, as I didn't need to set the delay to get it to work when adding a new contact. I guess to make up for it, it looks like the spacer doesn't work to push the dismiss keyboard icon over, it looks like it's being pushed offscreen as it's not visible.
Create custom Bindings in SwiftUI | Advanced Learning #27
30:41
Swiftful Thinking
Рет қаралды 5 М.
НАШЛА ДЕНЬГИ🙀@VERONIKAborsch
00:38
МишАня
Рет қаралды 2,7 МЛН
Smart Sigma Kid #funny #sigma
00:14
CRAZY GREAPA
Рет қаралды 24 МЛН
龟兔赛跑:好可爱的小乌龟#short #angel #clown
01:00
Super Beauty team
Рет қаралды 46 МЛН
Xcode Frameworks and Workspaces
19:20
Stewart Lynch
Рет қаралды 2,4 М.
Deep Dive into TabView Changes in iOS18
32:07
Stewart Lynch
Рет қаралды 2,5 М.
Build a Two-Factor Authentication System with React in 90 Minutes
1:31:33
Beginner's Guide to the Bash Terminal
1:14:37
Joe Collins (EzeeLinux)
Рет қаралды 2,3 МЛН
How to use @FocusState in SwiftUI | Bootcamp #60
16:28
Swiftful Thinking
Рет қаралды 18 М.
Getting the MOST out of Xcode 16
24:52
Stewart Lynch
Рет қаралды 4,9 М.
Xcode templates, projects, targets, schemes and workspaces
24:42
Stewart Lynch
Рет қаралды 4,1 М.
Creator of git, Linus Torvalds Presents the Fundamentals of git
1:10:15
Developers Alliance
Рет қаралды 117 М.
НАШЛА ДЕНЬГИ🙀@VERONIKAborsch
00:38
МишАня
Рет қаралды 2,7 МЛН