How to declare a scope in code ?

Code Block
//
//  GegeApp.swift
//  Gege
//
//  Created by Besleaga Alexandru Marian on 5/15/21.
//
import SwiftUI
@main
struct GegeApp: App {
    var body: some Scene {
        WindowGroup {
            Text("Besleaga Alexandru Marian")
        }
        #if os(macOS)
                Settings {
                    SettingsView()
                }
        #endif
    }
}
struct GeneralSettingsView: View {
    @AppStorage("showPreview") private var showPreview = true
    @AppStorage("fontSize") private var fontSize = 12.0
    var body: some View {
        Form {
            Toggle("Show Previews", isOn: $showPreview)
            Slider(value: $fontSize, in: 9...96) {
                Text("Font Size (\(fontSize, specifier: "%.0f") pts)")
            }
        }
        .padding(20)
        .frame(width: 350, height: 100)
    }
}
struct SettingsView: View {
    private enum Tabs: Hashable {
        case general, advanced
    }
    var body: some View {
        TabView {
            GeneralSettingsView()
                .tabItem {
                    Label("General", systemImage: "gear")
                }
                .tag(Tabs.general)
            `AdvancedSettingsView()`
                .tabItem {
                    Label("Advanced", systemImage: "star")
                }
                .tag(Tabs.advanced)
        }
        .padding(20)
        .frame(width: 375, height: 150)
    }
}


Cannot find AdvancedSettingsView in scope ?

Cannot find AdvancedSettingsView in scope ?

As already said in another thread of yours, the scope for type names is usually whole your project.

You may need to add AdvancedSettingsView.swift into your project and write the right definition of AdvancedSettingsView in it.
Please be careful about spellings.
Which version of Xcode ? Which version of MacOS ?

AdvancedSettingsView is only available for MacOS 11.0 +

It seems you copied this code:
https://developer.apple.com/documentation/swiftui/settings?changes=l_3_7

But it is different:
Code Block
var body: some View {
TabView {
GeneralSettingsView()
.tabItem {
Label("General", systemImage: "gear")
}
.tag(Tabs.general)
AdvancedSettingsView()
.tabItem {
Label("Advanced", systemImage: "star")
}
.tag(Tabs.advanced)
}


They do not show it, but they have to define
Code Block
struct AdvancedSettingsView: View {
}

as they defined
Code Block
struct GeneralSettingsView: View { }



There is not other method to declare the scope beside creating a new SwiftUI view file ?

Kind Regards

There is not other method to declare the scope beside creating a new SwiftUI view file ?

Correct. The scope is defined by the definitions. You can add AdvancedSettingsView in the same file if you prefer.
But anyway, you need a definition of AdvancedSettingsView somewhere in your project.

There is not other method to declare the scope beside creating a new SwiftUI view file ?

Your wording is confusing.
You do not declare a scope, you declare something and depending where and how, that defines its visibility scope.

Problem you had here was that the declaration was just missing, hence AdvancedSettingsView could not be found in the scope where you tried to use.

Note that you can limit scope of visibility, with attributes as private, fileprivate.
My issue is the following : "I want to program a function and I receive a 'scope' error". How do I declare a scope and were in my programming code to allow the variable to function in accordance with the iOS Mobile App that I want to develop these year ?

My issue is the following : "I want to program a function and I receive a 'scope' error". How do I declare a scope and were in my programming code to allow the variable to function in accordance with the iOS Mobile App that I want to develop these year ?

As already said, scope is not something you define. Ignore the word scope in the error message and find what you need to define.
What you need to do is described in the other parts than scope in the error message.

If you get Cannot find AdvancedSettingsView in scope, it is AdvancedSettingsView that you need to define, not scope.
How do I #define
Code Block
AdvancedSettingsView
in my code ?

"I want to program a function and I receive a 'scope' error". How do I declare a scope

Just declare the property (which has the scope problem), in another place, for instance at the class level, not inside a func.
If so, take care not to redeclare a property with the same name in the func.

"I want to program a function and I receive a 'scope' error".

Please also show the func and where you get the error message.

To define AdvancedSettingsView, just do like any other SwiftUI View
Code Block
struct AdvancedSettingsView: View {
var body: some View {
Text("Hello")
}
}


Thank you for your answers.

How do I #define 

Code Block
AdvancedSettingsView

in my code ?
It depends on what sort of View you want to show.
Codes shown in reference are intended show outlines of the usage, they are often not complete as c&p ready.

If you cannot fill in the missing parts, you should better not copy codes in some reference, but better find a good tutorial.
@BesleagaMAlexandru1991
Does it work now ?

If so, don't forget to close the thread by marking the correct answer.
How to declare a scope in code ?
 
 
Q