Post

Replies

Boosts

Views

Activity

Reply to Error
Have you looked at your post ? It is just unreadable with all those extra blank lines. When you paste code, please: use Paste and Match Style format with code formatter tool (<>) And there misses lines, so it is impossible to understand your code. There are also very basic errors:             Image(systemName: isDecrementOn ? "minus" : plus") Misses a quote before plus" you define func performMaths in the middle of the code. and the func misses 3 } to end properly ! All buttons actions mis a closing ) for the action, and the Text() must be inside { } as a closure You define performMaths but call performsMat You define 2 scrollViews. Are they inside each other ? It is a real mess. Please, make the effort to post something readable. I did a little formatting ans some corrections: struct ContentView: View { &#9;&#9;@State private var currentCount = UserDefaults.standard.integer(forKey: "currentCount") &#9;&#9;@State private var isDecrementOn = false &#9;&#9; &#9;&#9;func performsMath(isSubtract: Bool, num: Int) { &#9;&#9;&#9;&#9;var result = self.currentCount &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;if isSubtract==true{ &#9;&#9;&#9;&#9;&#9;&#9;result -= num &#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;result += num &#9;&#9;&#9;&#9;&#9;&#9;if result >= 0 { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;currentCount = result &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;UserDefaults.standard.set(currentCount, forKey: "currentCount") &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;ScrollView { &#9;&#9;&#9;&#9;&#9;&#9;VStack(alignment: .center, spacing: 10) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack(alignment: .center, spacing: 20) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.isDecrementOn.toggle() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Image(systemName: isDecrementOn ? "minus" : "plus") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.font(.headline) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(.blue) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;aspectRatio(contentMode: .fit) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.currentCount = 0 &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;UserDefaults.standard.set(0,forKey: "currentCount") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Image(systemName: "trash") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.font(.headline) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(.red) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;aspectRatio(contentMode: .fit) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.performsMath(isSubtract: self.isDecrementOn, num: 1) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}){ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("\(self.currentCount)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.font(.title) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} // THERE IS A PROBLEM HERE: WHERE IS THIS SCROLLVIEW ? INSIDE VSTACK ? &#9;&#9;&#9;&#9;&#9;&#9;ScrollView(.horizontal) { &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;HStack(alignment: .center, spacing: 10) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.performsMath(isSubtract: self.isDecrementOn, num: 1) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(isDecrementOn ? "-1" : "+1") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.performsMath(isSubtract: self.isDecrementOn, num: 2) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(isDecrementOn ? "-2" : "+2" &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.performsMath(isSubtract: self.isDecrementOn, num: 3) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(isDecrementOn ? "-3" : "+3" &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.performsMath(isSubtract: self.isDecrementOn, num: 4) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(isDecrementOn ? "-4" : "+4" &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.performsMath(isSubtract: self.isDecrementOn, num: 5) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(isDecrementOn ? "-5" : "+5" &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.performsMath(isSubtract: self.isDecrementOn, num: 10) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(isDecrementOn ? "-10" : "+10" &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 50) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.padding(.all) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;struct ContentView_Previews: PreviewProvider { &#9;&#9;static var previews: some View { &#9;&#9;&#9;&#9;ContentView() &#9;&#9;} } &#9;&#9;} }
Jan ’21
Reply to Protocol Not Working
So there is a problem in prepare. Instrument more the code: override func prepare(for segue: UIStoryboardSegue, sender: Any?) { &#9;print("segue identifier", segue.identifier) &#9;if segue.identifier == "r" { &#9;&#9;let hockeyDetailVC: HockeyDetailVC = segue.destination as! HockeyDetailVC &#9;&#9;hockeyDetailVC.delegate = self &#9;} } and tell what you get. If you get something different from segue identifier r such as segue identifier R or segue identifier SomeString that means that "r" is not the identifier of this segue. Then change "r" by what you got here after "segue identifier" Note: print("invoked HockeyDetailVC is", self) gives me invoked HockeyDetailVC is <LearnHockey.HockeyDetailVC: 0x7fe0b3026200>. Can you explain the 0x7fe0b3026200. 0x7fe0b3026200 is simply the address o self. The point would be to compare with the instance in HockeyDetailVC viewDidload But the problem is most likely in prepare.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Protocol Not Working
Okay I can't do segue.destination as? HockeyDetailVC but is (segue.destination as? HockeyDetailVC)! okay?  Did you write     if let hockeyDetailVC = segue.destination as? HockeyDetailVC  {   hockeyDetailVC.delegate = self &#9; } print("segue identifier", segue.identifier) does not give me any response on the console. Please tell exactly how you call the segue: by defining in IB ? If so, from where to where exactly in code with performSegue ? If so, show the complete func where it is called
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Predefined Shapes with UIPencilKit
Where is your problem ? creating the list ? Do you know how to use ToolPicker ? https ://medium. com/flawless-app-stories/getting-started-with-pencilkit-on-ios-13-a4bda3323fd8 or https ://www.raywenderlich. com/12198216-drawing-with-pencilkit-getting-started selecting a shape and display ? Same tutorial should help allow user to edit the shape ?
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’21
Reply to hidden Button on TabBar, second view.
You can access an item in the tab from its child views with:         let item0 = self.tabBarController!.tabBar.items![0] But you cannot suppress items there by invoking setItems from the "child". You then get a crash: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Directly modifying a tab bar managed by a tab bar controller is not allowed.' I did not find how to hide item from there. Maybe (I did not try), you could declare a Protocol with a func hideItem(row: Int) It would execute in the TabBarController and be invoked from a child.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’21
Reply to I need help
Your question is really too general. And the forum is not there to facilitate copying existing apps (they would be refused on the appstore anyway). Do you know how to use XCode ? Do you know Swift or objC ? Do you know the key API to program on iOS. If yes to all 3 questions, what is the first problem you have for your app ? Have you started designing the User Interface with Interface Builder ? If no, you need to learn. You may start with "intro to App Development with Swift" in Apple's Books Don't forget to close the thread by marking this answer if that answered your question.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Generic JSON response from API request
Because it shows me this error Value of type 'T' has no member ' results' That's true ! load() does not know anything yet about T. Why do you want a generic here ? And not directly Response ? Otherwise, you need to test is T is Response and cast it to Response. But what's the interest in doing so ?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to In App Settings
Continuation… When I initially determine if they allowed notifications something in there isn’t correct. I need code asking if they allowed local notification To request authorisation, do this: let center = UNUserNotificationCenter.current() center.delegate = self center.getNotificationSettings(completionHandler: { (settings) in if settings.authorizationStatus == .notDetermined { // Notification permission has not been asked yet, go for it! // Notification permission was previously denied, go to settings & privacy to re-enable center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in DispatchQueue.main.async { // Enable or disable features based on authorization. if !granted { let alert = UIAlertController(title: NSLocalizedString("Notification ", comment: ""), message: "", preferredStyle: .alert) alert.message = NSLocalizedString("Notifications disabled: Activate in Settings.", comment: "") alert.addAction(UIAlertAction(title: NSLocalizedString("ok", comment: ""), style: .cancel) { in // continue your work }) self.present(alert, animated: true, completion: nil) } } } } else if settings.authorizationStatus == .denied { DispatchQueue.main.async { let alert = UIAlertController(title: NSLocalizedString("Notification ", comment: ""), message: "", preferredStyle: .alert) // Enable or disable features based on authorization. alert.message = NSLocalizedString("Notifications disabled: Activate in Settings.", comment: "") alert.addAction(UIAlertAction(title: NSLocalizedString("ok", comment: ""), style: .cancel) { in // continue your work }) self.present(alert, animated: true, completion: nil) } } else if settings.authorizationStatus == .authorized { // Notification permission was already granted } }) ``` Note that date is never used (line 31)
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21