# SwiftUI State | raywenderlich.com

**URL:** <https://forums.kodeco.com/t/swiftui-state-raywenderlich-com/129340>\
**Category:** 🎓 Courses & Articles\
**Created:** [January 5, 2021, 6:48pm UTC](https://forums.kodeco.com/t/swiftui-state-raywenderlich-com/129340 "2021-01-05T18:48:56Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![rwenderlich](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rwenderlich/32/108604_2.png) [@rwenderlich](https://forums.kodeco.com/u/rwenderlich)\
**Post date:** [January 5, 2021, 6:48pm UTC](https://forums.kodeco.com/t/swiftui-state-raywenderlich-com/129340/1 "2021-01-05T18:48:56Z")

</div>

* * *
This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/17493408-your-first-ios-and-swiftui-app-an-app-from-scratch/lessons/12](https://www.raywenderlich.com/17493408-your-first-ios-and-swiftui-app-an-app-from-scratch/lessons/12)

---

<div class="post-metadata">

**Author:** ![tseplyaev](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tseplyaev/32/81494_2.png) [@tseplyaev](https://forums.kodeco.com/u/tseplyaev)\
**Post date:** [February 22, 2021, 4:13am UTC](https://forums.kodeco.com/t/swiftui-state-raywenderlich-com/129340/3 "2021-02-22T04:13:07Z")

</div>

Hi!

This is the first theme at this course, that I don’t understand at all. Could you give some links to read more about SwiftUI State.

---

<div class="post-metadata">

**Author:** ![rwenderlich](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rwenderlich/32/108604_2.png) [@rwenderlich](https://forums.kodeco.com/u/rwenderlich)\
**Post date:** [February 23, 2021, 9:20pm UTC](https://forums.kodeco.com/t/swiftui-state-raywenderlich-com/129340/4 "2021-02-23T21:20:04Z")

</div>

Sorry if things weren’t quite clear here! Here are a few other resources that may be helpful:

[https://www.raywenderlich.com/books/swiftui-by-tutorials/v2.0/chapters/9-state-data-flow](https://www.raywenderlich.com/books/swiftui-by-tutorials/v2.0/chapters/9-state-data-flow)

[https://www.raywenderlich.com/3967613-swift-ui-working-with-state](https://www.raywenderlich.com/3967613-swift-ui-working-with-state)

Also, we are working on a brand new book that is coming out later this year called the **SwiftUI Apprrentice** , which will cover all aspects of SwiftUI from a complete beginner perspective, so be sure to stay tuned for that!

---

<div class="post-metadata">

**Author:** ![tylerturnbull](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tylerturnbull/32/102075_2.png) [@tylerturnbull](https://forums.kodeco.com/u/tylerturnbull)\
**Post date:** [May 2, 2021, 5:24pm UTC](https://forums.kodeco.com/t/swiftui-state-raywenderlich-com/129340/5 "2021-05-02T17:24:55Z")

</div>

```
self.alertIsVisibile = true

```

is `self` just a general practice or preference here ? Coming from Android and we don’t use `this` in similar cases. Seems to work the same without `self` so wondering why and/or when we should use it.

---

<div class="post-metadata">

**Author:** ![rwenderlich](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rwenderlich/32/108604_2.png) [@rwenderlich](https://forums.kodeco.com/u/rwenderlich)\
**Post date:** [May 3, 2021, 5:12pm UTC](https://forums.kodeco.com/t/swiftui-state-raywenderlich-com/129340/6 "2021-05-03T17:12:07Z")

</div>

@tylerturnbull Good observation! To help make this easier to learn, at the beginning of the course, I show the “long way of doing things” by typing `self.xxx`. Later, in the video on [Type Inference](https://www.raywenderlich.com/17493408-your-first-ios-and-swiftui-app-an-app-from-scratch/lessons/28), I show how you can omit this (which is indeed the best practice).

---

<div class="post-metadata">

**Author:** ![wmobile15](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/wmobile15/32/81494_2.png) [@wmobile15](https://forums.kodeco.com/u/wmobile15)\
**Post date:** [August 4, 2021, 9:27pm UTC](https://forums.kodeco.com/t/swiftui-state-raywenderlich-com/129340/7 "2021-08-04T21:27:40Z")

</div>

Note for those who may have run into this like I did…

In the video, When you start adding the method that presents the popup window, he says type “alert” when you actually need to type “.alert” and then continue with the rest of the content from the video.

Normally, I would have caught this but at the time I was more listening to his instruction and looking at my screen. Oh well.

If you neglect to add that ever important . before alert, it WILL NOT throw any error messages, but the preview window will time out and when you try to run the simulator, you will get an error starting like this: [Error message: Thread 1: EXC\_BAD\_ACCESS]

It’s not obvious, but fixing the missing . resolves all of this.

---

<div class="post-metadata">

**Author:** ![omeronder](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/omeronder/32/81494_2.png) [@omeronder](https://forums.kodeco.com/u/omeronder)\
**Post date:** [September 20, 2021, 6:28am UTC](https://forums.kodeco.com/t/swiftui-state-raywenderlich-com/129340/8 "2021-09-20T06:28:12Z")

</div>

This was really helpful! I was wondering why preview section was not working, Thanks!

---

<div class="post-metadata">

**Author:** ![1bbulliard](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/1bbulliard/32/81494_2.png) [@1bbulliard](https://forums.kodeco.com/u/1bbulliard)\
**Post date:** [October 11, 2021, 2:22am UTC](https://forums.kodeco.com/t/swiftui-state-raywenderlich-com/129340/9 "2021-10-11T02:22:47Z")

</div>

It appears for the latest version of swiftui that the format of the alert presented is incorrect. There is no drop down for alerts in the format provided in the video.  
Sd be  
.alert(isPresented: $alertShown) { () → Alert in  
Alert(title: Text(“Alert Title”), message: Text(“Alert Message”), dismissButton: .default(Text(“Ok”)))  
}

---

<div class="post-metadata">

**Author:** ![curropalacios](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/curropalacios/32/81494_2.png) [@curropalacios](https://forums.kodeco.com/u/curropalacios)\
**Post date:** [October 11, 2021, 11:40pm UTC](https://forums.kodeco.com/t/swiftui-state-raywenderlich-com/129340/10 "2021-10-11T23:40:42Z")

</div>

![Captura de Pantalla 2021-10-11 a la(s) 18.32.30](https://files.chunter.kodeco.com/original/3X/6/b/6be0010921a65da2ced28561387e947551f293d4.png)

Hi! @rwenderlich could you tell us the new syntax for the .alert method Xcode suggest in using since the one used in the video pops a warning that the method will be deprecated.

---

<div class="post-metadata">

**Author:** ![rishabh997](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rishabh997/32/100022_2.png) [@rishabh997](https://forums.kodeco.com/u/rishabh997)\
**Post date:** [October 19, 2021, 1:59pm UTC](https://forums.kodeco.com/t/swiftui-state-raywenderlich-com/129340/11 "2021-10-19T13:59:07Z")

</div>

@rwenderlich yes cannot figure out the syntax little help here

---

<div class="post-metadata">

**Author:** ![jessycatterwaul](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jessycatterwaul/32/110937_2.png) [@jessycatterwaul](https://forums.kodeco.com/u/jessycatterwaul)\
**Post date:** [November 1, 2021, 7:07am UTC](https://forums.kodeco.com/t/swiftui-state-raywenderlich-com/129340/12 "2021-11-01T07:07:03Z")

</div>

SwiftUI no longer has a dedicated `Alert` type. Instead, you now create a `View` for an alert’s actions, and another for its message. There are many ways to get the necessary data to those views. Here’s a way to do it, keeping all the code in one place. (You can directly replace Ray’s alert with this.)

```swift
.alert(
  "Hello there!",
  isPresented: $alertIsVisible,
  presenting: {
    let roundedValue = Int(sliderValue.rounded())
    return (
      roundedValue,
      game.points(sliderValue: roundedValue)
    )
  } () as (roundedValue: Int, points: Int)
) { data in
  Button("Awesome!") {
    game.startNewRound(points: data.points)
  }
} message: { data in
  Text("The slider's value is \(data.roundedValue).\n" + "You scored \(data.points) points this round.")
}

```

@curropalacios
