Swift for Beginners Part 2: Variables & Constants

preview_player
Показать описание
iOS Academy offers the #1 course for iOS Development for Beginners. Learn to create iPhone and iPad apps from scratch. Everyone these days has an app idea; learn the important skill of making those apps, make yourself more marketable, change industries to get a different job, and enjoy the ride!
Рекомендации по теме
Комментарии
Автор

For anyone who doesn’t understand what a static is, he might explain it better in the following videos however I guess I’ll try myself from what I gathered in this video, I might be wrong myself though…

When you create a class it is essentially considered a data type, it can contain many other variables and constants of different types inside of itself, this could be useful for example with students, you may want to have multiple students represented in one program and each of those students should maybe have a name, age and grade.

This however can create optimization problems, because lets say all the students are from the same grade and have the same age, then it just becomes wasteful to put it inside the class because if there was 12 students the computer would create 12 student age variables when really all you need is one, since everyone has the same age.

By using the keyword static you’re basically telling the computer just create this element once, and have all of the students share this one element.

This can be practical to help with ram management since now instead of having 12 elements who store the same data you just have 1.

NXGen
Автор

I suggest that you start with variables and constants because they are easy to grasp and wait to explain static when you go through classes.

hamdymubarak
Автор

I've been coding for 7 or so years now and none of these concepts are new to me but like holy shit, this guy needs to take a lesson on teaching because I feel for anyone trying to learn these concepts for the first time here.

variable: same as any other language. assign a name to a value. the value can be a integer, floating point, string, boolean, etc and can be manipulated in classes, function, or just in other lines of code in the global context.

constant: a variable that cannot change value. when creating a global constant you are defining something that cannot be manipulated by other functions accidentally. the confusing part is creating a constant value inside of classes because even though you are creating one constant, each instance of that class will create a new constant specific to that instance.

static: a variable where you can access the value of it without creating an instance of that class. for example, let's create a class for an orange.

class orange {
static var color = "orange"
var numberOfSeeds = 0
}

to get the numberOfSeeds value I would need to create a new orange class and then get that value

var myOrange = orange()
print(myOrange.numberOfSeeds)

but if I just want to know the color of these oranges because I know they are all going to be the same then I can just do this:

print(orange.color)

nicholaskorte
Автор

For anyone in an introductory C++ course like me, think of static in a similar vain as the static.cast<type> operation, where you’re only temporarily casting a variable to a certain data type for the sake of whatever operation you’re performing

It’s static because we’re not explicitly changing the data type of the whole variable, just in that one instance

Now that’s just how I understood static variables, I know there’s way more that goes into it but that one idea let me grasp it enough to learn more

andreerna
Автор

static : owned by class
contants: owned by instance

chart_are_trustworthy
Автор

You should have left the explaination of static later with the class object lesson

elekal-bazi
Автор

Variables and constants explanations were clear. I came away a bit confused on the concept of a static.

darrylthomas
Автор

The title says it’s for beginners then in 20 minutes we learning Static. Even intermediate users find it difficult to grasp without knowing the class.

saidul
Автор

I understood this because I code in python but for someone with no programming experience it probably would have been a lot at once

XwitterEye
Автор

Started learning Swift 1 week ago. Was "playing" in Playgrounds and now I came here.
It is really thankful and I am grateful!
However, I too don't understand clearly what static is. Will go on with the videos and hope it will clear it out.
Cheers!

rezobachi
Автор

i think people need to understand you are not going to understand everything unless you watch the video multiple times and progress on the learning. A wrecking ball sitting around does not seem like it makes sense but once you put in on a string attached to a crane it makes sense. So this video all you learned was the ball. in later videos youll learn the crane and string

ajfernandez
Автор

You might want to redo this video without static. Leave that to a video after the intro to class's since they're only in class's anyway.

johncocksmith
Автор

Thank you for your awesome content, I'll start my journey become iOS Developer by following your content

herisusanto
Автор

This is a good course overall, but the instructor is improvising and could probably do with better course planning. Also, I find the fuzzy screen magnification too difficult to read. I ended up reading the official manual instead.

stormbytes
Автор

This one was all over the place for me... too much confusion as to what does what. Beginners here, remember, no coding experience whatsoever, but I want to learn.

NTuneLabs
Автор

Noticed that in Swift, when assigning float/double variables that represent currency, a value such as $5.00 will print as $5.0 and a Value without the double zero ($5.01) will print as $5.01. To fix, a conversion to string is required ... var string ValueString(format : %.2f). If you need to perform math, then the Float Value would have to be used and for displaying, ValueString is used. ValueString does not automatically update either. You must re assign ValueString each time Value changes if you want to print the updated value of the instance. Is there a way in Swift to use the string formatting function as the expression in print after the var declaration? ... print( ValueString = $5.00) Sorry, I could have tried this but just thought of it now. Thanks for your videos! I highly value your time and hard work in making these videos.

xy-plgg
Автор

Where can I find the playground file in the video to download?

javindahhibbert
Автор

Must agree with other comments - totally over complicated things trying to jump to statics on first lesson 😅

nmyster
Автор

Can you help me?
I didn't understand static.
Please help

CosmoFusion
Автор

love the name of the channel. it has great potential, BUT please use more real life examples of how and whys of the computer programming. It's very annoying to just don't question something and ask the students just believe. you did this for free, so it's just my feedback. Thanks for providing the video tutorials!!!!

hichewy