iOS 15: Why does SwiftUI use structs for views? – Views and Modifiers SwiftUI Tutorial 1/10

preview_player
Показать описание

Other parts in Project 3:

1. Why does SwiftUI use structs for views?: This video

Рекомендации по теме
Комментарии
Автор

I'm a big fan of your videos, Paul. Many thanks for your effort.

reinaldof
Автор

Genuine question... why does Swift limit to 10 views if structs are so small? You mention the iPhone being able to handle thousands?

NathanBudd
Автор

Hi Paul, I like what you do explaining SwiftUI in your videos, your website etc.
However your comments about OOP sound quite dramatic to me and I quote:
"classes" "smash through the constant wall"
"It can lead to a lot of messy code" etc.
Yes, you are right about the latter of course, messy code with class (reference) based programming is indeed possible... like with any other programming paradigm

For example, accessing class (instance) properties directly.
Instead, deploying getters & setters should be the only way to access these vital properties, which, of course, should be confined to their class or the class's hierarchy by defining these properties as private or protected. By using Setters, a class has complete control over what goes in, what it might mutate - not only for the contents of the value in question, but also with respect to the complete environment within that specific class. Yes, classes can be "intelligent things" which is cool.

The above example illustrates not really knowing how to use Object Oriented Design & Programming techniques properly.. Similar - but the other way around - it would happen to me if I had to switch quite suddenly from Object Oriented Programming to the Function Programming paradigm. My code in FP would for some months be awful, because this is a whole different way of programming than what I am used to.

Classes are "Intelligent things that grow out of control" ? you'd say?
If the use of classes would "grow out of control" then there is probably something wrong or at least neglected in the design of an app, framework or system.
All I know is, that OODP has proven itself for decades. Most applications today are made with it and most of those apps are of good quality.

About performance issues, Structs vs. Classes. True, class instances are stored on the heap and only accessible with indirect addressing. Structs are mostly pushed on the stack.
In any case, we are talking microseconds here, . Comparing a GUI made with UIKit and one made with
SwiftUI users would hardly notice the difference. Especially today, because processors have become
incredibly fast.

I make my apps completely with classes. Reference type programming, Because less copying (structs are value types) takes place it might even be that the using classes based reference programming is faster. To me this is more reliable because throughout the app I am always referring to one and the same object.
Some nuance would be nice.
Thank you, kind regards
Ted

tedvga
Автор

my comment about the pros and cons about SwiftUI vs UIkit is (as yet) not visible.. why?

tedvga