ObservedObject

The @ObservedObject does not bind the ObservableObject to the view where it is defined. That means that when the changes a value in one view, it is going to be propagated between the views as well.

Here is the code to make views with the shared state.

import SwiftUIpublic class ContentViewModel: ObservableObject {
@Published var value: String = ""
}
struct ContentView: View {

@ObservedObject var viewModel: ContentViewModel = ContentViewModel()

var body: some View {
TextField("Value", text: $viewModel.value)
.padding()
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
}

StateObject

The @StateObject is binded…


These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn what are arrays in programming in this article.

Array

An array is a special type of variable that can hold multiple values.

Imagine you need to store a list of values but you don’t know how many values exactly it is because those values might be coming from a user or other sources of data. That means you cannot dynamically create multiple variables to hold all the values, like this:

let name1 =…


These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn how to use another fundamental building block in programming, called conditional statements (a.k.a if/else branches).

Conditional (if/else) Statements

The if/else statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed. The if/else statement is a part of JavaScript’s “Conditional” Statements, which are used to perform different actions based on different conditions.
W3Schools

Syntax

There are three ways to define if/else branches.

“If” or nothing


These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn what is a boolean variable and how to work with it in this article.

Boolean variables

Boolean variables can be assigned only one of these two values: true or false.

<script>
let amIAmazing = true
console.log(amIAmazing)
let isThisFailing = false
console.log(isThisFailing)
</script>

Evaluating values

The logic of a program is often driven by a comparison of a value to another value and then deciding what to do in case the result is true or false.

For…


These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn various ways to define and work with string variables in this article.

Text/String variables

Text variables are called string variables in programming. String and text are used interchangeably from now on because they are the same thing. Learn more about the strings on Wikipedia.

The text variables are used a lot in programming and there are few ways to define them:

  1. Quotes symbol, let name = "Jimmy"
  2. Apostrophe, let name = 'Jimmy'
  3. Backtick a.k.a…

These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn how to define and work with numeric variables.

Numeric variables

The numeric variables can be whole numbers or decimal numbers. Let’s define a whole number and print out the value into the web browser console.

let age = 24
console.log(age)

Here it is, put it into VS Code and displayed in a web browser console.

You can define a variable with a decimal value in the same way. Just add the decimal part to…


These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn what are the primitive types in Javascript.

Variable Types

There is a couple of primitive types in JavaScript. The main primitive types in JavaScript are:

  • undefined — indicates that value is not provided, so the type cannot be identified
  • number — a type of variable stores a whole or decimal number
  • text —a type of variable stores a string value
  • boolean — type of variable stores true or false values

The primitive types are…


These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn all the ways to define variables.

All the code examples in this article need to be put into <script></script> tag in order to be executable, as we did in previous articles. For conciseness, some code samples omit the script tag.

Define a variable and assign a value later on

You have learned that you don’t have to define variables immediately in the previous article. Let’s remind that a variable can define and used later.

let numberA
numberA = 100

Define a variable and assign a value on a single row

It is…


These JavaScript articles are written for people who are interested in coding and are meant to provide an introduction to the programming world.

You are going to learn why and when you should use variables.

Why and when to use variables

Let’s start with a generic statement about variables: “We want to define a variable and set a value into a variable whenever we need to keep that value, so we can use it later on”.

It is tricky to understand this statement because it is too generic. Continue reading and when you are done with this chapter, come back and read the statement again. …

Ondrej Kvasnovsky

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store