# TabView

```swift
// Tab geçişlerinin gerçekleştiğini gözlemlemek için
// bir dummy view oluşturalım.
struct SampleTabView: View {
    
    let title: String
    
    var body: some View {
        Text(title)
    }
    
}

struct TabContainerView: View {
    var body: some View {
        TabView {
        
            SampleTabView(title: "Tab - 1")
                .tabItem {
                    Image(systemName: "1.circle.fill")
                    Text("Tab-1").bold()
                }
            
            SampleTabView(title: "Tab - 2")
                .tabItem {
                    Image(systemName: "2.circle.fill")
                    Text("Tab-2").bold()
                }
            
            SampleTabView(title: "Tab - 3")
                .tabItem {
                    Image(systemName: "3.circle.fill")
                    Text("Tab-3").bold()
                }
        }
    }
}
```

![](/files/-M5vLabAo76eBh65d4wO)

**tabItem** düzenleyicisini kullandığımızda `Image` ve `Text` bileşenlerini bizim için otomatik olarak yerleştirir.

#### Ekstra

Sekmeler (Tab (View)) arasında **@EnvironmentObject** kullanarak veri paylaşımı yapabiliriz.

```swift
// Demo için bir dummy class oluşturalım.
class User: Identifiable, Codable {
    var id = UUID()
    var name = ""
}

// EnvironmentObject
class UserService: ObservableObject {
    @Published var users: [User]

    init () {
        self.users = []
    }
}

struct TabContainerView: View {
    var userService = UserService()
    
    var body some: View {
        SampleTabView { .. }
            .environmentObject(userService)
            // Paylaşmak istediğimiz veriyi
            // Bu senaryoda UserService, bu şekilde environmentObject'e
            // argüman olarak geçiyoruz.
    }
}

// Tab View
struct SampleTabView: View {
    @EnvironmentObject var userService: UserService
    // Tab View içinde de bu şekilde, referans olarak geçtiğimiz
    // UserService'e tekrar erişebiliriz.
    
    var body: some View { .. }
}
```

`@EnvironmentObject` kullandığımız zaman SwiftUI, `View` oluşturulduğunda bu o objenin de hazır olduğuna emin oluyor


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://eneskaraosman53.gitbook.io/swiftui/ui-components/tabview.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
