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(...) {...}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Where can I find a list of those characters that can be put in front of the ""character in a string literal, such as "n", thus the following would print a new line?
I don't know what those characters are called. I thought they were called "escape characters" or "format specifiers".
print("\n", terminator: "")
What would happen if I add an index to a record type in development that isn't there in production, then I deploy the development into production?
I would like my app to allow the Messages app to allow content shared with the user of the Messages app in iOS to automatically appear in my app when my app is selected in iOS Settings->Messages->Shared with You. I can't find information saying I can do this. The Share app extension doesn't enable this. Please someone say they know how to do this?
Is there a logical disjunction operator or function in Swift?
Even better, is there a logical disjunction that works with optional variables instead of boolean variables that returns an object when true, and returns nil when false?
A logical disjunction evaluates two boolean variables, and if at least one of them is true, then the return value is true. If neither variables is true, then the return value is false.
Topic:
Programming Languages
SubTopic:
Swift
Tags:
Swift
Swift Student Challenge
Education
Swift Packages
What criteria does Apple use to determine whether a vCard sent for example as an email attachment has a duplicate? I would think there has to be more in common between the duplicates than just the given name and the family name? Does Apple say whether the given name, family name, and address enough similarities to consider two contacts duplicates of each other?
I'm looking for the Swift tutorial that had always been used since I started learning Swift for the first time about 5 years ago. I can't remember the name. It was an app that reviewed restaurants, as I remember. I need a sample of key-value-coding. I recall that tutorial used key-value-coding.
Where is the “Use standard social compose interface” checkbox "in the Xcode target-adding pane" that the documentation for Share App Extension references in the "NOTE" grayed section under the "Use the Xcode Share Template"?
I am sure it's not where it says it is.
Where is Apple's documentation of NSConcreteAttributedString?
I need to get the String from NSExtensionItem.attributedContentText property, which is of type NSConcreteAttributedString.
The intent property doesn't even show when I initialize an instance of NSExtensionContent, as in the following code:
let extensionContext = NSExtensionContext() extensionContext.intent
I get an error saying:
Value of type 'NSExtensionContext' has no member 'intent'
Why is this? The documentation doesn't say it is deprecated. Even when something is deprecated, it still shows in Xcode.
Does an operation that is synchronous have to be run on a separate thread? I think so, otherwise it would deadlock right from the beginning, if it’s run on and called from the main thread. What about if it’s run on and called from a thread other than the main thread? Will it deadlock?
This question arose when I was reading the following content at
Documentation/Foundation/Task Management/Operation
Asynchronous Versus Synchronous Operations
When you add an operation to an operation queue, the queue ignores the value of the isAsynchronous property and always calls the start() method from a separate thread. Therefore, if you always run operations by adding them to an operation queue, there is no reason to make them asynchronous.
I tried running the following code and it raises the following error every time:
DispatchQueue.main.sync { }
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
I found this post on stackoverflow that says to never run synchronous code on the main queue:
DispatchQueue crashing with main.sync in Swift
I had assumed that because the sync { } method is there that means there is some context that it can be used. Is there absolutely no use for executing synchronous code on the main queue?
This documentation: Documentation/Bundle/Resources/Information Property List/Data and storage/NSSupportsPurgeableLocalStorage says:
Property List Key
NSSupportsPurgeableLocalStorage
A Boolean value indicating whether the app continues working if the system purges the local storage.
Under what conditions does the system "[purge] the local storage", and does this mean the entire local storage for the app? I can see how when a user deletes an app the local storage would be deleted, but then the app would not continue working, since it's no longer on the device.
How can my app know if a text message is sent to a device that has my app installed?
Is there a user notification or a remote notification that notifies when a text message or iMessage arrives on the device?
i’m willing to try anything.
What is this type of variable (specifically constant) declaration called that initializes itself with a "stored procedure" with code within curly braces followed by an empty set of parentheses? I don't know what key words to search for.
let object: NSObject = {
let nestedObject = NSObject()
return nestedObject
}()
I want to know if that variable gets initialized when it's needed the first time if I declare it globally in a swift file outside any other scope, or if it is initialized when the iOS app starts up before the variable is even called.
I thought the code within the curly braces runs when the iOS app launches, thus initializing the value of the variable, but I got an run time error while debugging my Xcode project when such a variable is called for the first time. I got a runtime error that says:
EXC_BREAKPOINT (code=1, subcode=0x...)
I also was told at one time in a question I posted on stackoverflow that the code runs only once.