Post

Replies

Boosts

Views

Activity

Reply to Checkmarks are not removed from the table cell
I use this if condition inside of didSelectRowAt method That seems to be the critical part of your code. In your code, item is a local variable. Changing the property of it does not affect the instance property food. Please try something like this: override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { foods[indexPath.row].isSelected.toggle() tableView.reloadRows(at: [indexPath], with: .automatic) } UITableView manages cell selection internally. So, you may need to add some code to make your isSelected work with such internal selection management, but anyway, please try the code above and tell us what happens.
Topic: UI Frameworks SubTopic: UIKit Tags:
Sep ’21
Reply to Toggling Values on EnvironmentValue (EditMode)
You can use toggle() on Bool, because Bool has a method named toggle(): toggle() As far as I checked, EditMode does not have a method named toggle() nor any other method of similar functionalities. EditMode If you do want it, you can define your own extension for EditMode: struct ContentView: View { @State var users = ["Susan", "Kate", "Natalie", "Kimberly", "Taylor", "Sarah", "Nancy", "Katherine", "Nicole", "Linda", "Jane", "Mary", "Olivia", "Barbara"] @State var editMode: EditMode = .inactive var body: some View { NavigationView { List { ForEach(users, id: \.self) { user in Text(user) } } .navigationBarTitle("Friends") .environment(\.editMode, $editMode) .navigationBarItems(leading: Button("Edit", action: { self.editMode.toggle() })) } } } extension EditMode { mutating func toggle() { if self.isEditing { self = .inactive } else { self = .active } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to How to add swift availability check to Environment values?
You may need to add @available on the struct using the new Environment value, and choose it using if #available. Something like this: struct MyView_watchOS7OrLower: View { var body: some View { Circle() .fill(Color.blue) } } @available(watchOSApplicationExtension 8.0, *) struct MyView_watchOS8OrHigher: View { @Environment(\.isLuminanceReduced) var isLuminanceReduced var body: some View { if isLuminanceReduced { Circle() .stroke(Color.gray, lineWidth: 10) } else { Circle() .fill(Color.white) } } } @ViewBuilder func MyView() -> some View { if #available(watchOS 8.0, *) { MyView_watchOS8OrHigher() } else { MyView_watchOS7OrLower() } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to Can't Download Xcode 12.4
I tried and it stopped at 2.60GB with unknown error. Generally, just around iPhone event (and WWDC) is not a good time to download huge things. Apple's servers get super-unstable in such period. Wail about a week after new iOS is published and try again. Maybe Apple needs to hire better network engineers.
Sep ’21
Reply to How to tap a row in a UIPickerView
How can I get the value of when the user taps the row? If you do not like adding a "Select" button, you can add a UITapGestureRecognizer to the UIPickerView. Something like this: import UIKit class ViewController: UIViewController { @IBOutlet weak var picker: UIPickerView! @IBOutlet weak var yourSquare: UILabel! var pickerData: [String] = [ "10", "20", "30" ] var squaresTaken: [Int] = [] override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. picker.delegate = self picker.dataSource = self let tap = UITapGestureRecognizer(target: self, action: #selector(pickerTapped)) tap.delegate = self picker.addGestureRecognizer(tap) } func intToString() { //??? } @objc func pickerTapped(_ gestureRecognizer: UITapGestureRecognizer) { guard let pickerView = gestureRecognizer.view as? UIPickerView else { return } let row = pickerView.selectedRow(inComponent: 0) squaresTaken.append(Int(pickerData[row])!) yourSquare.text = pickerData[row] } } extension ViewController: UIPickerViewDelegate, UIPickerViewDataSource { func numberOfComponents(in pickerView: UIPickerView) -> Int { return 1 } func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { pickerData.count } func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { intToString() return pickerData[row] } } extension ViewController: UIGestureRecognizerDelegate { func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true } }
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Reply to Problems with NavigationView and NavigationLink
I cannot find how to submit a Xcode bug report. You use Apple's Feedback Assistant to report a bug. Please do not forget to include: Your environment -- not only Xcode version, your macOS version your Mac model, simulator/device OS version & model, etc... Issue-reproducible project Step-by-step instruction to reproduce the issue What you expect What actually happens Some Apple's engineers may want to know the bug report number and you can share it writing here.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to Rotate View around an other View SwiftUI
Please try this: struct MyGameView: View { @State private var degress: Double = 0 let timer = Timer.publish(every: 0.05, on: .main, in: .common).autoconnect() var body: some View { VStack{ ZStack{ Circle() .frame(width: 80) ZStack{ Circle() .stroke(lineWidth: 1) .frame(width: 300) BallonShape() .scaledToFit() .scaleEffect(0.2) .foregroundColor(.red) .offset(x: 0, y: -170) //Uncomment to clarify what is rotating around what //.background(Color(.displayP3, red: 0.7, green: 0, blue: 0.3, opacity: 0.5)) .rotationEffect(.degrees(degress), anchor: .center) //<- Move `rotationEffect` after `offset` and use `.center` } } } .onReceive(timer) { input in withAnimation(.easeIn(duration: 0.05).speed(10)){ degress += 1 } } } } You should better try with various sizes of devices or simulators to check if the code works as expected in all the sizes.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to MacOs - NSTableView, editing single cell
I'm using a cell based NSTableView. You should better read this old article: Programmatically Editing Data in an NSCell-Based Table Seems you need to implement tableView(_:setObjectValue:for:row:) in your NSTableViewDataSource: func tableView(_ tableView: NSTableView, setObjectValue object: Any?, for tableColumn: NSTableColumn?, row: Int) { guard let stringValue = object as? String else { return } //Check `tableColumn` in a real implementation... print("cell was edited") print(stringValue) infoForTableView[row] = stringValue } Generally, NSCell-based table view is sort of an older part of NSTableView, it is simpler in many simple cases, but less customizable.
Topic: UI Frameworks SubTopic: AppKit Tags:
Sep ’21
Reply to Is it possible to replicate @State or @FetchRequest behaviour?
Or in a more concrete way: how can I send a state change from my own property wrapper so the view hierarchy is updated as response? Maybe you can achieve what you want using DynamicProperty. A simplified example: import SwiftUI struct ContentView: View { @Delay(seconds: 3) var value var body: some View { VStack { Text("\(value)") .padding() Button("add delayed") { value += 1 } } } } @propertyWrapper struct Delay: DynamicProperty { @State var value: Int = 0 let seconds: Int var wrappedValue: Int { get { value } nonmutating set { DispatchQueue.main.asyncAfter(deadline: .now() + DispatchTimeInterval.seconds(seconds)) { self.value = newValue } } } } Or this article might be a good example: https://www.hackingwithswift.com/plus/intermediate-swiftui/creating-a-custom-property-wrapper-using-dynamicproperty
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to Checkmarks are not removed from the table cell
I use this if condition inside of didSelectRowAt method That seems to be the critical part of your code. In your code, item is a local variable. Changing the property of it does not affect the instance property food. Please try something like this: override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { foods[indexPath.row].isSelected.toggle() tableView.reloadRows(at: [indexPath], with: .automatic) } UITableView manages cell selection internally. So, you may need to add some code to make your isSelected work with such internal selection management, but anyway, please try the code above and tell us what happens.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Toggling Values on EnvironmentValue (EditMode)
You can use toggle() on Bool, because Bool has a method named toggle(): toggle() As far as I checked, EditMode does not have a method named toggle() nor any other method of similar functionalities. EditMode If you do want it, you can define your own extension for EditMode: struct ContentView: View { @State var users = ["Susan", "Kate", "Natalie", "Kimberly", "Taylor", "Sarah", "Nancy", "Katherine", "Nicole", "Linda", "Jane", "Mary", "Olivia", "Barbara"] @State var editMode: EditMode = .inactive var body: some View { NavigationView { List { ForEach(users, id: \.self) { user in Text(user) } } .navigationBarTitle("Friends") .environment(\.editMode, $editMode) .navigationBarItems(leading: Button("Edit", action: { self.editMode.toggle() })) } } } extension EditMode { mutating func toggle() { if self.isEditing { self = .inactive } else { self = .active } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to How can I remove the healthkit framework and source(Metadata Rejected)
e. pod update If any of the pods are using HealthKit internally, updating is not sufficient and you may need to remove them. You might be able to check if your app binary contains HK- or Health-something in the similar way as shown in this post.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to dataWithContentsOfURL is nil with url from Files app
Why would my app not have permission to view the document when it's from the files app? Sandboxed apps (meaning all the usual apps we developers create) do not have permissions to access documents of other apps.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to add swift availability check to Environment values?
You may need to add @available on the struct using the new Environment value, and choose it using if #available. Something like this: struct MyView_watchOS7OrLower: View { var body: some View { Circle() .fill(Color.blue) } } @available(watchOSApplicationExtension 8.0, *) struct MyView_watchOS8OrHigher: View { @Environment(\.isLuminanceReduced) var isLuminanceReduced var body: some View { if isLuminanceReduced { Circle() .stroke(Color.gray, lineWidth: 10) } else { Circle() .fill(Color.white) } } } @ViewBuilder func MyView() -> some View { if #available(watchOS 8.0, *) { MyView_watchOS8OrHigher() } else { MyView_watchOS7OrLower() } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Can't Download Xcode 12.4
I tried and it stopped at 2.60GB with unknown error. Generally, just around iPhone event (and WWDC) is not a good time to download huge things. Apple's servers get super-unstable in such period. Wail about a week after new iOS is published and try again. Maybe Apple needs to hire better network engineers.
Replies
Boosts
Views
Activity
Sep ’21
Reply to Xcode 12.4 results won’t show in sidebar
Is it something I’m missing? May be or may not be. Hard to say something sure without seeing more info about your app. Can you show enough code to reproduce the issue? One more, using the right tags is very important to get help in the dev forums, Xcode Cloud is not what you are asking about.
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to tap a row in a UIPickerView
How can I get the value of when the user taps the row? If you do not like adding a "Select" button, you can add a UITapGestureRecognizer to the UIPickerView. Something like this: import UIKit class ViewController: UIViewController { @IBOutlet weak var picker: UIPickerView! @IBOutlet weak var yourSquare: UILabel! var pickerData: [String] = [ "10", "20", "30" ] var squaresTaken: [Int] = [] override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. picker.delegate = self picker.dataSource = self let tap = UITapGestureRecognizer(target: self, action: #selector(pickerTapped)) tap.delegate = self picker.addGestureRecognizer(tap) } func intToString() { //??? } @objc func pickerTapped(_ gestureRecognizer: UITapGestureRecognizer) { guard let pickerView = gestureRecognizer.view as? UIPickerView else { return } let row = pickerView.selectedRow(inComponent: 0) squaresTaken.append(Int(pickerData[row])!) yourSquare.text = pickerData[row] } } extension ViewController: UIPickerViewDelegate, UIPickerViewDataSource { func numberOfComponents(in pickerView: UIPickerView) -> Int { return 1 } func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { pickerData.count } func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { intToString() return pickerData[row] } } extension ViewController: UIGestureRecognizerDelegate { func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Problems with NavigationView and NavigationLink
I cannot find how to submit a Xcode bug report. You use Apple's Feedback Assistant to report a bug. Please do not forget to include: Your environment -- not only Xcode version, your macOS version your Mac model, simulator/device OS version & model, etc... Issue-reproducible project Step-by-step instruction to reproduce the issue What you expect What actually happens Some Apple's engineers may want to know the bug report number and you can share it writing here.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to CryptoKit TOTP Fails in Swift Package
Maybe you have another HMAC in your module, no?
Topic: Privacy & Security SubTopic: General Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to There are two variables set by the user. After counting up from 1 to one variable, I want to count up the number from 1 to the other variable.
Readers would be happy if you could respond to answers or comments.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Rotate View around an other View SwiftUI
Please try this: struct MyGameView: View { @State private var degress: Double = 0 let timer = Timer.publish(every: 0.05, on: .main, in: .common).autoconnect() var body: some View { VStack{ ZStack{ Circle() .frame(width: 80) ZStack{ Circle() .stroke(lineWidth: 1) .frame(width: 300) BallonShape() .scaledToFit() .scaleEffect(0.2) .foregroundColor(.red) .offset(x: 0, y: -170) //Uncomment to clarify what is rotating around what //.background(Color(.displayP3, red: 0.7, green: 0, blue: 0.3, opacity: 0.5)) .rotationEffect(.degrees(degress), anchor: .center) //<- Move `rotationEffect` after `offset` and use `.center` } } } .onReceive(timer) { input in withAnimation(.easeIn(duration: 0.05).speed(10)){ degress += 1 } } } } You should better try with various sizes of devices or simulators to check if the code works as expected in all the sizes.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to MacOs - NSTableView, editing single cell
I'm using a cell based NSTableView. You should better read this old article: Programmatically Editing Data in an NSCell-Based Table Seems you need to implement tableView(_:setObjectValue:for:row:) in your NSTableViewDataSource: func tableView(_ tableView: NSTableView, setObjectValue object: Any?, for tableColumn: NSTableColumn?, row: Int) { guard let stringValue = object as? String else { return } //Check `tableColumn` in a real implementation... print("cell was edited") print(stringValue) infoForTableView[row] = stringValue } Generally, NSCell-based table view is sort of an older part of NSTableView, it is simpler in many simple cases, but less customizable.
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Is it possible to replicate @State or @FetchRequest behaviour?
Or in a more concrete way: how can I send a state change from my own property wrapper so the view hierarchy is updated as response? Maybe you can achieve what you want using DynamicProperty. A simplified example: import SwiftUI struct ContentView: View { @Delay(seconds: 3) var value var body: some View { VStack { Text("\(value)") .padding() Button("add delayed") { value += 1 } } } } @propertyWrapper struct Delay: DynamicProperty { @State var value: Int = 0 let seconds: Int var wrappedValue: Int { get { value } nonmutating set { DispatchQueue.main.asyncAfter(deadline: .now() + DispatchTimeInterval.seconds(seconds)) { self.value = newValue } } } } Or this article might be a good example: https://www.hackingwithswift.com/plus/intermediate-swiftui/creating-a-custom-property-wrapper-using-dynamicproperty
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Will I be able to upload using beta SDK?
NO. You need to use Xcode/SDK released with Apple's announcement saying you can submit apps. News and Updates Seems the Xcode 13 RC is the version you need.
Replies
Boosts
Views
Activity
Sep ’21