Post

Replies

Boosts

Views

Activity

Reply to Lags in UICollectionView accessories when animatedly applying a snapshot unless .disclosureIndicator() is also an accessory
Make a custom cell: class SwitchCell: UICollectionViewListCell { let _switch = UISwitch() override init(frame: CGRect) { super.init(frame: frame) accessories = [ .customView(configuration: .init( customView: _switch, placement: .trailing()) ) ] } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } And edit cellRegistration accordingly: let cellRegistration = UICollectionView.CellRegistration<SwitchCell, String> { [weak self] cell, indexPath, itemIdentifier in guard let self else { return } cell._switch.isOn = bool cell._switch.addTarget(self, action: #selector(toggleBool), for: .valueChanged) }
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’24
Reply to Update collection view supplementary view content
https://stackoverflow.com/questions/78311570/how-do-i-update-a-collection-view-supplementary-view-without-giving-up-on-animat At this time the answer is: To directly update a supplementaryView you need to know its kind and section. With your example, you could add a following didSet code to a footerText: var footerText = "Initial footer text" { didSet { guard let footer = collectionView.supplementaryView(forElementKind: UICollectionView.elementKindSectionFooter, at: IndexPath(row: 0, section: 0)) as? UICollectionViewListCell else { return } var contentConfiguration = UIListContentConfiguration.cell() contentConfiguration.text = self.footerText footer.contentConfiguration = contentConfiguration } } This way each time you change footerText, your footer will be updated. You could also move contentConfiguration update to a separate fuction, I've just copied it from your configureSupplementaryViewProvider
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’24
Reply to Swift 5.10: Cannot access property '*' with a non-sendable type '*' from non-isolated deinit; this is an error in Swift 6
https://stackoverflow.com/questions/78284030/swift-5-10-cannot-access-property-with-a-non-sendable-type-from-non-iso/78285030#78285030 In a nutshell: call signInAnonymouslyIfNecessary() in viewDidDisappear(): avoid in general dealing with class deinitializers. But if you insist on calling signInAnonymouslyIfNecessary() in the deinitializer, you can: Mark AuthController as @MainActor Mark signInAnonymouslyIfNecessary as nonisolated Wrap signInAnonymouslyIfNecessary in a Task: @MainActor final class AuthController { nonisolated func signInAnonymouslyIfNecessary() { Task { @MainActor in /// ... } } }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’24
Reply to SwiftUI previews not loading
Thank you for responding despite my vagueness. Apple MacBook Air M1, 8 GB, MacOS Sonoma 14.2.1, Xcode 15.2--I forgot to paste it from the TSI message. After a few hours, I got the "Cannot preview in this file" error. I’ve noticed that my derived data folder has a different location according to Xcode and Finder. According to Xcode, the root path is /Users/filippo. But, according to Finder, it's /Users/Filippo. I changed my username a year ago. If you think this issue could be related to my problem, please tell me how to solve it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’24
Reply to How to align UITextView text to the title of a table view section
https://stackoverflow.com/questions/746670/how-to-lose-margin-padding-in-uitextview
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to Lags in UICollectionView accessories when animatedly applying a snapshot unless .disclosureIndicator() is also an accessory
Make a custom cell: class SwitchCell: UICollectionViewListCell { let _switch = UISwitch() override init(frame: CGRect) { super.init(frame: frame) accessories = [ .customView(configuration: .init( customView: _switch, placement: .trailing()) ) ] } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } } And edit cellRegistration accordingly: let cellRegistration = UICollectionView.CellRegistration<SwitchCell, String> { [weak self] cell, indexPath, itemIdentifier in guard let self else { return } cell._switch.isOn = bool cell._switch.addTarget(self, action: #selector(toggleBool), for: .valueChanged) }
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to Update collection view supplementary view content
https://stackoverflow.com/questions/78311570/how-do-i-update-a-collection-view-supplementary-view-without-giving-up-on-animat At this time the answer is: To directly update a supplementaryView you need to know its kind and section. With your example, you could add a following didSet code to a footerText: var footerText = "Initial footer text" { didSet { guard let footer = collectionView.supplementaryView(forElementKind: UICollectionView.elementKindSectionFooter, at: IndexPath(row: 0, section: 0)) as? UICollectionViewListCell else { return } var contentConfiguration = UIListContentConfiguration.cell() contentConfiguration.text = self.footerText footer.contentConfiguration = contentConfiguration } } This way each time you change footerText, your footer will be updated. You could also move contentConfiguration update to a separate fuction, I've just copied it from your configureSupplementaryViewProvider
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to Swift 5.10: Cannot access property '*' with a non-sendable type '*' from non-isolated deinit; this is an error in Swift 6
https://stackoverflow.com/questions/78284030/swift-5-10-cannot-access-property-with-a-non-sendable-type-from-non-iso/78285030#78285030 In a nutshell: call signInAnonymouslyIfNecessary() in viewDidDisappear(): avoid in general dealing with class deinitializers. But if you insist on calling signInAnonymouslyIfNecessary() in the deinitializer, you can: Mark AuthController as @MainActor Mark signInAnonymouslyIfNecessary as nonisolated Wrap signInAnonymouslyIfNecessary in a Task: @MainActor final class AuthController { nonisolated func signInAnonymouslyIfNecessary() { Task { @MainActor in /// ... } } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to How do I resize a UICollectionViewListCell containing a UITextView?
https://stackoverflow.com/questions/78268523/how-do-i-resize-a-uicollectionviewlistcell-containing-a-uitextview.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Apr ’24
Reply to Can't display the simplest UIToolbar
https://stackoverflow.com/questions/78248735/cant-display-the-simplest-uitoolbar
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to SwiftUI selectable stepper in view that presents modally
https://stackoverflow.com/questions/78089692/swiftui-selectable-stepper-in-view-that-presents-modally
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to Override show(_:sender:) of UIViewController freezes the UI
https://stackoverflow.com/questions/78241008/override-show-sender-of-uiviewcontroller-freezes-the-ui
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to UIStepper disclosure indicator
Fixed: cell.accessories = [.disclosureIndicator(), .customView(configuration: .init(customView: UIStepper(), placement: .trailing(), reservedLayoutWidth: .actual))]
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to How do I inject reference types in a table view cell and reload the row of the said cell without causing a memory leak?
Okay thank you. I don’t understand why the memory keeps growing, but I understand that I simply cannot use reloadRows(at:) in this case.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Mar ’24
Reply to Change derived data location in Xcode
Answer: https://stackoverflow.com/questions/77939616/change-derived-data-location-in-xcode
Replies
Boosts
Views
Activity
Feb ’24
Reply to SwiftUI previews not loading
Thank you for responding despite my vagueness. Apple MacBook Air M1, 8 GB, MacOS Sonoma 14.2.1, Xcode 15.2--I forgot to paste it from the TSI message. After a few hours, I got the "Cannot preview in this file" error. I’ve noticed that my derived data folder has a different location according to Xcode and Finder. According to Xcode, the root path is /Users/filippo. But, according to Finder, it's /Users/Filippo. I changed my username a year ago. If you think this issue could be related to my problem, please tell me how to solve it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’24