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

294 Posts
Sort by:
Post not yet marked as solved
3 Replies
530 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
.
Post not yet marked as solved
1 Replies
124 Views
I'm getting some Crash Reports for an app of mine that's on the Mac App Store. A few details: -All the crash reports are on ARM-64 Macs. -The call stack shows my app calling NSURL's -getResourceValue:forKey: method with NSURLLocalizedNameKey, which is the last call made by my app before the crash. After that crash logs look like this: **Thread 0 Crashed: 0   libobjc.A.dylib               0x00000001a623c4b0 objc_retain + 16 1   LaunchServices                0x00000001a6954f68 -[FSNode(PathAndName) nameWithError:] + 72 2   LaunchServices                0x00000001a6a36278 +[_LSDisplayNameConstructor(ConstructForAnyFile) displayNameConstructorWithContextIfNeeded:bundle:bundleClass:node:preferredLocalizations:error:] + 2732 3   LaunchServices                0x00000001a6a357ac +[_LSDisplayNameConstructor(ConstructForAnyFile) displayNameConstructorWithContextIfNeeded:node:error:] + 44 4   LaunchServices                0x00000001a6ae5b20 LaunchServices::URLPropertyProvider::getDisplayNameConstructor(LaunchServices::Database::Context&, FSNode*, LaunchServices::URLPropertyProvider::State*, NSError* __autoreleasing*) + 88 5   LaunchServices                0x00000001a6ae1930 LaunchServices::URLPropertyProvider::prepareLocalizedNameValue(LaunchServices::Database::Context&, FSNode*, __FileCache*, __CFString const*, LaunchServices::URLPropertyProvider::State*, NSError* __autoreleasing*) + 328 6   LaunchServices                0x00000001a6953d6c LaunchServices::URLPropertyProvider::prepareValues(__CFURL const*, __FileCache*, __CFString const* const*, void const**, long, void const*, __CFError**) + 456 7   CoreServicesInternal          0x00000001a8def6f0 prepareValuesForBitmap(__CFURL const*, __FileCache*, _FilePropertyBitmap*, __CFError**) + 452 8   CoreServicesInternal          0x00000001a8dec5ec _FSURLCopyResourcePropertyForKeyInternal(__CFURL const*, __CFString const*, void*, void*, __CFError**, unsigned char) + 236 9   CoreFoundation                0x00000001a64546b0 CFURLCopyResourcePropertyForKey + 144 10  CoreFoundation                0x00000001a646b944 -[NSURL getResourceValue:forKey:error:] + 120** -- I haven't been able to reproduce the issue on my ARM-64 Mac. Not sure what's going with _LSDisplayNameConstructor or if there is a way I can workaround/resolve. Some of the crashes have the following lines included: Kernel Triage: VM - Compressor failed a blocking pager_get VM - Compressor failed a blocking pager_get VM - Compressor failed a blocking pager_get VM - Compressor failed a blocking pager_get VM - Compressor failed a blocking pager_get
Posted Last updated
.
Post not yet marked as solved
0 Replies
112 Views
We've been working with VMWare on a ticket related to slow upload/download transfers using the VMWare API/SDK on Mac. They believe the root cause is below.  The slow performance is caused by Apple's authentication subsystem (PAM/opendrectoryd) being slow and using a lot of CPU. The security for guestOps file transfer requires an authn check for every packet, packets are limited to ~60k bytes due to the underlying arch; hence every 60k bytes of data has a ~.2 second overhead for the authn. (We see no such delays for Linux or Windows.) Does anyone have any experience with PAM/opendirectoryd who might be able be help me?
Posted
by RainerSe.
Last updated
.
Post not yet marked as solved
0 Replies
142 Views
A puzzling phenomenon occurs in obtaining the week number. Please see the attached source. In Step 0, the correct week number can be obtained according to ISO8601. In Step 1, by changing minimumDaysInFirstWeek, a new (correct) week number can be obtained. In Step 2, if I re-set the firstWeekday, for some reason the week number reverts back to the original, even though the value has not been changed. Shouldn't Step2 return 1 for both weekOfMonth and weekOfYear? I have verified this with XCode 13.4 playground. Thanks in advance. import Foundation var calendar = Calendar(identifier: .iso8601) let date = calendar.date(from: DateComponents(year: 2022, month: 1, day: 1)) print("*** Step 0 ***") print("firstWeekday : \(calendar.firstWeekday)") print("minimumDaysInFirstWeek : \(calendar.minimumDaysInFirstWeek)") print("weekOfMonth : \(calendar.component(.weekOfMonth, from: date!))") print("weekOfYear : \(calendar.component(.weekOfYear, from: date!))") print("\n*** Step 1 ***") calendar.minimumDaysInFirstWeek = 1 print("firstWeekday : \(calendar.firstWeekday)") print("minimumDaysInFirstWeek : \(calendar.minimumDaysInFirstWeek)") print("weekOfMonth : \(calendar.component(.weekOfMonth, from: date!))") print("weekOfYear : \(calendar.component(.weekOfYear, from: date!))") print("\n*** Step 2 ***") calendar.firstWeekday = 2 print("firstWeekday : \(calendar.firstWeekday)") print("minimumDaysInFirstWeek : \(calendar.minimumDaysInFirstWeek)") print("weekOfMonth : \(calendar.component(.weekOfMonth, from: date!))") print("weekOfYear : \(calendar.component(.weekOfYear, from: date!))") Result *** Step 0 *** firstWeekday : 2 minimumDaysInFirstWeek : 4 weekOfMonth : 0 weekOfYear : 52 *** Step 1 *** firstWeekday : 2 minimumDaysInFirstWeek : 1 weekOfMonth : 1 weekOfYear : 1 *** Step 2 *** firstWeekday : 2 minimumDaysInFirstWeek : 1 weekOfMonth : 0 weekOfYear : 52
Posted Last updated
.
Post not yet marked as solved
1 Replies
184 Views
I'm working on an app where we want to upload data every 5 minutes or so to a cloud server even if the app is in the background. We're able to receive data from a BLE sensor in the background, but couldn't find anything on uploading the data consistently. We think it should be possible due to products like the Dexcom glucose monitoring system which uploads data from the background every 5 minutes. Any idea on how we'd go about doing this?
Posted Last updated
.
Post marked as solved
3 Replies
164 Views
I've followed several tutorials and nothing works or is remotely simple. can anyone perhaps link a json tutorial that can load the following in a "SWIFT UI" format? { "id": 182, "name": "message 2048", "interactive": "https://wolvideos.firebaseapp.com/Test1.mp4", "thumbnail": "https://wolvideos.firebaseapp.com/back.jpg", "date": "April 1", "videolink": "https://player.vimeo.com/external/656370948.m3u8?s=e50ca2b440798886646ba88a07e9c46a90c9df11", "sharelink": "https://youtu.be/n7YjxFCyDNQ" }, { "id": 180, "name": "Title 4", "interactive": "https://wolvideos.firebaseapp.com/Test2.mp4", "thumbnail": "https://wolvideos.firebaseapp.com/back.jpg", "date": "April 2", "videolink": "https://player.vimeo.com/external/653500077.m3u8?s=96c687bef62bfd01ea195e4113e197ebd8d09143", "sharelink": "https://youtu.be/n7YjxFCyDNQ" }, { "id": 172, "name": "Titil 20203", "interactive": "https://wolvideos.firebaseapp.com/Test1.mp4", "thumbnail": "https://wolvideos.firebaseapp.com/back.jpg", "date": "April 1", "videolink": "https://player.vimeo.com/external/656370948.m3u8?s=e50ca2b440798886646ba88a07e9c46a90c9df11", "sharelink": "https://youtu.be/n7YjxFCyDNQ" }, { "id": 171, "name": "Title 20part2", "interactive": "https://wolvideos.firebaseapp.com/Test2.mp4", "thumbnail": "https://wolvideos.firebaseapp.com/back.jpg", "date": "April 2", "videolink": "https://player.vimeo.com/external/653500077.m3u8?s=96c687bef62bfd01ea195e4113e197ebd8d09143", "sharelink": "https://youtu.be/n7YjxFCyDNQ" }, { "id": 170, "name": "Title 2021", "interactive": "https://wolvideos.firebaseapp.com/Test1.mp4", "thumbnail": "https://wolvideos.firebaseapp.com/back.jpg", "date": "April 1", "videolink": "https://player.vimeo.com/external/656370948.m3u8?s=e50ca2b440798886646ba88a07e9c46a90c9df11", "sharelink": "https://youtu.be/n7YjxFCyDNQ" }, { "id": 169, "name": "Title 2020", "interactive": "https://wolvideos.firebaseapp.com/Test2.mp4", "thumbnail": "https://wolvideos.firebaseapp.com/back.jpg", "date": "April 2", "videolink": "https://player.vimeo.com/external/653500077.m3u8?s=96c687bef62bfd01ea195e4113e197ebd8d09143", "sharelink": "https://youtu.be/n7YjxFCyDNQ" } ] https://wolvideos.firebaseapp.com/Simple.json
Posted
by TechyGod.
Last updated
.
Post not yet marked as solved
1 Replies
168 Views
Apple's Certificate Transparency policy says that Signed Certificate Timestamps (SCTs) are accepted from TLS extension or OCSP Stapling in addition to the SCTs embedded in the certificate. If we're implementing our own Certificate Transparency enforcement in code written using URLSession, is there a way to obtain SCTs that were presented via TLS extension or OCSP Stapling? I'm able to get the SCTs from the certificate by calling SecCertificateCopyValues with "1.3.6.1.4.1.11129.2.4.2" inside the urlSession(_:didReceive:completionHandler:) delegate function. I see that there are functions for adding TLS/OCSP SCTs to the ServerTrust, but I don't see any functions for getting them out, and I don't know if URLSession would be including those SCTs in the ServerTrust automatically anyway. Is there any way to get these other SCTs using URLSession? Or would I have to drop down to Network Framework to do that? Thanks for any help.
Posted Last updated
.
Post marked as solved
2 Replies
139 Views
TL;DR - the API cannot be changed, and the variable parameters are a vital part of my app. I've created a type that stores parameters for an API call. To make use of them with a successful request, I first need to format them into the URL. Say, my parameters are expressed as such: struct Parameters: Encodable { var name: String var taste: Taste var numberOfSpoons: Int? var topping: Taste? private enum CodingKeys: String, CodingKey { case name, taste, topping case numberOfSpoons = "spoons" } init(name: String, taste: Taste, numberOfSpoons: Int? = 1, topping: Taste? = nil){ self.name = name self.taste = taste self.numberOfSpoons = numberOfSpoons self.topping = topping } } Notice that my structure uses both Optionals (as the API does not need all the parameters from my app) and CodingKeys (as the names requested by the API look rather ugly in the code, but are necessary). Here's the Taste - not much going on except explicit Encodable conformance. enum Taste: String, Encodable { case choco, strawberry, vanilla } Now I want to call the API, so, according to the suggestion of John Sundell (I can't provide a link to the article due to Apple's censorship), I'm using URLComponents. For example: var components = URLComponents() components.scheme = "ftp" components.host = "icecream.ogs" components.path = "/spoons" If I were to add queryItems by hand, it would be fairly easy. components.queryItems = [ URLQueryItem(name: "name", value: iceCreamParameters.name), URLQueryItem(name: "numberOfSpoons", value: "\(iceCreamParameters.numberOfSpoons!)") ] How to dynamically create URLQueryItems from a non-CaseIterable type? The URLQueryItem needs both name and value parameters. I want the i-th name to be equal to I-thParameters.PropertyName, the same goes for values. As CaseIterable would not be feasible to implement* in the Parameters struct, I tried to fake it using the Encodable protocol - I thought about serializing the type to JSON (as the encoder gets rid of nil values, too) and then somehow get the keys from a deserialized Dictionary of AnyType (?), but there's got to be a better way. If this approach is not feasible, please provide your answers with helpful examples.
Posted Last updated
.
Post marked as solved
1 Replies
95 Views
https://imdb-api.com/en/API/BoxOffice/k_92uqzcls i cast data like this :  let output = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as! Dictionary<String,Array<Dictionary<String, Any>>>//Array error: Could not cast value of type '__NSCFConstantString' (0x7fff869ca888) to 'NSArray' (0x7fff869ca8e8).
Posted
by ahmed2016.
Last updated
.
Post marked as solved
1 Replies
87 Views
We are now developing an online APP exam function,But students can cheat with keyboard custom phrases,How to turn off keyboard custom phrase hints?
Posted
by Xjq.
Last updated
.
Post not yet marked as solved
1 Replies
154 Views
recently my app published on app store facing some issue after i have implemented cloudflare and mtls to enhance security feature. Before that, when the API failed, i can receive http error code such as 403, 401 and etc. but after mtls is activated, all those failed http call is block by AppTransportSecurity layer and i can only receive 999 and error message as "URLSessionTask failed with error: The erver "***.***.com" requires a client certificate." i have read through Apple document, it says Apple introduce this security layer by default to ensure network security without known weakness https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW35 does anyone have come across similar issue like this before?
Posted
by JosCc.
Last updated
.
Post not yet marked as solved
1 Replies
122 Views
I'm getting errors when I use NSKeyedArchiver and NSKeyedUnarchiver that works with iOS 15.5 but not with iOS 12.4 nor iOS 12.5.5. I have tried combinations of using devices and simulators. The error message appears in the Xcode debug window when the catch scope handles an error that occurs when the following statement executes: try NSKeyedUnarchiver.unarchivedObject(ofClass: CNGroup.self, from: dataToUnarchive) Here is what prints in the Xcode debug window for Error.localizedDescription: The data couldn’t be read because it isn’t in the correct format. Here is what prints in the Xcode debug window when only the Error object is put in the print statement parentheses: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: incomprehensible archive (0x62, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4)" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: incomprehensible archive (0x62, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4)} I found an answer to a similar question like this in Apple Developer Forums which had to do with NSCoder that indicated that the older iOS expects the Data object not to use secure coding, my code as this post concerns is not using secure coding. There are stackoverflow questions that deal with similar questions to mine, but they are very old and they deal with different facets of NSCoder. The following are the respective function definitions for archive(cnGroup:completionHandler:) and unarchive(dataOfCNGroup:completionHandler) that I use. Definition for unarchive(dataOfCNGroup:completionHandler) func archive(cnGroup: CNGroup, completionHandler: @escaping (Result<Data, Error>)->Void) { do { if #available(iOS 11.0, *) { let data: Data = try NSKeyedArchiver.archivedData(withRootObject: cnGroup, requiringSecureCoding: false) completionHandler(.success(data)) } else { let data: Data = NSKeyedArchiver.archivedData(withRootObject: cnGroup) completionHandler(.success(data)) } } catch { completionHandler(.failure(error)) } } // func archive(...) {...} Definition for archive(cnGroup:completionHandler:) func unarchive(dataOfCNGroup dataToUnarchive: Data, completionHandler: @escaping (Result<CNGroup, Error>)->Void) { print("func unarchive(dataOfCNGroup dataToUnarchive: Data, completionHandler: @escaping (Result<CNGroup, Error>)->Void)") do { if let unwrappedUnarchivedCNGroup: CNGroup = try NSKeyedUnarchiver.unarchivedObject(ofClass: CNGroup.self, from: dataToUnarchive) { completionHandler(.success(unwrappedUnarchivedCNGroup)) } else { let nsError = NSError(domain: "func unarchive(dataOfCNGroup dataToUnarchive: Data, completionHandler: @escaping (Result<CNGroup, Error>?)->Void)", code: #line, userInfo: nil) let error: Error = nsError completionHandler(.failure(error)) return } } catch { print("catch error in unarchive(dataOfCNGroup:_:) on line \(#line)") print("\(error.localizedDescription)") completionHandler(.failure(error)) } } // func unarchive(...) {...}
Posted Last updated
.
Post not yet marked as solved
5 Replies
761 Views
Hi, I'm trying to display a string containing the number of the largest given time unit for the time since as given date - i.e. "2 Months Ago" or "1 Week Ago". DateComponentsFormatter appears to be a useful tool for this (the app targets iOS 10.2), however it doesn't seem to be formatting the number of weeks consistently. This is how I'm setting up the formatter: import Foundation let day = 60*60*24 let formatter = DateComponentsFormatter() formatter.calendar = Calendar.current formatter.allowedUnits = [.hour, .day, .weekOfMonth, .month] formatter.unitsStyle = .full formatter.maximumUnitCount = 1 formatter.allowsFractionalUnits = false formatter.zeroFormattingBehavior = .dropAll For the given range, I would expect 8-13 to use "1 week", but this doesn't seem to be the case: (0..40).forEach {   print("\($0): \(formatter.string(from: TimeInterval(day * $0))!)") } The actual output of this is: 0: 0 hours 1: 1 day 2: 2 days 3: 3 days 4: 4 days 5: 5 days 6: 6 days 7: 1 week 8: 2 weeks 9: 2 weeks 10: 2 weeks 11: 2 weeks 12: 2 weeks 13: 1 week 14: 2 weeks 15: 2 weeks 16: 2 weeks 17: 2 weeks 18: 2 weeks 19: 2 weeks 20: 2 weeks 21: 3 weeks 22: 3 weeks 23: 3 weeks 24: 3 weeks 25: 3 weeks 26: 3 weeks 27: 3 weeks 28: 4 weeks 29: 4 weeks 30: 4 weeks 31: 1 month 32: 1 month 33: 1 month 34: 1 month 35: 1 month 36: 1 month 37: 1 month 38: 1 month 39: 1 month Could anyone point me in the right direction?
Posted
by robham.
Last updated
.
Post not yet marked as solved
1 Replies
116 Views
Xcode version: 13.2.1 (13C100) plateform: iOS Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x99288 __exceptionPreprocess 1 libobjc.A.dylib 0x16744 objc_exception_throw 2 CoreFoundation 0x176fc4 +[NSObject(NSObject) _copyDescription] 3 CoreFoundation 0x2de98 forwarding 4 CoreFoundation 0x2cf70 _CF_forwarding_prep_0 5 QuartzCore 0xcb320 CA::Layer::run_animation_callbacks(void*) 6 libdispatch.dylib 0x3a30 _dispatch_client_callout 7 libdispatch.dylib 0x11f48 _dispatch_main_queue_drain 8 libdispatch.dylib 0x11b98 _dispatch_main_queue_callback_4CF 9 CoreFoundation 0x51800 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE 10 CoreFoundation 0xb704 __CFRunLoopRun 11 CoreFoundation 0x1ebc8 CFRunLoopRunSpecific 12 GraphicsServices 0x1374 GSEventRunModal 13 UIKitCore 0x514648 -[UIApplication _run] 14 UIKitCore 0x295d90 UIApplicationMain 15 TCPApp 0xa44bb8 main + 39 (AppDelegate.swift:39) 16 ??? 0x104f49ce4 (Missing)
Posted Last updated
.
Post not yet marked as solved
1 Replies
313 Views
I have a Settings.bundle for my app Roughly, which tells the approximate time in words (e.g. it's about quarter to six) in a complication. It supports a number of languages, but I allow people to use a different language to their own, to help them learn how to tell the time in another language. The preference switch works fine in the Watch app on the iPhone, but if a user downloads the app direct from the App Store to their watch, there is no way for them to access those preferences. The preferences do not appear in the Watch app without the iOS app present on the iPhone. Does anyone have a good solution to this? Do I have to offer a preferences switch in the app itself?
Posted Last updated
.
Post not yet marked as solved
0 Replies
122 Views
#define KdownloadsPath NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES).firstObject _downloadedPath = [KdownloadsPath stringByAppendingPathComponent:fileName]; _downloadingPath = [_downloadedPath stringByAppendingString:@".download"]; NSDictionary* info = [NSDictionary dictionaryWithObjectsAndKeys:         @"NSProgressFileOperationKindDownloading", @"NSProgressFileOperationKindKey",         [NSURL fileURLWithPath:_downloadingPath], @"NSProgressFileURLKey",         nil]; self.progress = [[NSProgress alloc] initWithParent:nil userInfo:info]; [self.progress setKind:@"NSProgressKindFile"]; [self.progress setPausable:NO]; [self.progress setCancellable:YES]; [self.progress setTotalUnitCount:_totalBytes]; [self.progress publish]; (updating the progress indicator happens elsewhere) I'm creating an NSProgress object to show a progress indicator underneat a file in my Downloads directory. The entitlements includes com.apple.security.files.downloads.read-write. The indicator does not show when NSProgressFileURLKey points to the sandboxed file path, e.g. /Users/mdbraber/Library/Containers/com.mdbraber.TestApp/Data/Downloads/Test.pptx.download. It does work when NSProgressFileURLKey points to the direct download location which the sandbox links to e.g. /Users/mdbraber/Downloads/Test.pptx.download Is this a bug or should I use something else for NSProgressFileURLKey to make this work?
Posted
by mdbraber.
Last updated
.