Post

Replies

Boosts

Views

Activity

Data struct not working
Hi! I'm very new to swift and I was having an issue with using data from a data model. struct Orchard: Identifiable {     var id = UUID()     var title: String     var category: String     var year: String     var itemID: Int     var imageName: String     var bannerName: String } let orchardData: [Orchard] = [     Orchard(title: "iPhone 12", category: "iPhone", year: "2020", itemID: 1001, imageName: "iphone_12", bannerName: "iphone_12_wallpaper"),     Orchard(title: "iPhone 12 Pro", category: "iPhone", year: "2020", itemID: 1002, imageName: "iphone_12_pro", bannerName: "iphone_12_pro_wallpaper"),     Orchard(title: "iPhone 11", category: "iPhone", year: "2019", itemID: 1003, imageName: "iphone_11", bannerName: "iphone_11_wallpaper"),     Orchard(title: "iPhone 11 Pro", category: "iPhone", year: "2019", itemID: 1004, imageName: "iphone_11_pro", bannerName: "iphone_11_pro_wallpaper"),     Orchard(title: "iPhone XS", category: "iPhone", year: "2018", itemID: 1005, imageName: "iphone_xs", bannerName: "iphone_xs_wallpaper"),     Orchard(title: "iPhone SE 2nd Gen", category: "iPhone", year: "2020", itemID: 1006, imageName: "iphone_8", bannerName: "iphone_se_2_wallpaper") ] I get the error "Global 'var' declaration requires an initializer expression or an explicitly stated getter" Any help would be greatly appreciated, thanks!
6
0
859
Oct ’21
List changing into a different mode in a different view
Hello! I'm having an issue where my SwiftUI list changes into some different kind of list when I move it into a new view (see screenshots). How would I make it so it stays the same in both views? (The view I want) import SwiftUI struct SheetListView: View {     @State private var showGreeting = true     var body: some View {         List {             HStack {                 Label("Expert mode", systemImage: "list.bullet.rectangle.portrait")                     .font(.title2)                 Image(systemName: "questionmark.circle")                     .foregroundColor(.gray)                 Spacer()                 Toggle("Expert Mode", isOn: $showGreeting)                     .toggleStyle(.switch)                     .labelsHidden()             }             Section(header: Text("Extras")) {                 Label("FAQ", systemImage: "bubble.left.and.exclamationmark.bubble.right")                     .font(.title2)                 Label("Meet the maker", systemImage: "hand.wave")                     .font(.title2)                 Label("Tips", systemImage: "dollarsign.square")                     .font(.title2)                 Label("Credits", systemImage: "person.2")                     .font(.title2)             }             Section(header: Text("Contact")) {                 Label("Contact me", systemImage: "envelope")                     .font(.title2)                 Label("Report a bug", systemImage: "ant")                     .font(.title2)             }         }     } } struct SheetListView_Previews: PreviewProvider {     static var previews: some View {         SheetListView()     } } (The view I get) import SwiftUI struct SheetView: View {     @Environment(\.dismiss) var dismiss     var body: some View {         NavigationView {             VStack {                 SheetListView()                 Spacer()                 HStack {                     Text("App version 0.1 (DEV)")                         .foregroundColor(.gray)                 }                 .toolbar {                     Button("Done") {                         dismiss()                     }                     .font(.headline)                     .padding()                 }             }             .background(Color(.systemGroupedBackground))         }     } } struct SheetView_Previews: PreviewProvider {     static var previews: some View {         SheetView()     } }
1
0
665
Oct ’21
SwiftUI sidebar not behaving as intended
Hi! I'm having an issue where my sidebar isn't showing my NavigationView's how I wanted them to be displayed (See screenshots). I would like if it could take up the whole second panel, any help would be greatly appreciated, thanks! import SwiftUI struct SidebarView: View {     var body: some View {         NavigationView {             List {                 NavigationLink(destination: ExploreView()) {                     Label("Explore", systemImage: "rectangle.3.group")                 }                                  NavigationLink(destination: ListView()) {                     Label("Devices", systemImage: "list.bullet.below.rectangle")                 }             }             .listStyle(.sidebar)             .navigationTitle("Orchard")             ExploreView()         }     } } struct SidebarView_Previews: PreviewProvider {     static var previews: some View {         SidebarView()             .environmentObject(ModelData()) .previewInterfaceOrientation(.landscapeLeft)     } }
1
0
1.4k
Nov ’21
Take json data from url
Hi! I would like to take in json data from a url that I already have set up, using something like this. Thanks! func load<T: Decodable>(_ filename: String) -> T {     let data: Data     guard let file = Bundle.main.url(forResource: filename, withExtension: nil)         else {             fatalError("Couldn't find \(filename) in main bundle.")     }     do {         data = try Data(contentsOf: file)     } catch {         fatalError("Couldn't load \(filename) from main bundle:\n\(error)")     }     do {         let decoder = JSONDecoder()         return try decoder.decode(T.self, from: data)     } catch {         fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)")     } }
1
0
430
Dec ’21
Xcode AppleConnect authentication error
Hello! I am trying to install the iOS simulator on Xcode 15 but I get an error message telling me I am not signed in to AppleConnect every time. I am aware that AppleConnect is Apple's interal employee SSO, but I am not an employee or contractor. Does anyone know how to get around this message? I have searched my Mac for files and directories that could have lead to the issue, and signed in and out of my Apple ID to no avail. I greatly appricate any help! Thank you. See the error here: The operation couldn’t be completed. (DVTNFASupport.AppleConnectError error 1.) Domain: DVTNFASupport.AppleConnectError Code: 1 User Info: { DVTErrorCreationDateKey = "2023-06-08 00:45:07 +0000"; } -- System Information macOS Version 14.0 (Build 23A5257q) Xcode 15.0 (22181.17) (Build 15A5160n) Timestamp: 2023-06-07T18:45:07-06:00
1
1
520
Jun ’23