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.

Pinned Posts

Posts under Foundation tag

293 Posts
Sort by:
Post not yet marked as solved
1 Replies
10 Views
I am seeing this crashes in 15.5 version, I am using flutter code base seeing like this and dlyd issues many crashes
Posted
by ajayextra.
Last updated
.
Post not yet marked as solved
0 Replies
51 Views
I need any kind of help I can get on this question and am open to any solutions or workarounds. When I archive FileManager.ubiquityIdentityToken with NSKeyedArchiver.archivedData(withRootObject:requiringSecureCoding:), what should I set the second parameter to in order to be able to unarchive later, and how do I unarchive the Data object using unarchivedObject(ofClass:from:) or any other method of NSKeyedUnarchiver? My code currently uses the deprecated method of archivedData(withRootObject:), which gives me a code time warning saying: 'archivedData(withRootObject:)' was deprecated in iOS 12.0: Use +archivedDataWithRootObject:requiringSecureCoding:error: instead I'm getting code time error messages in red for the argument to archivedData(withRootObject:requiringSecureCoding:) which is declared as type Any. I tried different arguments. The one I this should work is (NSCoding & NSCopying & NSObject).Type, which generates two error messages: Static method 'unarchivedObject(ofClass:from:)' requires that '(NSObject & NSCoding & NSCopying).Type' inherit from 'NSObject' Type '(NSObject & NSCoding & NSCopying).Type' cannot conform to 'NSCoding' Setting the argument to (NSCoding & NSCopying & NSObject) generates the error message: 'NSObject & NSCoding & NSCopying' cannot be used as a type conforming to protocol 'NSCoding' because 'NSCoding' has static requirements I haven't been able to discover what that means that 'NSCoding' has static I get the idea to use (NSCoding & NSCopying & NSObject) because when run code: print("type of FileManager.default.ubiquityIdentityToken: \(type(of: FileManager.default.ubiquityIdentityToken))") the debug window shows type of FileManager.default.ubiquityIdentityToken: Optional<NSCoding & NSCopying & NSObject> but when I run the following code print("type of FileManager.default.ubiquityIdentityToken: \(type(of: FileManager.default.ubiquityIdentityToken!))") I get the following in the debug window type of FileManager.default.ubiquityIdentityToken: _NSInlineData I read on stackoverflow that "_NSInlineData" is not made available to us by Apple. I'm open to doing this any other way, not necessarily with NSKeyedArchiver or NSKeyedUnarchiver, including using unsafe pointers if necessary. In one of Apple's documentation or sample Xcode projects, I found code to check the login status of a user on iOS when an app logs on by checking FileManager.ubiquityIdentityToken and to check the current status with the previous status by checking the ubiquityIdentityToken that was saved in UserDefaults. Is there a better way of doing this?
Posted Last updated
.
Post not yet marked as solved
6 Replies
117 Views
I am trying to write a Swift standalone library to monitor a UserDefaults value and callback a function in Python. To do so, I need an event loop in the Swift code that allows the Observer code to run and, when needed, call the callback function. I am monitoring the default via a KVO Observer class, which inherits a NSObject with UserDefaults.standard.addObserver in its init and implements observeValue as callback. To keep the loop running, up to now I called RunLoop.current.run() in the end of the Swift library invoked function. As you can imagine, this works well when the library is called from a main thread, which can provide inputs to the RunLoop. On the other hand, this fails (the library returns immediately) when the function is invoked from a secondary thread without e.g. the stdin attached. I am looking for an alternative to RunLoop.current.run() that: runs indefinitely can run in a secondary thread with no inputs does not block callbacks to observeValue I tried the most obvious choices like an infinite while or DispatchQueue but so far I was not able to achieve what I need. Further details about the issue can be found in a related StackOverflow question here: https://stackoverflow.com/questions/72982210/swift-and-python-get-a-runloop-that-can-run-in-threading Thanks in advance for your help.
Posted
by asottile.
Last updated
.
Post marked as solved
1 Replies
61 Views
Our (legacy) code to communicate with peripherals on local IPv6 networks (LAN) adds the zone identifier / interface name ("%en0") to link-local IP addresses (FE80::/10) discovered via SSDP. SSDP is implemented using CocoaAsyncSocket - yes, that part of our code is old... (from before the introduction of the iOS 12+ Network framework). We use these modified IP addresses as the host component of a URL in a URLSession.dataTask. To insert the zone identifier we are using URLComponents (we modify the host and then request the string). This worked fine in iOS 15 and below, but no longer works in iOS 16 (Beta 1/2/3); the host is empty after inserting %en0 in the most recent beta. We have reported this via FB10549269, but from the answer it is unclear to me whether Apple is planning to fix this ("Resolution: Potential fix identified"), or we are doing it wrong. How should we handle IPv6 link-local addresses in iOS 16? (when using URLSession instead of Network) PS: We recently dropped support for iOS 12, but we still need to support iOS 13 and up
Posted
by phirk.
Last updated
.
Post not yet marked as solved
4 Replies
299 Views
is this a bug that NSDateFormatter knows about leap days but not about leap seconds? let f = DateFormatter() f.timeZone = TimeZone(identifier: "UTC") f.dateFormat = "yyyy/MM/dd HH:mm:ss" // last leap year let t1 = f.date(from: "2020/02/29 00:00:00") // 2020-02-29 00:00:00 UTC // last leap second let t2 = f.date(from: "2016/12/31 23:59:60") // nil
Posted Last updated
.
Post marked as solved
2 Replies
108 Views
According to the WWDC 21 Session https://developer.apple.com/videos/play/wwdc2021/10109/ It shows how can we describe custom attributes in markdown as followings: This text contains ^[an attribute](rainbow: 'extreme'). This text contains ^[two attributes](rainbow: 'extreme', otherValue: 42). This text contains ^[an attribute with 2 properties](someStuff: {key: true, key2: false}). So, the first one, I can guess how to create, and last one could archive with describing Value type as a Struct. However, I don't know how to handle the second case. CodableAttributedStringKey and MarkdownDecodableAttributedStringKey allow us to override decoding function. but that decoding function's Decoder can only accept to access to the value which comes from first attribute. Like rainbow's container. So how can we take the value in otherValue as 42?
Posted Last updated
.
Post not yet marked as solved
6 Replies
1.1k Views
I have received two strange crash reports from an iPad11,7 running iPadOS 15.1 and an iPad11,2 running iPadOS 15.2. On both occasions, the crashed thread calls CFURLRequestSetMainDocumentURL, which in turn calls _dispatch_source_set_runloop_timer_4CF in libdispatch, after which the application crashes with SIGSEGV and SEGV_MAPERR. The crashed thread's call stack is displayed below. Full crash logs are attached as well. What could this be? Exception Type: SIGSEGV Exception Codes: SEGV_MAPERR at 0x21d Crashed Thread: 20 Thread 20 Crashed: 0 libdispatch.dylib 0x00000001829e1784 _dispatch_source_set_runloop_timer_4CF + 36 1 CFNetwork 0x00000001834fc824 CFURLRequestSetMainDocumentURL + 2240 2 CFNetwork 0x00000001836b89a8 _CFNetworkErrorGetLocalizedDescription + 693652 3 CFNetwork 0x00000001834fdb1c CFURLRequestSetMainDocumentURL + 7096 4 CFNetwork 0x00000001834f3c34 CFURLRequestSetURL + 9668 5 libdispatch.dylib 0x00000001829ca914 _dispatch_call_block_and_release + 28 6 libdispatch.dylib 0x00000001829cc660 _dispatch_client_callout + 16 7 libdispatch.dylib 0x00000001829d3de4 _dispatch_lane_serial_drain + 668 8 libdispatch.dylib 0x00000001829d498c _dispatch_lane_invoke + 440 9 libdispatch.dylib 0x00000001829d5c74 _dispatch_workloop_invoke + 1792 10 libdispatch.dylib 0x00000001829df1a8 _dispatch_workloop_worker_thread + 652 11 libsystem_pthread.dylib 0x00000001f1eea0f4 _pthread_wqthread + 284 12 libsystem_pthread.dylib 0x00000001f1ee9e94 start_wqthread + 4 second_crashlog.txt report-2517628380750009999-e4d7ea06-6f22-4b7e-b129-045599e1dee5.txt
Posted
by datwelk.
Last updated
.
Post marked as solved
1 Replies
80 Views
NSMutableAttributedString does strange things with 𝛑 and 𝒆. This is Unicode "Mathematical Bold Small Pi" and the 𝒆 that is near it in the Unicode table. Less exotic characters don't have this problem. Changing the attribute map of an existing NSMutableAttributedString containing these characters with some foreground colors (like white, for instance) results in a strange doubling of the character when the resulting string is rendered in a CATextLayer. It doesn't happen if the NSMutableAttributedString is created with the different map. It only happens when you use #setAttributes on an existing string. Displaying an NSMutableAttributedString containing these characters with various colors applied in a UITextField results in the strange doubling regardless of the colors involved. Furthermore, attribute ranges are thrown off by this.
Posted Last updated
.
Post not yet marked as solved
3 Replies
95 Views
Has anyone else seen in Ventura B3 where you have a URL path as a source and you want to use the filename for that, aka lastPathComponent in a destination URL, so you have something like: let destinationURL = destinationDIrectory.appendingPathExtension(sourceURL.lastPathComponent) and lastPathComponent is a file name but what you get for destinationURL is: destinationDirectory.lastPathComponent instead of destinationDirectory/lastPathComponent or is it just me?
Posted Last updated
.
Post not yet marked as solved
0 Replies
65 Views
Problem My app needs to send an HTTP-like request over TCP, followed by periodic data and get back a stream of data in the foreground and background in return. In the background, I need to open and close the socket after receiving a Bluetooth characteristic value, which is an unnecessary overhead that slows the user down and may lead to a lot of lost data. Currently In the foreground, it opens an NSSocket (through a framework), sends the initial request and periodically sends and receives data. While in the background, the app is started when it receives a characteristic value from the bluetooth-central background mode. It then opens the socket to send some initial data, waits for some data in return, and closes the socket. Considerations The protocol I need to connect to is HTTP-like (NTRIP), so I considered using a URLSession, which can keep a socket open, even in the background. However, the protocol has some non-standard behaviors. Namely: It can return a SOURCETABLE response (interchangeable with HTTP/1.1). Some implementations have a non-standard second status line (e.g. HTTP/1.1 OK 200, followed by HTTP/1.1. Not Authorized 401). Some rare implementations incorrectly fail to separate the status line and message body with CRLF. The connection needs to be kept open to periodically send and receive data. A future revision of NTRIP does enforce HTTP compliance, but is not yet widely used.
Posted
by cj-.
Last updated
.
Post marked as solved
7 Replies
280 Views
Crashed: com.apple.main-thread 0 libsystem_kernel.dylib 0x7260 __pthread_kill + 8 1 libsystem_pthread.dylib 0x73c0 pthread_kill + 268 2 libsystem_c.dylib 0x20e74 abort + 180 3 libsystem_c.dylib 0x77940 err + 270 4 UIFoundation 0xde800 -[_NSOptimalLineBreaker _softHyphenPenaltyForBreak:].cold.1 + 42 5 UIFoundation 0x70ca4 -[_NSOptimalLineBreaker _breakPenaltyForHyphenationFactor:] + 174 6 UIFoundation 0x70cc8 -[_NSOptimalLineBreaker _breakPenaltyForHyphenationFactor:] + 36 7 UIFoundation 0x70d38 -[_NSOptimalLineBreaker _softHyphenPenaltyForBreak:] + 72 8 UIFoundation 0x70e7c -[_NSOptimalLineBreaker _demeritFromBreak:toBreak:usingExpansionRatio:] + 164 9 UIFoundation 0x725f4 -[_NSOptimalLineBreaker _createNodeWithParent:lineBreak:expansionRatio:] + 152 10 UIFoundation 0x72f84 __50-[_NSOptimalLineBreaker _calculateOptimalWrapping]_block_invoke + 144 11 CoreFoundation 0x6ea4 __CFSetApplyFunction_block_invoke + 28 12 CoreFoundation 0x29344 CFBasicHashApply + 148 13 CoreFoundation 0xd87c CFSetApplyFunction + 320 14 UIFoundation 0xb51f8 _CFSetApplyBlock + 60 15 UIFoundation 0x72a00 -[_NSOptimalLineBreaker _calculateOptimalWrapping] + 472 16 UIFoundation 0x93e8c -[NSParagraphArbitrator _computeOptimalLayout] + 252 17 UIFoundation 0x93ce4 -[NSParagraphArbitrator _optimalLineBreakContextBeforeIndex:lineFragmentWidth:range:] + 84 18 UIFoundation 0xa0b50 -[NSCoreTypesetter _createLineRefForParentLineRef:range:availableWidth:offset:paragraphArbitrator:lineBreakMode:hyphenated:forcedClusterBreak:] + 532 19 UIFoundation 0x1aecc -[NSCoreTypesetter _stringDrawingCoreTextEngineWithOriginalString:rect:padding:graphicsContext:forceClipping:attributes:stringDrawingOptions:drawingContext:stringDrawingInterface:] + 4536 20 UIFoundation 0x161c8 __NSStringDrawingEngine + 1284 21 UIFoundation 0x24cbc -[NSAttributedString(NSExtendedStringDrawing) boundingRectWithSize:options:context:] + 644 22 UIKitCore 0x1462f0 _UIComputedSizeForLabel + 452 23 UIKitCore 0x2676e0 -[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 700 24 UIKitCore 0x14e8e0 -[UILabel _intrinsicSizeWithinSize:] + 476 25 UIKitCore 0x259494 -[UILabel intrinsicContentSize] + 280 26 UIKitCore 0x155150 -[UIView _generateContentSizeConstraints] + 52 27 UIKitCore 0x1e68d8 -[UIView _updateContentSizeConstraints] + 244 28 UIKitCore 0x275b98 -[UIView(AdditionalLayoutSupport) _updateSystemConstraints] + 88 29 UIKitCore 0x2c5cc4 -[UIView(AdditionalLayoutSupport) _sendUpdateConstraintsIfNecessaryForSecondPass:] + 348 30 UIKitCore 0x13c5b8 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 764 31 UIKitCore 0x13c4d4 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 536 32 UIKitCore 0x13c4d4 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 536 33 UIKitCore 0x13c4d4 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 536 34 UIKitCore 0x13c4d4 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 536 35 UIKitCore 0x13c4d4 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 536 36 UIKitCore 0x13c4d4 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 536 37 UIKitCore 0x13c4d4 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 536 38 UIKitCore 0x13c4d4 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 536 39 CoreAutoLayout 0x787c -[NSISEngine withBehaviors:performModifications:] + 84 40 UIKitCore 0x1f42fc -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 508 41 UIKitCore 0x3986ec -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:] + 388 42 UIKitCore 0x13ff78 -[UIView _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 332 43 UIKitCore 0x13989c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1980 44 QuartzCore 0x3b380 CA::Layer::layout_if_needed(CA::Transaction*) + 500 45 QuartzCore 0x2d238 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 148 46 QuartzCore 0x41834 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 456 47 QuartzCore 0x4abd8 CA::Transaction::commit() + 652 48 QuartzCore 0x2c918 CA::Transaction::flush_as_runloop_observer(bool) + 88 49 UIKitCore 0x42c768 _UIApplicationFlushCATransaction + 52 50 UIKitCore 0x64f310 _UIUpdateSequenceRun + 84 51 UIKitCore 0xc72984 schedulerStepScheduledMainSection + 172 52 UIKitCore 0xc71fcc runloopSourceCallback + 92 53 CoreFoundation 0xb928c CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28 54 CoreFoundation 0xc9dc8 __CFRunLoopDoSource0 + 176 55 CoreFoundation 0x5d2c __CFRunLoopDoSources0 + 244 56 CoreFoundation 0xb4f4 __CFRunLoopRun + 836 57 CoreFoundation 0x1f080 CFRunLoopRunSpecific + 612 58 GraphicsServices 0x1360 GSEventRunModal + 164 59 UIKitCore 0x40afb4 -[UIApplication _run] + 888 60 UIKitCore 0x2116e8 UIApplicationMain + 340
Posted Last updated
.
Post not yet marked as solved
2 Replies
227 Views
Hi Apple Engineers, We are making an iOS app which uses NSURLSession for network communication. To provide enterprise customer the ability to monitor network traffic, we want to support proxy settings inside our app. So, we take advantage of the connectionProxyDictionary property of NSURLSessionConfiguration. We set the kCFNetworkProxiesProxyAutoConfigURLString key, and expect requests that are scripted to be proxied to either go through the proxy or fail when proxy is not reachable. This is necessary because we don't want requests to go out without being monitored. But during development we noticed that when proxy server is not reachable, requests don't always fail with kCFErrorHTTPProxyConnectionFailure or kCFErrorHTTPSProxyConnectionFailure (CFNetworkError 306 and 310). More specifically, the behavior we observed are as follows: PAC URL resolution timeout: Task failed with 306/310 PAC URL resolution error: Task bypassed proxy and succeeded PAC file download timeout: Task failed with 306/310 PAC file download error: Task bypassed proxy and succeeded PAC file parse error: Task bypassed proxy and succeeded Proxy server connection timeout: Task failed with 306/310 Proxy server connection error: Task bypassed proxy and succeeded The inconsistency of error handling behavior is confusing, is this a bug? If not, is there a way to configure NSURLSession to always yield error without bypassing the proxy when any of the above happens?
Posted
by yueqiz.
Last updated
.
Post not yet marked as solved
0 Replies
103 Views
Will user default values will be cleared if TestFlight build is installed on top of App Store build? App is getting abnormal in some times when this action happens. But not sure if this could be an ideal reason. This action was not able to replicate when in debugging mode. please help on clarifying the issue. Thanks
Posted Last updated
.
Post not yet marked as solved
1 Replies
82 Views
I tested below code: var c = URLComponents(string: "myscheme://")! c.host = "my host with space" let url = c.url! print(url) print(url.host) In Xcode 13.4, the console prints: myscheme://my%20host%20with%20space Optional("my host with space") In Xcode 14, the console prints: myscheme: nil According to URLCompinents.host documentation, it should encode in setter: The getter for this property removes any percent encoding this component may have (if the component allows percent encoding). Setting this property assumes the subcomponent or component string is not percent encoded and will add percent encoding (if the component allows percent encoding).
Posted Last updated
.
Post not yet marked as solved
0 Replies
86 Views
So far have this custom API class and I'm wanting to create a custom URL delegate for the tasks that I will be performing with this API, this code below gathered from the Apple Docs -> Apple Docs URL loading/fetching Listing #2 to be exact... keep getting 'Argument type 'API' does not conform to expected type 'URLSessionDelegate''    var delegate: URLSessionDelegate?   static var requestObject: URLSession = {     let configuration = URLSessionConfiguration.ephemeral     configuration.allowsCellularAccess = true     configuration.waitsForConnectivity = true     return URLSession(configuration: configuration, delegate: self, delegateQueue: nil)         }() } protocol URLSessionDelegate{   var delegate: URLSessionDelegate? {get}     } Not sure why but seems to be maybe error in codebase, as I have tried many tutorials and solutions and no one provides an explicit working version for a custom delegate (not a shared session) that allows for various configurations for URLSessions.
Posted Last updated
.
Post not yet marked as solved
0 Replies
99 Views
Hello community! As I read from https://support.apple.com/kb/SP743?locale=en_US iPhone7 has A10 Fusion chip, which has 4 cores, but [NSProcessInfo processInfo].processorCount returns 2. Also here it is stated that "Unlike most implementations of big.LITTLE, such as the Snapdragon 820 or Exynos 8890, only one core type can be active at a time, either the high-performance or low-power cores, but not both. Thus, the A10 Fusion appears to software and benchmarks as a dual core chip. " Another source tells us that: "Meanwhile it should be noted that while A10 technically has four CPU cores – the two Hurricane cores and the two smaller cores – this is not a heterogeneous design, and only two cores are active at once. So for the purposes of high performance benchmarking, this means we're benchmarking the big cores nearly exclusively." Can anybody confirm this or give the link to apple documentation to prove that? Thanks!
Posted Last updated
.
Post not yet marked as solved
3 Replies
528 Views
I've implemented the NSFilePresenter protocol in a Mac app (Catalina 10.15.3 Xcode 10.15.3) to watch a directory.Most protocol methods get called correctly, but some don't get called at all. For some there are (cumbersome) alternatives, but if, for example a file is immediately deleted in Finder using option+command+del, the NSFilePresenter delegate never receives any callback. Is there a workaround to trigger the callbacks?final class FileController: NSObject, NSFilePresenter { ... init() { presentedItemURL = // Some directory NSFileCoordinator.addFilePresenter(self) } func accommodatePresentedItemDeletion(completionHandler: @escaping (Error?) -> Void) { // Never gets called completionHandler(nil) } func presentedSubitemDidAppear(at url: URL) { // Never gets called } func presentedSubitemDidChange(at url: URL) { // Does get called } }
Posted Last updated
.