Post

Replies

Boosts

Views

Activity

When using NSCollectionLayoutSection.list, how to specific header height and cell item height?
I am using NSCollectionLayoutSection.list as follow. private func layoutConfig() -> UICollectionViewCompositionalLayout { let layout = UICollectionViewCompositionalLayout { section, layoutEnvironment in var config = UICollectionLayoutListConfiguration(appearance: .plain) config.headerMode = .supplementary config.footerMode = .none config.showsSeparators = false config.headerTopPadding = 0 // https://developer.apple.com/forums/thread/759987 let layoutSection = NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment) layoutSection.interGroupSpacing = 0 layoutSection.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0) if let header = layoutSection.boundarySupplementaryItems.first(where: { $0.elementKind == UICollectionView.elementKindSectionHeader }) { header.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0) } return layoutSection } return layout } We provide our own custom header view and cell item view. Header View class HideShowHeader: UICollectionViewListCell { override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func systemLayoutSizeFitting(_ targetSize: CGSize) -> CGSize { // Ensure the cell fills the width of the collection view let size = CGSize( width: targetSize.width, height: 80 ) print(">>>> size \(size)") return size } } Cell Item View class TodoCell: UICollectionViewListCell { override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func systemLayoutSizeFitting(_ targetSize: CGSize) -> CGSize { // Ensure the cell fills the width of the collection view let size = CGSize( width: targetSize.width, height: 80 ) return size } } We would like to fine-tune the height of header and cell item. However, override systemLayoutSizeFitting doesn't work. May I know, when using NSCollectionLayoutSection.list, how to specific header height and cell item height? Thanks.
Topic: UI Frameworks SubTopic: UIKit Tags:
0
1
502
Jul ’24
How to Simulate Subscription Cancellation with Products.storekit in Simulator?
Hi, Currently, instead of using a real device and test account for in-app purchase testing, we are using Products.storekit with the Simulator. Our app offers a subscription plan with a 3-day free trial. We would like to simulate the following test scenarios: User cancels the subscription within the 3-day free trial period. User cancels the subscription after the 3-day free trial period. However, in Xcode, under Debug > StoreKit > Manage Transactions..., we couldn’t find an option to simulate a subscription cancellation. There is an option to refund the purchase, but we believe this is not the same as a cancellation. Do you have any idea how we can simulate these two cases using Products.storekit and the Simulator? Thanks in advance!
1
1
120
Apr ’25
Unexpected Change in Apple Refund Handling CONSUMPTION_REQUEST - Impact on Subscription App with AI Backend
We offer a 3-day free trial, and our paywall clearly states that users will be charged after the trial ends. However, some users request refunds after the charge - even after fully using our app for days or even weeks. In some cases, refunds are approved despite the users having consumed our AI processing services for up to a month. Since our app relies on backend AI processing, each user session incurs a real cost. To prevent losses, we utilize RevenueCat’s CONSUMPTION_REQUEST system and have set our refundPreference to: "2. You prefer that Apple declines the refund". Until recently, Apple typically respected this preference, and 90% of refund requests were declined as intended. However, starting about a week ago, we observed a sudden reversal: Apple is now approving around 90% of refund requests, despite our refund preference. As a result, we are operating at a loss and have had to halt both our marketing campaigns and our 3-day free trial. We’re trying to understand whether this shift is due to a change in Apple’s refund policy, or if we need to handle CONSUMPTION_REQUEST differently on our end. Has anyone else experienced similar changes? Any insights would be greatly appreciated.
0
1
449
May ’25
The following simple function will cause Xcode 12E262 to have "Abort: trap 6"
The following simple function will cause Xcode 12E262 to have "Abort: trap 6" during compilation. import UIKit import CoreData class ViewController: UIViewController {     func xyz() {         let container = NSPersistentContainer(name: "xyz")         let batchUpdateRequest = NSBatchUpdateRequest(entityName: "xyz")         let batchUpdateResult = try! container.viewContext.execute(batchUpdateRequest) as? NSBatchUpdateResult         guard let batchUpdateResult = batchUpdateResult else { return }     }     override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.     } } We will not observe "Abort: trap 6", if under Build Settings, we are using "Optimize for Speed" in Debug, instead of "No Optimization" We can also avoid "Abort: trap 6", if we change the following code guard let batchUpdateResult = batchUpdateResult else { return } to guard let batchUpdateResult2 = batchUpdateResult else { return } May I know, why is it so? A simpler code example to reproduce problem, without CoreData would be import UIKit class ViewController: UIViewController {     func getAny() throws -> Any? {         return nil     }     func xyz() {         let name = try! getAny() as? UIViewController         guard let name = name else { return }     }     override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.     } }
2
0
985
Jun ’21
Why an invisible same cell is being updated when update is performing using NSFetchedResultsController and Diffable Data Source?
Introduction I expect when I perform "update" on 1 of the CoreData entity content, corresponding UICollectionViewCell should updated seamlessly. But, the thing doesn't work as expected. After debugging, I notice that instead of updating visible UICollectionViewCell on screen, an invisible offscreen UICollectionViewCell has been created and all update operations are performed on the invisible UICollectionViewCell?! Simple hookup between NSFetchedResultsController and Diffable Data Source The hookup is pretty straightforward extension ViewController: NSFetchedResultsControllerDelegate { func controller(_ fetchedResultsController: NSFetchedResultsController<NSFetchRequestResult>, didChangeContentWith snapshotReference: NSDiffableDataSourceSnapshotReference) { guard let dataSource = self.dataSource else { return } let snapshot = snapshotReference as NSDiffableDataSourceSnapshot<Int, NSManagedObjectID> print("dataSource.apply") dataSource.apply(snapshot, animatingDifferences: true) { } } } Simple data structure import Foundation import CoreData extension NSTabInfo { @nonobjc public class func fetchRequest() -> NSFetchRequest<NSTabInfo> { return NSFetchRequest<NSTabInfo>(entityName: "NSTabInfo") } @NSManaged public var name: String? @NSManaged public var order: Int64 } extension NSTabInfo : Identifiable { } Simple data source to update cell private func initDataSource() { let dataSource = DataSource( collectionView: collectionView, cellProvider: { [weak self] (collectionView, indexPath, objectID) -> UICollectionViewCell? in guard let self = self else { return nil } guard let cell = collectionView.dequeueReusableCell( withReuseIdentifier: "cell", for: indexPath) as? CollectionViewCell else { return nil } guard let nsTabInfo = self.getNSTabInfo(indexPath) else { return nil } cell.label.text = nsTabInfo.name print("Memory for cell \(Unmanaged.passUnretained(cell).toOpaque())") print("Content for cell \(cell.label.text)\n") return cell } ) self.dataSource = dataSource } Updating code doesn't work We perform update on the 1st cell using the following code @IBAction func updateClicked(_ sender: Any) { let backgroundContext = self.backgroundContext backgroundContext.perform { let fetchRequest = NSFetchRequest<NSTabInfo>(entityName: "NSTabInfo") fetchRequest.sortDescriptors = [ NSSortDescriptor(key: "order", ascending: true) ] do { let nsTabInfos = try fetchRequest.execute() if !nsTabInfos.isEmpty { // Perform update on the first cell nsTabInfos[0].name = "\(Int(nsTabInfos[0].name!)! + 1)" if backgroundContext.hasChanges { try backgroundContext.save() } } } catch { print("\(error)") } } } Nothing is changed on the screen. However, if we look at the print output. We can see the initial content ("0") of the 1st cell is updated to "1". But, all of these are being done in an invisible same instance cell. dataSource.apply Memory for cell 0x0000000138705cd0 Content for cell Optional("1") Memory for cell 0x0000000138705cd0 Content for cell Optional("1") Memory for cell 0x0000000138705cd0 Content for cell Optional("2") Memory for cell 0x0000000138705cd0 Content for cell Optional("3") Ordering work without issue Changing the ordering of the cell works as expected. The following is the code for charging ordering. @IBAction func moveClicked(_ sender: Any) { let backgroundContext = self.backgroundContext backgroundContext.perform { let fetchRequest = NSFetchRequest<NSTabInfo>(entityName: "NSTabInfo") fetchRequest.sortDescriptors = [ NSSortDescriptor(key: "order", ascending: true) ] do { let nsTabInfos = try fetchRequest.execute() for (index, element) in nsTabInfos.reversed().enumerated() { element.order = Int64(index) } if backgroundContext.hasChanges { try backgroundContext.save() } } catch { print("\(error)") } } } Do you have idea why such problem occur? I prefer not to have collectionView.reloadData as workaround, as it will create more issue (like resetting scroll position, cell press state, ...) I posted a complete demo at https://github.com/yccheok/problem-update-frc-diffable Thank you
1
0
1.3k
Jul ’21
Should I use weak to avoid from interferencing with CoreData memory management?
Currently, I have the following core data backed collection view, which enable users to perform add/ delete/ modify/ reordering. It will be much more convenient to achieve what I, if I let UICollectionViewCell, to hold its corresponding NSManagedObject. So that I can each perform add/ delete/ modify/ reordering. I was wondering, should I mark the NSManagedObject as weak, to avoid from interferencing with how CoreData manage its memory? Using weak class TabInfoSettingsCell: UICollectionViewCell { // NSManagedObject. Use weak, as we do not want to inteference with how CoreData manage its memory. private weak var nsTabInfo : NSTabInfo? Use strong Or, such concern is invalid. We can simply use strong class TabInfoSettingsCell: UICollectionViewCell { // NSManagedObject. private var nsTabInfo : NSTabInfo? Use struct Or, such concern is valid and using weak is unsafe (as it can become nil in some edge case?). We can use a struct, which contains everything including objectID, but excluding NSManagedObjectContext. class TabInfoSettingsCell: UICollectionViewCell { // struct. Contains everything including objectID, but excluding NSManagedObjectContext. private var tabInfo : TabInfo? This come with the cost of having to create a struct out from NSManagedObject each time, in cellForItemAt. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { ... tabInfoSettingsCell.update(nsTabInfo.toTabInfo()) ... } May I know, which is the correct design, as far as safe memory management is concerned?
1
0
709
Jun ’21
Is NSAsynchronousFetchRequest suitable for production app?
NSAsynchronousFetchRequest seems like an answer to read large amount of data from CoreData, without blocking main thread. But, it is lacking some key features, provided by NSFetchedResultsController. The key features are :- In NSFetchedResultsControllerDelegate didChange and controllerDidChangeContent, we automatically receive a complete change information of persistence store. This enables us to implement the animation of add/delete/move/modify in collection view. Always listen to DB changes. Whenever there is changes being written into the persistence store, NSFetchedResultsControllerDelegate didChange and controllerDidChangeContent will be triggered automatically. This enables us to ensure our UI is in sync with DB. But, NSAsynchronousFetchRequest doesn't come with NSAsynchronousFetchedResultsController :( I was wondering, if you were using NSAsynchronousFetchRequest, how do you implement Animation changes on collection view? Always listen to DB change? My initial thought for animation changes on collection view, it seems we can utilise UICollectionViewDiffableDataSource. But, I notice it might be highly memory inefficient to do so. We need to keep ALL NSManagedObject in memory, fire all faults during comparison. It looks like we will run out of memory, if there are many rows. May I know, how do you achieve the following features, if you ever apply NSAsynchronousFetchRequest in production app? Animation changes on collection view? Always listen to DB change? Thanks.
1
0
811
Jul ’21
Is restore button still required if we were using StoreKit2 Transaction.currentEntitlements
Since StoreKit2 Transaction.currentEntitlements will able to return us user current owned purchased, during app startup. If that is the case, is it still necessary for developer to provide a restore button? If we still need to provide a restore button, what should the restore button do and what API should it call? Thanks
1
0
1.5k
Apr ’22
AVFAudio - Is it safe to perform file copy immediately after AVAudioRecorder.stop()
We start a voice recording via self.avAudioRecorder = try AVAudioRecorder( url: self.recordingFileUrl, settings: settings ) self.avAudioRecorder.record() At certain point, we will stop the recording via self.avAudioRecorder.stop() I was wondering, is it safe to perform file copy on self.recordingFileUrl immediately, after self.avAudioRecorder.stop()? Is all recording data has been flushed to self.recordingFileUrl and self.recordingFileUrl file is closed properly?
1
0
1.4k
May ’22
Is there any special handling required in StoreKit2, to handle promo code redemption?
My users will redeem promo code via app store (outside my app) Currently, I am using StoreKit2 to Query Transaction.currentEntitlements during app startup Keep listening to Transaction.updates I was wondering, is that is so, is there any special code required, to handle Promo code redeem from user? I guess by keep listening to Transaction.updates, will able to handle such case? But, I am not able to test that, without rolling out my app to production. Thanks.
1
0
809
Sep ’22
Stability of XCode 14
My XCode 13+ was used at MacBook Pro (13-inch, M1, 2020, 16G RAM) without issue Even since updated XCode to 14 week ago, I experience slowness while typing in XCode, and other editing operation. and, this crash happens few times a day Does anyone experience the same thing as I do? Thanks.
1
0
686
Sep ’22
Is there a way to override the theme of WidgetKit, so that we can retrieve correct named color in WidgetKit?
In main app, I can override dark/ light theme based on user preference, so that I can retrieve correct color information based on named color. if (user preference) { overrideUserInterfaceStyle = .light } else { overrideUserInterfaceStyle = .dark } // Dark theme/ light theme automatic aware color. SwiftUI.Color("purpleColor") However, how can I override the theme of a WidgetKit, so that my WidgetKit can interpret named color correctly? I know in WidgetKit, I can read what is current system wide theme settings using  @Environment(\.colorScheme) But, that is not what I want. I want the ability to override theme of a WidgetKit based on user preference, then able to retrieve correct named color. Thanks.
1
0
1k
Aug ’24
What is a reliable way, to check user system locale is using 12-hours or 24-hours format?
We would like to know, whether a user system locale is using 12-hours or 24-hours format? There are many proposed solutions at https://stackoverflow.com/q/1929958/72437 One of the solutions are let formatString = DateFormatter.dateFormat(fromTemplate: "j", options: 0, locale: Locale.current)! let hasAMPM = formatString.contains("a") However, to me, this is not a correct solution. When I tested with de_DE (German is using 24-hours), the returned string is HH 'Uhr' What is Uhr mean for? I guess it mean "clock" in German? There are so many other locales and one of them might contain letter a. Does anyone know, what is a correct way, to check whether user system locale is using 12-hours or 24-hours format?
3
0
902
Feb ’23
UISheetPresentationController: Remove Dim Background but Keep Touch-to-Dismiss?
I'm using the UISheetPresentationController to present a view, as shown in the following code: @IBAction func click(_ sender: Any) { let whiteViewController = WhiteViewController.instanceFromMainStoryBoard() if let sheet = whiteViewController.sheetPresentationController { sheet.detents = [.medium()] sheet.prefersScrollingExpandsWhenScrolledToEdge = false sheet.prefersGrabberVisible = false // Remove dim effect. ////sheet.largestUndimmedDetentIdentifier = .medium } self.present(whiteViewController, animated: true) } The outcome is as follow This code results in a presentation with: A dimmed background. A 'Touch anywhere to dismiss' behavior. However, I want to remove the dim background while keeping the 'Touch anywhere to dismiss' functionality. When I add the line: sheet.largestUndimmedDetentIdentifier = .medium The dim background is indeed removed, but the touch-to-dismiss behavior is gone too, as illustrated: Is there a way to achieve both – removing the dim background and retaining the touch-to-dismiss functionality? Thank you.
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
2.1k
Oct ’23
What are some other actionable items I can do, so that I can get through "Guideline 4.3(a) - Design - Spam" app update rejection?
I have an app which is in the app store since 2022. It is an app with combined features of note taking, todo list and calendar. My most recent app update is rejected with the following message. Guideline 4.3(a) - Design - Spam We noticed your app shares a similar binary, metadata, and/or concept as apps submitted to the App Store by other developers, with only minor differences. Submitting similar or repackaged apps is a form of spam that creates clutter and makes it difficult for users to discover new apps. Next Steps Since we do not accept spam apps on the App Store, we encourage you to review your app concept and submit a unique app with distinct content and functionality. Resources Some factors that contribute to a spam rejection may include: Submitting an app with the same source code or assets as other apps already submitted to the App Store Creating and submitting multiple similar apps using a repackaged app template Purchasing an app template with problematic code from a third party Submitting several similar apps across multiple accounts Learn more about our requirements to prevent spam in App Review Guideline 4.3(a). Support Reply to this message in your preferred language if you need assistance. If you need additional support, use the Contact Us module. Consult with fellow developers and Apple engineers on the Apple Developer Forums. Help improve the review process or identify a need for clarity in our policies by suggesting guideline changes. I reply the reviewer with the following message. Hi, I am writing to appeal the rejection of my app, XXX. I would like to emphasize the unique aspects of XXX that distinguish it from other apps in the market: Integrated Functionality: Unlike most apps that are standalone note-taking, to-do, or calendar apps, XXX uniquely combines all three functions into a single app. Extensive Calendar Features: XXX includes a comprehensive calendar feature covering holidays in 250 countries and 3,680 states and provinces, a rare and valuable feature. Chinese Lunar Calendar: Our app includes a Chinese Lunar Calendar, which is highly appreciated in the Taiwanese market, adding a culturally specific feature not commonly found in other apps. Organizational Tools: XXX allows unlimited tabs and colors for organizing notes, surpassing many competitors who offer limited color options. Flexible Viewing and Sorting Modes: Users can choose from four viewing modes (Grid, Compact Grid, List, Compact List) and five sorting modes (Modified Time, Created Time, Alphabet, Color, Check, Reminder), enhancing the user experience by providing flexibility and customization. No Character Limit: Our design supports notes of any length without character limitations, unlike many apps that impose restrictions. Organized To-Do Lists: Completed to-do items are automatically moved to the bottom, keeping the list clean and organized, a feature that sets us apart from other apps. Rich Attachments: XXX supports unlimited picture attachments, drawing attachments, and voice recordings for notes, offering more versatility than many other apps. Advanced Security: XXX offers 3 different kinds of password lock mechanisms to protect note privacy, ensuring users have multiple options for securing their information. Powerful Reminders: Our app includes highly customizable reminders that can repeat daily, weekly, monthly, or yearly, making it easy for users to stay on top of their tasks and appointments. Due to the character limits of this form, I cannot list all the unique features of XXX. Please refer to our product description for a comprehensive overview. We are proud of our 5k user reviews with an average rating of 4.8, reflecting user satisfaction with XXX's unique features. Here's are some of the recent reviews. (United states only. Please kindly contact me to obtain full list of the reviews) by ??? – Jun 14, 2024 omg i cannot explain how much i love XXX like unlike the boring notes app this one is actually fun to use and rlly easy and i rlly like the fonts, color, to do list, calandar that can remind you like every day, week, month, and year like omg?!?!? i love XXX and this app is going in like my "I 💖U" folder like tysm for making XXX idk what i would do without it like omg tysm i cant explain in words how much i love it💖💖💖💖💖💖💖💖💖💖💖💖💖💖 by ??? – May 12, 2024 I love it sooo much I give it a 5 because there is a password so no one can look by ??? – Apr 30, 2024 Perfect app. All in one by ??? – Mar 26, 2024 I just downloaded this app a few days ago and I love it!! 😃 Up til recently I ALWAYS used paper sticky notes that I would have on my desk - and the reason why is because I could see everything all at once at all times; it’s very convenient - but it also produces clutter and anxiety because every subject is all in one place. XXX fixed that!! 😀 With tabs and the list or grid view mode, I can have more organization of subjects and still see almost everything all at once! I love it! 🤩 suggestion I would really love to have more format options for the text! 🙂 Like a button to indent, and be able to have sub notes with points, dashes, or numbers. It makes everything look more tidy and neat. Thank you for this wonderful app! 😆 I am available at 123-456-789 to discuss further and provide additional detail. Thank you. Till to date, I haven't received reply from the reviewer. May I know, what are some other actionable items I can do, so that I can get through "Guideline 4.3(a) - Design - Spam" app update rejection? Thank you so much!
1
0
1.2k
Aug ’24
When using NSCollectionLayoutSection.list, how to specific header height and cell item height?
I am using NSCollectionLayoutSection.list as follow. private func layoutConfig() -> UICollectionViewCompositionalLayout { let layout = UICollectionViewCompositionalLayout { section, layoutEnvironment in var config = UICollectionLayoutListConfiguration(appearance: .plain) config.headerMode = .supplementary config.footerMode = .none config.showsSeparators = false config.headerTopPadding = 0 // https://developer.apple.com/forums/thread/759987 let layoutSection = NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment) layoutSection.interGroupSpacing = 0 layoutSection.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0) if let header = layoutSection.boundarySupplementaryItems.first(where: { $0.elementKind == UICollectionView.elementKindSectionHeader }) { header.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0) } return layoutSection } return layout } We provide our own custom header view and cell item view. Header View class HideShowHeader: UICollectionViewListCell { override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func systemLayoutSizeFitting(_ targetSize: CGSize) -> CGSize { // Ensure the cell fills the width of the collection view let size = CGSize( width: targetSize.width, height: 80 ) print(">>>> size \(size)") return size } } Cell Item View class TodoCell: UICollectionViewListCell { override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func systemLayoutSizeFitting(_ targetSize: CGSize) -> CGSize { // Ensure the cell fills the width of the collection view let size = CGSize( width: targetSize.width, height: 80 ) return size } } We would like to fine-tune the height of header and cell item. However, override systemLayoutSizeFitting doesn't work. May I know, when using NSCollectionLayoutSection.list, how to specific header height and cell item height? Thanks.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
0
Boosts
1
Views
502
Activity
Jul ’24
How to Simulate Subscription Cancellation with Products.storekit in Simulator?
Hi, Currently, instead of using a real device and test account for in-app purchase testing, we are using Products.storekit with the Simulator. Our app offers a subscription plan with a 3-day free trial. We would like to simulate the following test scenarios: User cancels the subscription within the 3-day free trial period. User cancels the subscription after the 3-day free trial period. However, in Xcode, under Debug > StoreKit > Manage Transactions..., we couldn’t find an option to simulate a subscription cancellation. There is an option to refund the purchase, but we believe this is not the same as a cancellation. Do you have any idea how we can simulate these two cases using Products.storekit and the Simulator? Thanks in advance!
Replies
1
Boosts
1
Views
120
Activity
Apr ’25
Unexpected Change in Apple Refund Handling CONSUMPTION_REQUEST - Impact on Subscription App with AI Backend
We offer a 3-day free trial, and our paywall clearly states that users will be charged after the trial ends. However, some users request refunds after the charge - even after fully using our app for days or even weeks. In some cases, refunds are approved despite the users having consumed our AI processing services for up to a month. Since our app relies on backend AI processing, each user session incurs a real cost. To prevent losses, we utilize RevenueCat’s CONSUMPTION_REQUEST system and have set our refundPreference to: "2. You prefer that Apple declines the refund". Until recently, Apple typically respected this preference, and 90% of refund requests were declined as intended. However, starting about a week ago, we observed a sudden reversal: Apple is now approving around 90% of refund requests, despite our refund preference. As a result, we are operating at a loss and have had to halt both our marketing campaigns and our 3-day free trial. We’re trying to understand whether this shift is due to a change in Apple’s refund policy, or if we need to handle CONSUMPTION_REQUEST differently on our end. Has anyone else experienced similar changes? Any insights would be greatly appreciated.
Replies
0
Boosts
1
Views
449
Activity
May ’25
The following simple function will cause Xcode 12E262 to have "Abort: trap 6"
The following simple function will cause Xcode 12E262 to have "Abort: trap 6" during compilation. import UIKit import CoreData class ViewController: UIViewController {     func xyz() {         let container = NSPersistentContainer(name: "xyz")         let batchUpdateRequest = NSBatchUpdateRequest(entityName: "xyz")         let batchUpdateResult = try! container.viewContext.execute(batchUpdateRequest) as? NSBatchUpdateResult         guard let batchUpdateResult = batchUpdateResult else { return }     }     override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.     } } We will not observe "Abort: trap 6", if under Build Settings, we are using "Optimize for Speed" in Debug, instead of "No Optimization" We can also avoid "Abort: trap 6", if we change the following code guard let batchUpdateResult = batchUpdateResult else { return } to guard let batchUpdateResult2 = batchUpdateResult else { return } May I know, why is it so? A simpler code example to reproduce problem, without CoreData would be import UIKit class ViewController: UIViewController {     func getAny() throws -> Any? {         return nil     }     func xyz() {         let name = try! getAny() as? UIViewController         guard let name = name else { return }     }     override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.     } }
Replies
2
Boosts
0
Views
985
Activity
Jun ’21
Why an invisible same cell is being updated when update is performing using NSFetchedResultsController and Diffable Data Source?
Introduction I expect when I perform "update" on 1 of the CoreData entity content, corresponding UICollectionViewCell should updated seamlessly. But, the thing doesn't work as expected. After debugging, I notice that instead of updating visible UICollectionViewCell on screen, an invisible offscreen UICollectionViewCell has been created and all update operations are performed on the invisible UICollectionViewCell?! Simple hookup between NSFetchedResultsController and Diffable Data Source The hookup is pretty straightforward extension ViewController: NSFetchedResultsControllerDelegate { func controller(_ fetchedResultsController: NSFetchedResultsController<NSFetchRequestResult>, didChangeContentWith snapshotReference: NSDiffableDataSourceSnapshotReference) { guard let dataSource = self.dataSource else { return } let snapshot = snapshotReference as NSDiffableDataSourceSnapshot<Int, NSManagedObjectID> print("dataSource.apply") dataSource.apply(snapshot, animatingDifferences: true) { } } } Simple data structure import Foundation import CoreData extension NSTabInfo { @nonobjc public class func fetchRequest() -> NSFetchRequest<NSTabInfo> { return NSFetchRequest<NSTabInfo>(entityName: "NSTabInfo") } @NSManaged public var name: String? @NSManaged public var order: Int64 } extension NSTabInfo : Identifiable { } Simple data source to update cell private func initDataSource() { let dataSource = DataSource( collectionView: collectionView, cellProvider: { [weak self] (collectionView, indexPath, objectID) -> UICollectionViewCell? in guard let self = self else { return nil } guard let cell = collectionView.dequeueReusableCell( withReuseIdentifier: "cell", for: indexPath) as? CollectionViewCell else { return nil } guard let nsTabInfo = self.getNSTabInfo(indexPath) else { return nil } cell.label.text = nsTabInfo.name print("Memory for cell \(Unmanaged.passUnretained(cell).toOpaque())") print("Content for cell \(cell.label.text)\n") return cell } ) self.dataSource = dataSource } Updating code doesn't work We perform update on the 1st cell using the following code @IBAction func updateClicked(_ sender: Any) { let backgroundContext = self.backgroundContext backgroundContext.perform { let fetchRequest = NSFetchRequest<NSTabInfo>(entityName: "NSTabInfo") fetchRequest.sortDescriptors = [ NSSortDescriptor(key: "order", ascending: true) ] do { let nsTabInfos = try fetchRequest.execute() if !nsTabInfos.isEmpty { // Perform update on the first cell nsTabInfos[0].name = "\(Int(nsTabInfos[0].name!)! + 1)" if backgroundContext.hasChanges { try backgroundContext.save() } } } catch { print("\(error)") } } } Nothing is changed on the screen. However, if we look at the print output. We can see the initial content ("0") of the 1st cell is updated to "1". But, all of these are being done in an invisible same instance cell. dataSource.apply Memory for cell 0x0000000138705cd0 Content for cell Optional("1") Memory for cell 0x0000000138705cd0 Content for cell Optional("1") Memory for cell 0x0000000138705cd0 Content for cell Optional("2") Memory for cell 0x0000000138705cd0 Content for cell Optional("3") Ordering work without issue Changing the ordering of the cell works as expected. The following is the code for charging ordering. @IBAction func moveClicked(_ sender: Any) { let backgroundContext = self.backgroundContext backgroundContext.perform { let fetchRequest = NSFetchRequest<NSTabInfo>(entityName: "NSTabInfo") fetchRequest.sortDescriptors = [ NSSortDescriptor(key: "order", ascending: true) ] do { let nsTabInfos = try fetchRequest.execute() for (index, element) in nsTabInfos.reversed().enumerated() { element.order = Int64(index) } if backgroundContext.hasChanges { try backgroundContext.save() } } catch { print("\(error)") } } } Do you have idea why such problem occur? I prefer not to have collectionView.reloadData as workaround, as it will create more issue (like resetting scroll position, cell press state, ...) I posted a complete demo at https://github.com/yccheok/problem-update-frc-diffable Thank you
Replies
1
Boosts
0
Views
1.3k
Activity
Jul ’21
Should I use weak to avoid from interferencing with CoreData memory management?
Currently, I have the following core data backed collection view, which enable users to perform add/ delete/ modify/ reordering. It will be much more convenient to achieve what I, if I let UICollectionViewCell, to hold its corresponding NSManagedObject. So that I can each perform add/ delete/ modify/ reordering. I was wondering, should I mark the NSManagedObject as weak, to avoid from interferencing with how CoreData manage its memory? Using weak class TabInfoSettingsCell: UICollectionViewCell { // NSManagedObject. Use weak, as we do not want to inteference with how CoreData manage its memory. private weak var nsTabInfo : NSTabInfo? Use strong Or, such concern is invalid. We can simply use strong class TabInfoSettingsCell: UICollectionViewCell { // NSManagedObject. private var nsTabInfo : NSTabInfo? Use struct Or, such concern is valid and using weak is unsafe (as it can become nil in some edge case?). We can use a struct, which contains everything including objectID, but excluding NSManagedObjectContext. class TabInfoSettingsCell: UICollectionViewCell { // struct. Contains everything including objectID, but excluding NSManagedObjectContext. private var tabInfo : TabInfo? This come with the cost of having to create a struct out from NSManagedObject each time, in cellForItemAt. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { ... tabInfoSettingsCell.update(nsTabInfo.toTabInfo()) ... } May I know, which is the correct design, as far as safe memory management is concerned?
Replies
1
Boosts
0
Views
709
Activity
Jun ’21
Is NSAsynchronousFetchRequest suitable for production app?
NSAsynchronousFetchRequest seems like an answer to read large amount of data from CoreData, without blocking main thread. But, it is lacking some key features, provided by NSFetchedResultsController. The key features are :- In NSFetchedResultsControllerDelegate didChange and controllerDidChangeContent, we automatically receive a complete change information of persistence store. This enables us to implement the animation of add/delete/move/modify in collection view. Always listen to DB changes. Whenever there is changes being written into the persistence store, NSFetchedResultsControllerDelegate didChange and controllerDidChangeContent will be triggered automatically. This enables us to ensure our UI is in sync with DB. But, NSAsynchronousFetchRequest doesn't come with NSAsynchronousFetchedResultsController :( I was wondering, if you were using NSAsynchronousFetchRequest, how do you implement Animation changes on collection view? Always listen to DB change? My initial thought for animation changes on collection view, it seems we can utilise UICollectionViewDiffableDataSource. But, I notice it might be highly memory inefficient to do so. We need to keep ALL NSManagedObject in memory, fire all faults during comparison. It looks like we will run out of memory, if there are many rows. May I know, how do you achieve the following features, if you ever apply NSAsynchronousFetchRequest in production app? Animation changes on collection view? Always listen to DB change? Thanks.
Replies
1
Boosts
0
Views
811
Activity
Jul ’21
Is restore button still required if we were using StoreKit2 Transaction.currentEntitlements
Since StoreKit2 Transaction.currentEntitlements will able to return us user current owned purchased, during app startup. If that is the case, is it still necessary for developer to provide a restore button? If we still need to provide a restore button, what should the restore button do and what API should it call? Thanks
Replies
1
Boosts
0
Views
1.5k
Activity
Apr ’22
AVFAudio - Is it safe to perform file copy immediately after AVAudioRecorder.stop()
We start a voice recording via self.avAudioRecorder = try AVAudioRecorder( url: self.recordingFileUrl, settings: settings ) self.avAudioRecorder.record() At certain point, we will stop the recording via self.avAudioRecorder.stop() I was wondering, is it safe to perform file copy on self.recordingFileUrl immediately, after self.avAudioRecorder.stop()? Is all recording data has been flushed to self.recordingFileUrl and self.recordingFileUrl file is closed properly?
Replies
1
Boosts
0
Views
1.4k
Activity
May ’22
Is there any special handling required in StoreKit2, to handle promo code redemption?
My users will redeem promo code via app store (outside my app) Currently, I am using StoreKit2 to Query Transaction.currentEntitlements during app startup Keep listening to Transaction.updates I was wondering, is that is so, is there any special code required, to handle Promo code redeem from user? I guess by keep listening to Transaction.updates, will able to handle such case? But, I am not able to test that, without rolling out my app to production. Thanks.
Replies
1
Boosts
0
Views
809
Activity
Sep ’22
Stability of XCode 14
My XCode 13+ was used at MacBook Pro (13-inch, M1, 2020, 16G RAM) without issue Even since updated XCode to 14 week ago, I experience slowness while typing in XCode, and other editing operation. and, this crash happens few times a day Does anyone experience the same thing as I do? Thanks.
Replies
1
Boosts
0
Views
686
Activity
Sep ’22
Is there a way to override the theme of WidgetKit, so that we can retrieve correct named color in WidgetKit?
In main app, I can override dark/ light theme based on user preference, so that I can retrieve correct color information based on named color. if (user preference) { overrideUserInterfaceStyle = .light } else { overrideUserInterfaceStyle = .dark } // Dark theme/ light theme automatic aware color. SwiftUI.Color("purpleColor") However, how can I override the theme of a WidgetKit, so that my WidgetKit can interpret named color correctly? I know in WidgetKit, I can read what is current system wide theme settings using  @Environment(\.colorScheme) But, that is not what I want. I want the ability to override theme of a WidgetKit based on user preference, then able to retrieve correct named color. Thanks.
Replies
1
Boosts
0
Views
1k
Activity
Aug ’24
What is a reliable way, to check user system locale is using 12-hours or 24-hours format?
We would like to know, whether a user system locale is using 12-hours or 24-hours format? There are many proposed solutions at https://stackoverflow.com/q/1929958/72437 One of the solutions are let formatString = DateFormatter.dateFormat(fromTemplate: "j", options: 0, locale: Locale.current)! let hasAMPM = formatString.contains("a") However, to me, this is not a correct solution. When I tested with de_DE (German is using 24-hours), the returned string is HH 'Uhr' What is Uhr mean for? I guess it mean "clock" in German? There are so many other locales and one of them might contain letter a. Does anyone know, what is a correct way, to check whether user system locale is using 12-hours or 24-hours format?
Replies
3
Boosts
0
Views
902
Activity
Feb ’23
UISheetPresentationController: Remove Dim Background but Keep Touch-to-Dismiss?
I'm using the UISheetPresentationController to present a view, as shown in the following code: @IBAction func click(_ sender: Any) { let whiteViewController = WhiteViewController.instanceFromMainStoryBoard() if let sheet = whiteViewController.sheetPresentationController { sheet.detents = [.medium()] sheet.prefersScrollingExpandsWhenScrolledToEdge = false sheet.prefersGrabberVisible = false // Remove dim effect. ////sheet.largestUndimmedDetentIdentifier = .medium } self.present(whiteViewController, animated: true) } The outcome is as follow This code results in a presentation with: A dimmed background. A 'Touch anywhere to dismiss' behavior. However, I want to remove the dim background while keeping the 'Touch anywhere to dismiss' functionality. When I add the line: sheet.largestUndimmedDetentIdentifier = .medium The dim background is indeed removed, but the touch-to-dismiss behavior is gone too, as illustrated: Is there a way to achieve both – removing the dim background and retaining the touch-to-dismiss functionality? Thank you.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
1
Boosts
0
Views
2.1k
Activity
Oct ’23
What are some other actionable items I can do, so that I can get through "Guideline 4.3(a) - Design - Spam" app update rejection?
I have an app which is in the app store since 2022. It is an app with combined features of note taking, todo list and calendar. My most recent app update is rejected with the following message. Guideline 4.3(a) - Design - Spam We noticed your app shares a similar binary, metadata, and/or concept as apps submitted to the App Store by other developers, with only minor differences. Submitting similar or repackaged apps is a form of spam that creates clutter and makes it difficult for users to discover new apps. Next Steps Since we do not accept spam apps on the App Store, we encourage you to review your app concept and submit a unique app with distinct content and functionality. Resources Some factors that contribute to a spam rejection may include: Submitting an app with the same source code or assets as other apps already submitted to the App Store Creating and submitting multiple similar apps using a repackaged app template Purchasing an app template with problematic code from a third party Submitting several similar apps across multiple accounts Learn more about our requirements to prevent spam in App Review Guideline 4.3(a). Support Reply to this message in your preferred language if you need assistance. If you need additional support, use the Contact Us module. Consult with fellow developers and Apple engineers on the Apple Developer Forums. Help improve the review process or identify a need for clarity in our policies by suggesting guideline changes. I reply the reviewer with the following message. Hi, I am writing to appeal the rejection of my app, XXX. I would like to emphasize the unique aspects of XXX that distinguish it from other apps in the market: Integrated Functionality: Unlike most apps that are standalone note-taking, to-do, or calendar apps, XXX uniquely combines all three functions into a single app. Extensive Calendar Features: XXX includes a comprehensive calendar feature covering holidays in 250 countries and 3,680 states and provinces, a rare and valuable feature. Chinese Lunar Calendar: Our app includes a Chinese Lunar Calendar, which is highly appreciated in the Taiwanese market, adding a culturally specific feature not commonly found in other apps. Organizational Tools: XXX allows unlimited tabs and colors for organizing notes, surpassing many competitors who offer limited color options. Flexible Viewing and Sorting Modes: Users can choose from four viewing modes (Grid, Compact Grid, List, Compact List) and five sorting modes (Modified Time, Created Time, Alphabet, Color, Check, Reminder), enhancing the user experience by providing flexibility and customization. No Character Limit: Our design supports notes of any length without character limitations, unlike many apps that impose restrictions. Organized To-Do Lists: Completed to-do items are automatically moved to the bottom, keeping the list clean and organized, a feature that sets us apart from other apps. Rich Attachments: XXX supports unlimited picture attachments, drawing attachments, and voice recordings for notes, offering more versatility than many other apps. Advanced Security: XXX offers 3 different kinds of password lock mechanisms to protect note privacy, ensuring users have multiple options for securing their information. Powerful Reminders: Our app includes highly customizable reminders that can repeat daily, weekly, monthly, or yearly, making it easy for users to stay on top of their tasks and appointments. Due to the character limits of this form, I cannot list all the unique features of XXX. Please refer to our product description for a comprehensive overview. We are proud of our 5k user reviews with an average rating of 4.8, reflecting user satisfaction with XXX's unique features. Here's are some of the recent reviews. (United states only. Please kindly contact me to obtain full list of the reviews) by ??? – Jun 14, 2024 omg i cannot explain how much i love XXX like unlike the boring notes app this one is actually fun to use and rlly easy and i rlly like the fonts, color, to do list, calandar that can remind you like every day, week, month, and year like omg?!?!? i love XXX and this app is going in like my "I 💖U" folder like tysm for making XXX idk what i would do without it like omg tysm i cant explain in words how much i love it💖💖💖💖💖💖💖💖💖💖💖💖💖💖 by ??? – May 12, 2024 I love it sooo much I give it a 5 because there is a password so no one can look by ??? – Apr 30, 2024 Perfect app. All in one by ??? – Mar 26, 2024 I just downloaded this app a few days ago and I love it!! 😃 Up til recently I ALWAYS used paper sticky notes that I would have on my desk - and the reason why is because I could see everything all at once at all times; it’s very convenient - but it also produces clutter and anxiety because every subject is all in one place. XXX fixed that!! 😀 With tabs and the list or grid view mode, I can have more organization of subjects and still see almost everything all at once! I love it! 🤩 suggestion I would really love to have more format options for the text! 🙂 Like a button to indent, and be able to have sub notes with points, dashes, or numbers. It makes everything look more tidy and neat. Thank you for this wonderful app! 😆 I am available at 123-456-789 to discuss further and provide additional detail. Thank you. Till to date, I haven't received reply from the reviewer. May I know, what are some other actionable items I can do, so that I can get through "Guideline 4.3(a) - Design - Spam" app update rejection? Thank you so much!
Replies
1
Boosts
0
Views
1.2k
Activity
Aug ’24