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.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
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.
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?
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.
Which build caches and unused SDKs can I delete to free up storage on my Mac Pro with the latest macOS Monterey that I just updated? The all fall under the heading "Xcode Project Build Files". I see some that are considered "Xcode Project Build Files" and some "iOS Device Support" and some that are considered "BridgeOS Device Support". They all have the Xcode icon. I explain in detail below how I get to this screen. Basically it's in the System Information app. I'm not sure what is safe to delete.
I have to free up space to update my Xcode on my Mac Pro. When I look at the screen that shows when I got to the Apple Logo on the very top left-hand corner of the menu, then go to About this Mac, then the Storage Tab and then click on the button that says "Manage...", then click on the button that says "Review Files"... When I click on "Developer" on the left tab, I see some rather large files. At the top it says, "Remove project build caches and unused SDKs to free storage space."
The sample project CloudKitShare downloaded from developer.apple.com Sharing CloudKit Data with Other iCloud Users has a line of code in HandleCloudKitError.swift that optionally casts an instance of Error to a variable of type NSError.
guard let nsError = error as NSError? else {
return nil
}
Under what conditions would this fail? I thought this would always succeed.
How do I find out why the cast is unsuccessful? When I put code that prints the type of variable 'error', it seems to always result in Optional like so:
Code:
guard let nsError = error as NSError? else {
print(type(of: error))
return nil
}
Optional
I have wondered before how I can find out what messages have been sent and perhaps even to whom and from whom. What is the underlying technology behind the search feature in iOS when the user swipes right from the first screen of the home screen? Is that part of Siri. Setting group Siri and Search together. Does the search feature I speak of use Intents, and is that made accessible to developers. I have also noticed that there is an intent property to the extension context object that passes information between a host app and another app's share extension. I'm brainstorming and looking for any ideas. I hope someone out there have good information for me. macOS has Spotlight. Is that available on iOS?
What is the purpose of the following line of code? It doesn't seem to do anything. If it were in Playground or in a print statement it would at least show something.
_ = masterVC.view
It's in Apple's sample code at Sharing CloudKit Data with Other iCloud Users.
Here's the complete significant code that contains that line of code:
if let masterVC = masterNC?.viewControllers.first as? ZoneViewController {
_ = masterVC.view
start ? masterVC.spinner.startAnimating() : masterVC.spinner.stopAnimating()
}
I found this article at Apple's Developer Documentation:
Understanding the Exception Types in a Crash Report
Anyone know where I can find specific documentation for the codes that go with each exception type?
I got a run time error during a debug run of my Xcode project for iOS at a line of code where I initialize a custom struct.
I want to look up what that "2" represents.
Thread 3: EXC_BAD_ACCESS (code=2, address=0x16dbc7ff0)
I think I found documentation at one time for those codes at another source outside of Apple. It seems there are codes that are used by hardware manufacturers for "architectures" such as "arm64" and "armv7". I see those in Xcode project build settings.
Do I really need to know what each code as given in the error message represent?
I found this documentation on Apple's Exception Handling Framework in a search with Google: Exception Handling. I don't see what I need. This framework seems to be more than I need at this time.
Can a shared CloudKit record have child records in a different zone, as long as they are in the same database?
What does that mean in Xcode When the name of a swift file that is showing in the tab at the top in the editor window is italicized?
I have used code to test whether a child record and a parent record have to be in the same zone. They do.
Now... Does a parent record have to be in the same CKDatabase as a child record?
Can I add a CKDatabaseOperation to the queue belonging to a CKContainer object using CKContainer.add(_:)?
The CKContainer.add(_:) method takes a CKOperation argument, so it will take a subclass of CKOperation as far as I can tell. I can't find any documentation on this.
What I'm trying to figure out is which queue should I add a CKFetchRecordsOperation object to? Should I use CKDatabase.add(:), or CKContainer.add(:)?
let fetchRecordsOperation = CKFetchRecordsOperation.fetchCurrentUserRecordOperation()
I need the CKRecord for the current user for the entire CKContainer, or for the privateCloudDatabase and the sharedCloudDatabase to be specific. If I pass the CKFetchRecordsOperation object to the queue for CKDatabase, would that not return the current CKRecord for the current user for that CKDatabase only?
I suspect that if there is a separate CKRecord representing the current user in each database in a container, that they would each hold identical values, even identical recordName fields. Is that the case?