0Pricing
SwiftUI Academy · Ders

@State Özelliklerini Bildirme

Değiştirilebilir görünüme özgü verileri tutmak için @State ekleyin.

@State Özelliklerini Bildirme, CoddyKit'te ücretsiz bir SwiftUI Academy dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, SwiftUI Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. SwiftUI Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Meet the @State Wrapper

You declare mutable view-local data by marking a property with @State. This property wrapper tells SwiftUI to store and watch the value for you. 🏷️

@State private var count = 0

Always Give It a Default

A @State property needs an initial value right where you declare it. SwiftUI uses it to create the storage the first time the view appears.

@State private var isOn = false

Mark It private

State belongs to one view, so declare it private. This signals that no outside code should reach in and set it directly, keeping ownership clear.

@State private var name = ""

Reading the Value

Read a @State property like any normal variable. Just use its name in body and SwiftUI tracks that this view depends on it.

Text("You tapped \(count) times")

Writing the Value

You can mutate a @State property even though the view is a struct. Assign to it from an action and SwiftUI schedules a redraw automatically.

Button("Add") { count += 1 }

It Persists Across Redraws

SwiftUI keeps the @State value alive across the many times the view body is recomputed. Your count won't reset just because the view redrew.

Putting It Together

Declare state, read it in the body, and mutate it from a button. That is the full loop that powers most simple interactions.

struct CounterView: View {
    @State private var count = 0
    var body: some View {
        Button("Count \(count)") { count += 1 }
    }
}

Use Simple Value Types

@State works best with value types like Int, Bool, String, or small structs. For shared objects you'll later reach for other tools, but values are the norm here.

One Owner Per Property

The view that declares @State is its owner. Other views can receive access, but only one view should hold the original state for a given value.

Don't Overuse It

Reach for @State only when a value truly changes while the view is on screen. Constant labels and passed-in data don't need it.

Naming for Clarity

Name state for what it represents, like isLoading or selectedTab. Clear names make the data flow obvious to anyone reading the view.

Quick Check

Which line correctly declares a private piece of view-local state?

Recap

Declare changing view data with @State, give it a default, and keep it private. Read it freely in body and mutate it from actions to trigger redraws. ✅

Sıkça Sorulan Sorular

“@State Özelliklerini Bildirme” dersi ücretsiz mi?

Evet — “@State Özelliklerini Bildirme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve SwiftUI Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. SwiftUI Academy kursu toplamda 4 dersten oluşur.

“@State Özelliklerini Bildirme” dersinde ne öğreneceğim?

Değiştirilebilir görünüme özgü verileri tutmak için @State ekleyin. SwiftUI Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

SwiftUI Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te SwiftUI Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.

“@State Özelliklerini Bildirme” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu SwiftUI Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her SwiftUI Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Görünümler Neden Durum Gerektirir?
  2. @State Özelliklerini Bildirme
  3. Dokunma Sayacı Oluşturma
  4. Durumla Görünürlüğü Değiştirme
← SwiftUI Academy Sayfasına Dön