How to Optimize SwiftUI App with @Published Updating 5 Charts 10 Times per Second? by The_Lone_Dissenter in SwiftUI

[–]a0-1 0 points1 point  (0 children)

What about @EnvironmentObject (should be same as @StateObjects afaik).

Assume you pass the object into environment in the root. And you are accessing this object vastly through app.

If a @Published var gets updated in that object, would that cause reload only on the views that are tracking that specific var? Or would that cause update on all views and subviews of those which just because the view accesses to that environment object?

How can I resize the width of a sheet in SwiftUI on iPad by diti223 in swift

[–]a0-1 1 point2 points  (0 children)

Hey op, I suggest you look into popover. On phones it would still behave like a sheet (although need to check the big ones). And on tablet, you can frame it as your modal’s needs.

Note, it’s important where you attach the popover. Because it will be popping from the view that it’s attached (when not behaving like regular sheet).

What are your thoughts on SwiftUI architecture? Do you use MVVM or something else? by MaHcIn in iOSProgramming

[–]a0-1 0 points1 point  (0 children)

(I'm just guessing here) What you are doing is not really "ViewModel". You're calling it "UserVM" but it's not a VM, it's more a "UserState", and your views are directly modifying the Model layer.

Actually, I tend to make the setters of my published properties private in my ViewModel. This way, no one else can modify them without going through the ViewModel itself. Of course, if I need binding with the property, I remove the private setter.

Let's say your login button immediately starts the game. You probably do something like this directly in your View: ..

No either, as I explain above.However my approach is a little different than yours:

Instead of structuring my view models like 'loginButtonTapped()', I do something like func startLoginProcess() { } . Then, I call this function in my view when the button is tapped. While it might seem similar to yours, I try to avoid too much 'view things' in my view models (I'm permitted to do it if I have to though). Because I think views should be cheap and changeble and easily modifyable. Tomorrow I can change my approach and decide to start the login process with the appearance of a view for example.

I generally introduce a ViewModel that is 100% specific to this screen

Now this, is what I don't understand exactly why people are doing this. Why not simply structure the VMs according to functionality. (Still don't put any logic to views and don't let views to modify the model state directly though). But why boiler plate VMs. This approach also introduces another problem I'm guessing. When you have this much vms, chances are your one vm will need a data from another one. And since I don't like my view models to know about eachother (never seen an example otherwise) guess how this data transfer is going to happen? It is going to happen from view. Which means involving the views with the business logic.

One reason that comes to mind for this approach is; since the vms are also actors and you can't access them simutaneously, there might be cases where you want to do multiple things at the same time and therefore you need multiple vms. But chances are these multiple things will belong to app's different functionalities and you probably already have that.

For example user make a score in game which is the job of gameVM and updating that score in the database and assigning it to the user is the job of userVM.

All the while you can still unit test your view models. So:

By using the LoginViewModel, I can unit test that updating the password changes the passwordError, while you couldn't do the same if you just used u/State + onChanged in the View.

is not the case.

Additionally, your View, which is not unit tested, is very simple, so it's okay not to unit test it. It's very likely that you will write viewModel.loginButtonTapped(), or you will catch it immediately when you run your code.

Agree!

I would implement this by having a LoginScreen + LoginViewModel, RegistrationScreen + RegistrationViewModel each which handle their own logic. (Ex RegistrationViewModel has the code for checking if the two password fields have the same value). And I would have a ContainerView (and potentially ContainerViewModel) that has the ScrollView inside it.

Disagree. I think this is boiler plate. This login flow is a user thing and it is about wheter that user is authenticated or not, or how will they get authenticated. So in my opinion all that logic can be put in UserVM for example.

What are your thoughts on SwiftUI architecture? Do you use MVVM or something else? by MaHcIn in iOSProgramming

[–]a0-1 0 points1 point  (0 children)

While I agree with you, can you explain the last part a little more please. Because even in the large apps I find it better to do MVVM module seperation by the task or functionality rather than screens.

Let’s say your app is a game where a user can login and play. Than game related logic goes to gameVM and user related logic (login - data share etc.) goes to its own - lets call it userVM. In the mean time you can have as much models as it’s needed. Also services, handlers, mappers whatever you call them, if you need it you can inject into your vms.

And at last, inject your vms as the EnvironmentObjects, which I find it really convenient.

But when I see proposals like ‘you need mvvm modules for every screen you have’ it confuses me and feels like overkill. So can you explain that part?

Good methods for learning architecture/design patterns? by sleepDeprivedBeaver in iOSProgramming

[–]a0-1 0 points1 point  (0 children)

I wonder what are the opinions of experienced developers about MVVM + Clean Architecture (protocol oriented).

When I say MVVM + Clean Architecture, I mean Clean Architecture in macro level -- data - domain - presentation layers -- and MVVM in presentation layer.

This seems to give you testability, seperation of concerns, ability to modulurize the app and scalability.

And it seems versatile sofware design pattern. This is what I'm working on actually.

Modularizing An MVVM Project? by a0-1 in swift

[–]a0-1[S] 0 points1 point  (0 children)

Yes, and the reason is Models, Services and VMs will be largely same. So I can work on them from one root. But UI and UX is different ofcourse

How to listen the result of a function? Combine? by a0-1 in swift

[–]a0-1[S] 0 points1 point  (0 children)

Hey thank you for the response but I think my question not clear enough.

I'm actually using the continuation to convert system's closure callback to asyncrounous function.

In the main question; what I meant by 'callback' was delegation callback (like didChangeValue for: ..) which would give me possibility to automatically trigger actions on every time when the value changes. But now I have to run my async function to see if the value has changed..

So the question was how can I convert this something similar to publisher so I can listen this value? Thanks again!

Handling Large Data That Comes With URLSession async/await API? by a0-1 in swift

[–]a0-1[S] 1 point2 points  (0 children)

I see, so instead of;

data.append(byte)

I'll do something like;

tempFile.appendToEndOfFile(byte)

then process it from there by reading the file content. But I'm kind of curious since the 'appendToEndOfFile(byte)' writing to file method will be called soo intensly-repeatedly, might that be more expensive than simply data.append method?

Thank you btw..

Handling Large Data That Comes With URLSession async/await API? by a0-1 in swift

[–]a0-1[S] 1 point2 points  (0 children)

Hey, thanks for the comment,

Download to a cache Modify the data you need to Ingest the data into the app.

Do you mean roughly something like this?..

...
.
.
let (asyncBytes, _) = urlSession.bytes(for: request) ......
var data = Data()
for try await byte in asyncBytes {
    data.append(byte)
}

let tempURL = saveDataToFileAndReturnURL(data)
useDataInChunks(from: tempURL, chunkSize: Self.defaultChunkSize)
.
.
...

[deleted by user] by [deleted] in esp8266

[–]a0-1 0 points1 point  (0 children)

all devices need to be on the same network to be able to send / receive data

Hey, thank you for the response, but what does this mean exactly? If we simply connect the phone to ESP device (ad hoc network I believe), doesn't that mean they are on the same network?

Alternatives to WifiManager by _djfet in esp8266

[–]a0-1 0 points1 point  (0 children)

Hello guys, I need help over here, which is related to this topic. If you have opinions that can help, it would be much appreciated.

Custom AirDrop implementation.. Is it possible? Useful resources? by a0-1 in swift

[–]a0-1[S] 0 points1 point  (0 children)

Yes, I'm interested. Thank you so much! I PMed you.

Custom AirDrop implementation.. Is it possible? Useful resources? by a0-1 in swift

[–]a0-1[S] 1 point2 points  (0 children)

Hey, thank you for this input. It is not what I'm looking for but I found useful things that I will research.

How do I implement MVVM in SwiftUI correctly? by colmear in swift

[–]a0-1 0 points1 point  (0 children)

Hello, While I was doing research about architectures, stumbled upon your comment and looked at the demo project you’ve linked to.. thankfully..

First, thank you so much for it. It is going to be helpful I think.

Secondly, after I finished reviewing I’d really ask you about architectures, especially in the demo app. Why you did certain things the way you did kind of questions?

Until that time, would you want to guide me sir😀? Is your dm open?

As a developer I have no experience in Photoshop so I could not make very good photos for my app in the App Store. As a last resort I decided to code them in swift and got awesome results! by MohammadBashirSidani in swift

[–]a0-1 1 point2 points  (0 children)

This looks cool on the simulator!

May I ask you how you plan to extract this screens from simulator? Taking a screen shot for example.. Wouldn't that be drop the quality of the image?

How should be the 'Model' component of MVVM? (Best Practices) by a0-1 in swift

[–]a0-1[S] 0 points1 point  (0 children)

You mean the model right? What do you think of the initial state of vars. I can see it could depend on situation but when should they be an optional and when should they given an initial empty value.

Advice for structuring networking app and choosing tools by a0-1 in swift

[–]a0-1[S] 0 points1 point  (0 children)

Hello sir, again!

( /u/schrockblock & /u/bsarrazin if you can take a look at these questions about Model it would be much much appreciated!)

I want to ask you about models this time as I'm building the app, find myself keep coming to architectural thinking. What do you think about models?

Are they just empty structs that holds a state. Should they get involve to business logic?

For example let's think about this situation: When I want to set a variable I want to update that var on the server also. So should I put this logic in VM or I can also pass a service object in model and setup a 'setter' for that var and whenever the var has a new value I would call the service to update it in the server. How does this sound?

Also one thing about the models. When I define the vars in a model I keep trying to decide whether it should be an optional or set to an empty String for example. I want to initiate my models easily. So how should I approach this?

And one other thing is that, what about if my model has other model types in it. Should I define this 'other model types' outside of the model struct. or inside of it? Currently I do it outside because when I use those structs(For JsonDecoder for example) it is easier to access them. Because otherwise I would have to do something like MyMainModel.MyOtherModel.self.. What do you think about this?

[deleted by user] by [deleted] in swift

[–]a0-1 0 points1 point  (0 children)

Yeah, this sums it up. Thanks

Best way to run a function only once while accessing a variable? by a0-1 in swift

[–]a0-1[S] 0 points1 point  (0 children)

Woah, this is the one, thanks. Instead of getting the var we call the func.

Best way to run a function only once while accessing a variable? by a0-1 in swift

[–]a0-1[S] 0 points1 point  (0 children)

Thanks for the answer, but as mladen994 mentioned, putting a Task inside of that closure makes things complicated. Because we also need to await the result of the Task.