Post

Replies

Boosts

Views

Activity

Reply to access the uuid property in query
Why don't you simply access the property uuid? for result in results as! [HKQuantitySample] { let uuid = result.uuid print(uuid) let bloodGlucose = result.quantity.description //... } By the way, what is the type of results? You should better avoid risky forced casting as! as far as you can.
Topic: Programming Languages SubTopic: Swift Tags:
Feb ’21
Reply to progress bar will not work
What do you mean by will not work? If your code causes build time errors, you should show all the error messages. If your code causes runtime errors, you should include all the error info as well as all the steps to reproduce the error. If your code runs without errors but generates unexpected results, you need to clarify what you expect, what you actually get and how you can reproduce the issue.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’21
Reply to DES in Swift using CommonCrypto
Assuming you can supply all other parameters, you may need to write something like this: var result = Data(count: maximumSizeOfDecryptedData) var numBytesDecrypted: Int = 0 let err = result.withUnsafeMutableBytes {bufPtr in CCCrypt(op, alg, options, key, keyLength, iv, dataIn, dataInLength, bufPtr.baseAddress, bufPtr.count, &numBytesDecrypted) } if err == kCCSuccess { result.count = numBytesDecrypted print(result) //- Use `result` as the decrypted Data } else { print("error: \(err)") }
Topic: Programming Languages SubTopic: Swift Tags:
Feb ’21
Reply to Conditionally changing a value in an array
Even when you apply var to the control variable of for-in statement, the variable holds the copy of each element of the Array as its initial value. You cannot change the original Array when you just modify the control variable. You need to write index based access when you want to modify the Array: for index in myHorses[horseIndex].training.indices { if myHorses[horseIndex].training[index] 1.0 { print("value 1.0 found") myHorses[horseIndex].training[index] = 1.0 } }
Topic: Programming Languages SubTopic: Swift Tags:
Feb ’21
Reply to Beginner's question: Transferring MKPointAnnotation title to a new VC
Why don't you utilize the sender of the segue? func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) { self.performSegue(withIdentifier: "toDetailsVC", sender: view.annotation) //- } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "toDetailsVC" { guard let destinationVC = segue.destination as? DetailsVC, let annotation = sender as? MKPointAnnotation else { print("Unexpected segue: \(segue), \(String(describing: sender))") return } destinationVC.detailsTitle = annotation.title } }
Topic: Programming Languages SubTopic: Swift Tags:
Feb ’21
Reply to Setting UILabels to Firestore data
This is the most up to date code Thanks for updating the code. I have no knowledge and no intention to go deep into Firestore, but the lines 56...74 of your code is equivalent to the following: 								if snapshot == nil { 										if let currentRiddle = snapshot?["CurrentRiddle"] as? String { 												self.CurrentRiddle.text = "This Weeks Riddle: " + currentRiddle 												print(currentRiddle) 										} 										if let previousRiddle = snapshot?["CurrentRiddle"] as? String { 												self.PreviousRiddle.text = "Previous Riddle: " + previousRiddle 										} 								} The two if-lets are executed only when snapshot is nil, so, it has no meaning. You might want to do something like this: 								if let snapshot = snapshot { 										if let currentRiddle = snapshot["CurrentRiddle"] as? String { 												self.CurrentRiddle.text = "This Weeks Riddle: " + currentRiddle 												print(currentRiddle) 										} 										if let previousRiddle = snapshot["CurrentRiddle"] as? String { 												self.PreviousRiddle.text = "Previous Riddle: " + previousRiddle 										} 								}
Topic: Programming Languages SubTopic: Swift Tags:
Feb ’21
Reply to change binding of List with button press
I may be missing something, but why don't you simply add an @State variable to choose the lists? struct SplitView: View { 		@EnvironmentObject var viewRouter: ViewRouter 		@State var list1 = [MyModel]() 		@State var list2 = [MyModel]() 		 		@State var selected: Int = 1 		private var viewingModels: [MyModel] { 				switch selected { 				case 1: 						return list1 				case 2: 						return list2 				default: 						return [] 				} 		} 		var body: some View { 				HStack { 						Button(action: { 								selected = 1 						}){ 								Text("List 1") 						} 						Button(action: { 								selected = 2 						}){ 								Text("List 2") 						} 				} 				List(viewingModels, id: \.ID) { myitem in 								HStack(alignment: .center) { 										VStack(alignment: .leading) { 												Text(myitem.Name) 														.font(.subheadline) 														.fontWeight(.bold) 														Spacer() 										} 								} 				} 				.onAppear(perform: loadList) 				Spacer() 		} 		 }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’21