Post

Replies

Boosts

Views

Activity

Reply to Decoding JSON SwifUI
Hello I tried your solution and got this: Thread 1: Fatal error: Failed to decode sf.json from bundle.: keyNotFound(CodingKeys(stringValue: "id", intValue: nil), Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0)], debugDescription: "No value associated with key CodingKeys(stringValue: \"id\", intValue: nil) (\"id\").", underlyingError: nil))
Dec ’20
Reply to Decoding JSON SwifUI
This is the file now: [   {     "title": "Shapes",     "items": [       "rectangle",       "rectangle.fill",       "shield",       "shield.fill"     ]   },   {     "title": "Arrows",     "items": [       "arrowshape.turn.up.left",       "arrowshape.turn.up.left.fill",       "arrowshape.turn.up.left.circle",       "arrowshape.turn.up.left.circle.fill"     ]   } ]
Dec ’20
Reply to Decoding JSON SwifUI
Hello And I have another question about the decimalPad 		@State var deci = 3      var numberFormatter: NumberFormatter = {          let nf = NumberFormatter()          nf.locale = Locale.current          nf.numberStyle = .decimal          nf.maximumFractionDigits = deci          return nf      }() How do I fix this at line 10: Instance member 'deci' cannot be used on type 'BMIView'; did you mean to use a value of this type instead? Thank you very much for your time
Dec ’20
Reply to Fetch JSON Data not working
Still not working (I changed some code) // //	Charts // //	Created by Jad on 08/12/20. // import SwiftUI import Combine struct ContentView: View { 		@ObservedObject var networkController = NetworkController() 		@State var search: String = "" 		var body: some View { 				NavigationView{ 						Form{ 								Section(){ 										TextField("Search", text: $search) 								} 								Section(){ 										if search.isEmpty{ 												List(networkController.users, id: \.self){ user in 														NavigationLink(destination: DetailView(positive: user.positive, deathConfirmed: user.deathConfirmed)){ 																		Text(user.state) 														} 												} 										} else{ 												List(networkController.users.filter{$0.state.contains(search)}, id: \.self){ user in 														NavigationLink(destination: DetailView(positive: user.positive, deathConfirmed: user.deathConfirmed)){ 																		Text(user.state) 														} 												} 										} 								} 						} 						.navigationTitle("API") 				} 		} } class NetworkController: ObservableObject { 		private var can: AnyCancellable? 		 		let url = URL(string: "https://api.covidtracking.com/v1/states/current.json")! 		@Published var users = [User(state: "", positive: 0, deathConfirmed: 0)] 		 		init() { 				self.can = URLSession.shared.dataTaskPublisher(for: url) 						.map { $0.data } 						.decode(type: [User].self, decoder: JSONDecoder()) 						.replaceError(with: []) 						.eraseToAnyPublisher() 						.receive(on: DispatchQueue.main) 						.sink(receiveValue: { users in 								self.users	= users 						}) 		} 		 } struct User: Decodable, Hashable { 		var state: String 		var positive: Int 		var deathConfirmed: Int } //struct Records: Decodable, Hashable { //		var countriesAndTerritories: String //}
Dec ’20
Reply to Fetch JSON Data not working
I still don't get an error but I can't see any data Code: // //	Charts // //	Created by Jad on 08/12/20. // import SwiftUI import Combine struct ContentView: View { 		@ObservedObject var networkController = NetworkController() 		@State var search: String = "" 		var body: some View { 				NavigationView{ 						Form{ 								Section(){ 										TextField("Search", text: $search) 								} 								Section(){ 										if search.isEmpty{ 												List(networkController.users, id: \.self){ user in 														NavigationLink(destination: DetailView(positive: user.positive, state: user.state, deathConfirmed: user.deathConfirmed)){ 																		Text(user.state) 														} 												} 										} else{ 												List(networkController.users.filter{$0.state.contains(search)}, id: \.self){ user in 														NavigationLink(destination: DetailView(positive: user.positive, state: user.state, deathConfirmed: user.deathConfirmed)){ 																		Text(user.state) 														} 												} 										} 								} 						} 						.navigationTitle("API") 				} 		} } class NetworkController: ObservableObject { 		private var can: AnyCancellable? 		 		let url = URL(string: "https://api.covidtracking.com/v1/states/current.json")! 		@Published var users = [User(state: "", positive: 0, deathConfirmed: 0)] 		 		init() { 				self.can = URLSession.shared.dataTaskPublisher(for: url) 						.map { $0.data } 						.decode(type: [User].self, decoder: JSONDecoder()) 						//.replaceError(with: []) 						.eraseToAnyPublisher() 						.receive(on: DispatchQueue.main) 						.sink(receiveCompletion: {completion in 								print(completion) 						}, receiveValue: { users in 								self.users	= users 						}) 		} 		 } struct User: Decodable, Hashable { 		var state: String 		var positive: Int 		var deathConfirmed: Int } struct DetailView: View { 		 		var gridItemLayout = [GridItem(.flexible()), GridItem(.flexible())] 		 		var positive: Int 		var state: String 		var deathConfirmed: Int 		var body: some View { 				ScrollView{ 						LazyVGrid(columns: gridItemLayout, spacing: 10){ 								 								GroupBox{ 										VStack{ 												Text("State: ") 												Divider() 												Text(String(state)) 														.cornerRadius(16) 										} 								}.padding() 								 								GroupBox{ 										VStack{ 												Text("Positive: ") 												Divider() 												Text(String(positive)) 														.cornerRadius(16) 										} 										 								}.padding() 								 								GroupBox{ 										VStack{ 												Text("State: ") 												Divider() 												Text(String(deathConfirmed)) 														.cornerRadius(16) 										} 								}.padding() 						} 						.navigationBarTitle(state) 				} 		} } ```
Dec ’20
Reply to Fetch JSON Data not working
2020-12-28 14:36:28.125962+0100 Charts[47870:4787368] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed 2020-12-28 14:36:28.201001+0100 Charts[47870:4787265] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want.  Try this:  (1) look at each constraint and try to figure out which you don't expect;  (2) find the code that added the unwanted constraint or constraints and fix it.  (     "<NSLayoutConstraint:0x600002f2fe30 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x7f86e8424430]-(6)-[_UIModernBarButton:0x7f86e8421fd0'API']   (active)>",     "<NSLayoutConstraint:0x600002f2fe80 'CB_Trailing_Trailing' _UIModernBarButton:0x7f86e8421fd0'API'.trailing <= _UIButtonBarButton:0x7f86e8411020.trailing   (active)>",     "<NSLayoutConstraint:0x600002f0cc80 'UINav_static_button_horiz_position' _UIModernBarButton:0x7f86e8424430.leading == UILayoutGuide:0x60000351f1e0'UIViewLayoutMarginsGuide'.leading   (active)>",     "<NSLayoutConstraint:0x600002f0ccd0 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x7f86e8411020]-(0)-[UILayoutGuide:0x60000351f100'UINavigationBarItemContentLayoutGuide']   (active)>",     "<NSLayoutConstraint:0x600002f3d950 'UINavItemContentGuide-trailing' UILayoutGuide:0x60000351f100'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x7f86e8610bf0.trailing   (active)>",     "<NSLayoutConstraint:0x600002f0d450 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x7f86e8610bf0.width == 0   (active)>",     "<NSLayoutConstraint:0x600002f3dd10 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x60000351f1e0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarContentView:0x7f86e8610bf0 )>" ) Will attempt to recover by breaking constraint  Error: <NSLayoutConstraint:0x600002f2fe30 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x7f86e8424430]-(6)-[_UIModernBarButton:0x7f86e8421fd0'API']   (active)> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful. failure(Swift.DecodingError.valueNotFound(Swift.Int, Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 3", intValue: 3), CodingKeys(stringValue: "deathConfirmed", intValue: nil)], debugDescription: "Expected Int value but found null instead.", underlyingError: nil)))
Dec ’20
Reply to Attribute being read has no value: 768444
It happens on a real device This problem occurs when I close the window without writing anything or tapping done, and other times it crashes just when I close the app I think this is the real error: 2020-12-29 13:31:50.645517+0100 Nums[2002:352091] [error] precondition failure: attribute being read has no value: 785340 AttributeGraph precondition failure: attribute being read has no value: 785340. (lldb) I also get this when I separate the iPhone from the Mac: warning: failed to set breakpoint site at 0x1a2116b1c for breakpoint -5.1: error sending the breakpoint request (lldb) @State private var saveGoal = UserDefaults.standard.string(forKey: "Save")
Dec ’20
Reply to Attribute being read has no value: 768444
I changed it like this (still get errors) GroupBox { HStack { TextField("Have a goal?", text: $saveGoal.bound) .keyboardType(.numberPad) Spacer() Button("Save"){ UserDefaults.standard.set(self.saveGoal, forKey: "Save") self.hideKeyboard() } } Foe example if I open the textfield and press save without filling the textfield, sometimes it crashes Or if I close the window while the TextFiled is active
Dec ’20