Foundation

RSS for tag

Access essential data types, collections, and operating-system services to define the base layer of functionality for your app using Foundation.

Posts under Foundation tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Diagnosing iOS disc contention impacting networking?
When my app launches, it makes maybe 9 or so network requests to load initial data. It also reads some data from disc. Sporadically, I'm seeing an issue where some of the network requests succeed, but anything involving reading from disc does not load immediately. I'm able to move around in the app, tap buttons, swap tabs, swipe pages, so my main actor isn't stuck. Other data that don't involve disc reading / writing is also blank. About 2 minutes in, suddenly everything loads (both stuff from disc and stuff from the network), nearly instantly, the way it should have done when the app launched. Server logs show more initial network requests succeed than we can see data loaded in the app, and then about 2 minutes later, there's a flood of the rest of the requests which then succeed. The responses to some of these initial network requests cause us to make other network requests, and the sever sees some of those start right away. However, other consequences of these first requests are to touch the disc (to search for manually-cached data), and anything that is supposed to happen after that does not succeed until the 2 minute mark. But what bothers me is some things in the app which don't touch the disc also seem to have successful network requests. I'm seeing it on an iPhone 14Pro running iOS 18.2.1, with 607 GB of disc space available. When I take screenshots of the loading screens in my app during the apparent freeze, the clock in the screenshots are right - they reflect the clock at the moment I took the screenshot, but the EXIF data in all dozen or so images shows the exact second 2 minutes later when the server gets the resulting flood of network requests. Screenshots taken after the freeze is over have exif timestamps that match the screenshots, as short as 5 seconds after the freeze ends. The screenshot file names, though sequential, are out of order. for instance, some screenshots from 12:58 have file names numbered after screenshots taken at 12:59. but not all are out of order. This seems like disc contention has spread outside the app, and is impacting the system writing the images to disc. How do I diagnose a cause for this? How does disc contention affect the networking? I have caching turned off for my network requests. We only have a manual image cache, but I don't know how that would stall the display of data that should fetch and display without attempting to hit the image cache. This happens maybe a couple of times a day for some people, maybe once every couple of weeks for others, but of course, it never when we're trying to debug it.
9
0
401
Mar ’25
ar Locale default numbering system different between iOS 17 and iOS 18
Hi there The behaviour of using Locale(identifier: "ar") with NumberFormatter.locale appears to have changed between iOS 17 and iOS 18. Is this expected? Steps to reproduce import UIKit func numberFormatter(withlocaleString localeString: String) -> NumberFormatter { let locale = Locale(identifier: localeString) let numberFormatter = NumberFormatter() numberFormatter.locale = locale return numberFormatter } let numbers = 0...9 let localeDigits = numbers let ar_digits = localeDigits.compactMap { numberFormatter(withlocaleString: "ar").string(for: $0)?.first } print(ar_digits) Results The results show: **** numbering system on iOS 17 latn numbering system on iOS 18. iOS Output iOS 17 ["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"] iOS 18 ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
1
0
437
Feb ’25
Confusion About Objective-C's Memory Management (Cocoa)
Hello everyone, There is one thing about Objective-C's memory management that confuses me, which is a returned object's lifetime from methods with names doesn't start with "alloc", "new", "copy", or "mutableCopy". Take this as an example, when using NSBitmapImageRep's representationUsingType:properties: method, it returns an NSData object (reference: https://developer.apple.com/documentation/appkit/nsbitmapimagerep/representation(using:properties:)?language=objc). While testing this out, the NSData seemed to be an owned object (it doesn't get released until the end of the program). From what I understand, this may be an auto-released object which is released at the end of an autorelease pool block. Could someone explain this in more detail? What if I want to release that NSData object before the end of the autorelease pool block? How can I know which object is autoreleased, borrowed, or owned?
3
0
582
Jan ’25
NSTask launchRequirementData
I've noticed that NSTaks has this property as of macOS 14.4 @property (nullable, copy) NSData *launchRequirementData API_AVAILABLE(macos(14.4)) API_UNAVAILABLE(ios, watchos, tvos, visionos); It has no documentation whatsoever. Even google search has no clue. Does this have anything to do with code signature requirements validation? Any explanations and examples would be appreciated!
2
0
519
Jan ’25
[NSUserDefaults(NSUserDefaults) _initWithSuiteName:container:] Crash
In iOS 18, we encountered a crash: Thread 4 name: com.apple.root.user-interactive-qos Thread 4 Crashed: 0 CoreFoundation 0x18c4f9b10 __CFCheckCFInfoPACSignature + 4 1 CoreFoundation 0x18c53ed64 CFBundleGetInfoDictionary + 24 2 CoreFoundation 0x18c53ed1c CFBundleGetIdentifier + 16 3 Foundation 0x18b153740 -[NSUserDefaults(NSUserDefaults) _initWithSuiteName:container:] + 84 4 UIKitCore 0x18ef26ef0 ___UIKitUserDefaults_block_invoke + 40 5 libdispatch.dylib 0x1941ee0d0 _dispatch_client_callout + 20 6 libdispatch.dylib 0x1941ef918 _dispatch_once_callout + 32 7 UIKitCore 0x18ef9de28 _UIKitUserDefaults + 80 8 UIKitCore 0x18f058a7c ___UIKitPreferencesOnce_block_invoke + 20 9 libdispatch.dylib 0x1941ee0d0 _dispatch_client_callout + 20 10 libdispatch.dylib 0x1941ef918 _dispatch_once_callout + 32 11 UIKitCore 0x18f056c8c _UIKitPreferencesOnce + 80 12 UIKitCore 0x18f0563b8 ___UIApplicationMainPreparations_block_invoke + 20 13 libdispatch.dylib 0x1941ec370 _dispatch_call_block_and_release + 32 14 libdispatch.dylib 0x1941ee0d0 _dispatch_client_callout + 20 15 libdispatch.dylib 0x1941fff60 _dispatch_root_queue_drain + 860 16 libdispatch.dylib 0x194200590 _dispatch_worker_thread2 + 156 17 libsystem_pthread.dylib 0x2136ffc40 _pthread_wqthread + 228 18 libsystem_pthread.dylib 0x2136fc488 start_wqthread + 8 Below image show more details: And after set a symbol breakpoint: [NSUserDefaults _initWithSuiteName:container:] We found that at the beginning of app launch, the system will call it: It not always crash, but sometimes especially when app upgrade, what the root cause maybe?
2
0
293
Jan ’25
[NSUserDefaults(NSUserDefaults) _initWithSuiteName:container:] Crash
When using: [[NSUserDefaults alloc] initWithSuiteName:@"TestSuiteName"]; It sometimes cause crash, the crash detail is: Thread 4 name: com.apple.root.user-interactive-qos Thread 4 Crashed: 0 CoreFoundation 0x1963f9b10 __CFCheckCFInfoPACSignature + 4 1 CoreFoundation 0x19643ed64 CFBundleGetInfoDictionary + 24 2 CoreFoundation 0x19643ed1c CFBundleGetIdentifier + 16 3 Foundation 0x195053740 -[NSUserDefaults(NSUserDefaults) _initWithSuiteName:container:] + 84 4 UIKitCore 0x198e26ef0 ___UIKitUserDefaults_block_invoke + 40 5 libdispatch.dylib 0x19e0ee0d0 _dispatch_client_callout + 20 6 libdispatch.dylib 0x19e0ef918 _dispatch_once_callout + 32 7 UIKitCore 0x198e9de28 _UIKitUserDefaults + 80 8 UIKitCore 0x198f58a7c ___UIKitPreferencesOnce_block_invoke + 20 9 libdispatch.dylib 0x19e0ee0d0 _dispatch_client_callout + 20 10 libdispatch.dylib 0x19e0ef918 _dispatch_once_callout + 32 11 UIKitCore 0x198f56c8c _UIKitPreferencesOnce + 80 12 UIKitCore 0x198f563b8 ___UIApplicationMainPreparations_block_invoke + 20 13 libdispatch.dylib 0x19e0ec370 _dispatch_call_block_and_release + 32 14 libdispatch.dylib 0x19e0ee0d0 _dispatch_client_callout + 20 15 libdispatch.dylib 0x19e0fff60 _dispatch_root_queue_drain + 860 16 libdispatch.dylib 0x19e100590 _dispatch_worker_thread2 + 156 17 libsystem_pthread.dylib 0x21d7dfc40 _pthread_wqthread + 228 18 libsystem_pthread.dylib 0x21d7dc488 start_wqthread + 8 and for more detail crash info can see the attachment image . And Refer to the API's description: /// -initWithSuiteName: initializes an instance of NSUserDefaults that searches the shared preferences search list for the domain 'suitename'. For example, using the identifier of an application group will cause the receiver to search the preferences for that group. Passing the current application's bundle identifier, NSGlobalDomain, or the corresponding CFPreferences constants is an error. Passing nil will search the default search list. - (nullable instancetype)initWithSuiteName:(nullable NSString *)suitename API_AVAILABLE(macos(10.9), ios(7.0), watchos(2.0), tvos(9.0)) NS_DESIGNATED_INITIALIZER; It seems using a constants string is a wrong way. Does any one know what to root cause?
2
0
345
Jan ’25
URLComponents bug in 18.x
Prior to 18.x, this has worked for years. However, if a port is included, the behavior in 18.x is to return "///some/path". In all previous versions it correctly returns "/some/path". Is this a bug, or documented change we missed? func relativeURLString(for urlString: String) -> String? { guard var components = URLComponents(string: urlString) else { return nil } components.host = nil components.scheme = nil // WE FOUND IF YOU NIL THE PORT BEFORE HOST AND SCHEME, IT WORKS components.port = nil return components.string }
4
0
331
Jan ’25
How to get the real app language code + variation?
Hello, I have the app localised to many languages and its variants, like English from Australia or Dutch from Belgium. My phone language is en_UK and the region is configured to ES. I cannot find a way to get the regional language code (ex: en_au, nl_be), it always gets simplified to the language (ex: en, nl), or adds my device region (ex: en-ES, nl-ES). Here I attach some examples while I have the app on en_au Locale.preferredLanguages ▿ 3 elements - 0 : "en-ES" - 1 : "ca-ES" - 2 : "es-ES" Bundle.main.preferredLocalizations ▿ 1 element - 0 : "en" NSLocale.current.languageCode ▿ Optional<String> - some : "en" Locale.current ▿ en_001@rg=eszzzz (fixed en_001@rg=eszzzz) - identifier : "en_001@rg=eszzzz" - locale : "fixed en_001@rg=eszzzz" Locale.autoupdatingCurrent.languageCode ▿ Optional<String> - some : "en" Locale.current.languageCode ▿ Optional<String> - some : "en" Locale.preferredLanguages[0] "en-ES"
2
0
906
Jan ’25
how to save the state when I open another APP ?
how to save the state of my APP when I open another APP so that It can restore when I re-open it? my app will use over 10mb memory so if I open another APP(my app will go background) it will closed at all. when I re-open it it will restart. but I do not want it I want if I open Page A and then it go background and when I re-open it it still is Page A and do not restart.
2
0
343
Feb ’25
Is it safe to access the contents of an app's bundle from within an app extension?
I've got some materials in an app's bundle (some info.plist values, and some images in .xcassets files etc.) If I access them from within an app extension (a notification service extension, notification content extension for example), then it appears to work. However while running the extensions in the debugger, there were some messages in the console saying the app bundle wasn't loaded. So despite it working, this message made me wonder if its not a safe practice and it working was luck and/or timing etc. and if the materials should instead be duplicated within the extension bundle and obtained from there instead of accessing them from the app bundle?
2
0
445
Jan ’25
CTCellularDatash kCTCellularDataNotRestricted -1009
Hello, we are processing the first network permission request transaction on iOS. We have found that when the CTCellularData is in the kCTCellularDataNotRestricted state and we attempt to perform a network access in the callback function, an exception is reported. How can we resolve this issue? I’ve seen that some solutions on the internet suggest adding a delay of 1 second. Are there any other methods?
1
0
186
Jan ’25
Manually calling the superclass's dealloc in the overridden dealloc method causes a crash
I have a class object created dynamically using Runtime, and I want to release some manually allocated memory resources when this object is deallocated. To achieve this, I added a custom implementation of the dealloc method using the following code: SEL aSel = NSSelectorFromString(@"dealloc"); class_addMethod(kvoClass, aSel, (IMP)custom_dealloc, method_getTypeEncoding(class_getInstanceMethod(kvoClass, aSel))); However, I encountered some issues. If I don't call the superclass's dealloc method in the cus_dealloc function, the superclass's dealloc implementation will not be executed. On the other hand, if I explicitly call the superclass's dealloc method, the program crashes. Here is the implementation of the cus_dealloc function: void custom_dealloc(id self, SEL _cmd) { // Release other memory ![]("https://developer.apple.com/forums/content/attachment/c7b0c16b-be23-4776-b8db-f22b661c5e7d" "title=iShot_2025-01-03_19.31.34.png;width=1080;height=1895") Class superClass = class_getSuperclass(object_getClass(self)); void (*originIMP)(struct objc_super *, SEL, ...) = (void *)objc_msgSendSuper; struct objc_super *objcSuper = &(struct objc_super){self, superClass}; originIMP(objcSuper, _cmd); } demo
3
0
692
Jan ’25
NSExpression error handling
Context: SwiftUI TextField with a String for simple math using NSExpression. I first prepare the input string to an extent but a malformed input using valid characters still fails, as expected. Let's say preparedExpression is "5--" let expr = NSExpression(format: preparedExpression) gives FAULT: NSInvalidArgumentException: Unable to parse the format string "5-- == 1"; (user info absent) How can I use NSExpression such that either the preparedExpression is pre-tested before asking for actual execution or the error is handled in a polite way that I can use to alert the user to try again. Is there a Swift alternative to NSExpression that I've missed?
3
0
496
Jan ’25
Basic HTML converted to NSAttributedString is not rendered correctly
We have a sample code that initialises an NSAttributed string with simple HTML code and the result differs massively since XCode 16 and iPadOS 18 SDK. DESCRIPTION OF PROBLEM Since Xcode Version 16.1 HTML content passed into an NSAttributedString is not rendered correctly. Specifically, enumeration characters (such as bullet points or numbers) and the proper indentation for text within list items are missing. As a result, the structure of the HTML content, especially ordered and unordered lists, is not displayed as expected. STEPS TO REPRODUCE A UILabel was added to the view in a new Objective-C project in Xcode. A HTML string containing and Tags was converted into an NSAttributedString (With NSAttributedString::initWithData and NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType Parameter)within the viewDidLoad method and assigned to the UILabel. Expected Result: The lists should be displayed correctly with enumeration characters and appropriate indentation, as shown in the attached screenshot expected_result.jpeg. Same Code still works as expected using XCode 15.x Actual Result: The list is displayed without enumeration characters or indentation, which matches the attached screenshot actual_result.jpeg. Sample Code NSString *html = @"Es ist wichtig, dass Sie Ihren Arzt informieren:\n<ol>\n\t<li><strong>HIER !!!!!!! </strong>Wenn Sie gegenw&auml;rtig mit Zometa&reg;, dass die gleiche aktive Substanz enth&auml;lt wie Aclasta&reg; behandelt werden.</li>\n</ol>\n\n<ul>\n\t<li><strong>Hier !!!!!!</strong> Wenn Sie Nierenbeschwerden haben oder hatten, denn Ihre Nieren m&uuml;ssen korrekt funktionieren, um das &uuml;berfl&uuml;ssige Aclasta &reg; das f&uuml;r Ihre Knochen nicht ben&ouml;tigt wird, ausscheiden zu k&ouml;nnen.</li>\n\t<li>Wenn sie Medikamente einnehmen, die Kortsion als Bestandteil enthalten (z. B. Prendisolon oder Dexamethason)</li>\n\t<li>Wenn sie unter schlechter Zahngesundheit oder Zahnfleischerkrankungen leiden oder wenn eine Zahnextraktion geplant ist</li>\n</ul>\n"; NSString *textAttr = [NSString stringWithFormat:@"<span style=\"font-family:Arial; line-height: 80%%; font-size:10px;\">%@</style>", html]; NSData *data = [textAttr dataUsingEncoding:NSUTF16StringEncoding]; NSAttributedString *string = [[NSAttributedString alloc] initWithData:data options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF16StringEncoding)} documentAttributes:nil error:nil]; self.label.numberOfLines = 0; self.label.attributedText = string; Greetings
4
1
955
Jan ’25
Camera settings at intrinsic calibration time
Hi everyone, I am wondering under which settings the camera(s) were set by the time they were calibrated. For instance, one aspect that is easy to find is the reference resolution of the images taken when calibrating the intrinsics, this is by retrieving intrinsicMatrixReferenceDimensions. Making sure that the principal point is referenced to the by the time resolution used when the calibration was ongoing. However, recently I saw that there are focusing modes that potentially displace the lens' physical position. Settings like: AutoFocusRangeRestriction: none, near, far setFocusModeLocked: Locks the lens position at the specified value, and sets the focus mode to a locked state. My concern lies the impact this focusing lens displacements can have on the intrinsic matrix parameters, like these parameters no longer describe the camera since the lens position has changed. In simple words, what is the focus 'mode'/'range' the cameras were set when calibrating them for intrnisics?
0
0
475
Jan ’25
How to save a point cloud in the sample code "Capturing depth using the LiDAR camera" with the photoOutput
Hello dear community, I have the sample code from Apple “CapturingDepthUsingLiDAR” to access the LiDAR on my iPhone 12 Pro. My goal is to use the “photo output” function to generate a point cloud from a single image and then save it as a ply file. So far I have tested different approaches to create a .ply file from the depthmap, the intrinsic camera data and the rgba values. Unfortunately, I have had no success so far and the result has always been an incorrect point cloud. My question now is whether there are already approaches to this and whether anyone has any experience with it. Thank you very much in advance!!!
1
0
490
Jan ’25
Crash:Exceeded system-wide per-process Port Limit
Hi everyone, I’m encountering a crash in my app and need help understanding what’s causing it and how to resolve it. As stated in the crash report, the issue is caused by exceeding the system-wide per-process port limit. Can you tell me how to locate and identify why this is happening? Below are the full report of the crash log: crash.log Summary of Crash: ------------------------------------- Translated Report (Full Report Below) ------------------------------------- Incident Identifier: B509FF2B-C8D8-4E9F-B664-E24464CFD5F8 CrashReporter Key: b390cfe931a83efde49bd8b523023a275b55ef64 Hardware Model: iPhone14,2 Process: MyApp [22515] Path: /private/var/containers/Bundle/Application/F73212A7-4CB9-485A-A8B7-8114F4E9A9AB/MyApp.app/MyApp Identifier: com.beeasy.app.id.enterprise Version: 3.41.38-ID-MySDKMemory-12261114 (3.41.38-ID-MySDKMemory-12261114) Code Type: ARM-64 (Native) Role: Foreground Parent Process: launchd [1] Coalition: com.beeasy.app.id.enterprise [515] Date/Time: 2024-12-29 01:29:48.3023 +0800 Launch Time: 2024-12-26 16:38:36.7895 +0800 OS Version: iPhone OS 16.6.1 (20G81) Release Type: User Baseband Version: 2.80.01 Report Version: 104 Exception Type: EXC_RESOURCE (SIGKILL) Exception Codes: 0x000000000001c1d6, 0x0000000000000000 Termination Reason: PORT_SPACE 14123288431433990614 (Limit 115158 ports) Exceeded system-wide per-process Port Limit Triggered by Thread: 64 Thread 64 name: AURemoteIO::IOThread Thread 64 Crashed: 0 libsystem_kernel.dylib 0x20ce5eca4 mach_msg2_trap + 8 1 libsystem_kernel.dylib 0x20ce71b74 mach_msg2_internal + 80 2 libsystem_kernel.dylib 0x20ce71e4c mach_msg_overwrite + 540 3 libsystem_kernel.dylib 0x20ce5f1e8 mach_msg + 24 4 libEmbeddedSystemAUs.dylib 0x238bb2148 void* caulk::thread_proxy<std::__1::tuple<caulk::thread::attributes, AURemoteIO::IOThread::IOThread(AURemoteIO&, caulk::thread::attributes const&, caulk::mach::os_workgroup_managed const&)::'lambda'(), std::__1::tuple<>>>(void*) + 556 5 libsystem_pthread.dylib 0x22dcda6b8 _pthread_start + 148 6 libsystem_pthread.dylib 0x22dcd9b88 thread_start + 8
3
0
588
Jan ’25