Post

Replies

Boosts

Views

Activity

How does let statement work?
If I have a class property let appDelegate: AppDelegate? = UIApplication.shared.delegate as? AppDelegate Each time appDelegate is accessed, would it return the value at the time it is accessed, or would it return the value the first time it was accessed? I'm trying to understand whether the property above works the same way as let appDelegate: AppDelegate? = { return UIApplication.shared.delegate as? AppDelegate }() The second declaration of the appDelegate property runs the closure the first time the property is accessed and never again. Later references to appDelegate returns the value that was returned the first time the property was accessed.
1
0
505
Aug ’22
How do I avoid nested closures or clauses?
I need to take some suggestions from other programmers about something. When we have to use an asynchronous closure, often because the Framework provides only an asynchronous method for something we can't do without, it seems to prevent us from using the guard statement, which we need to make the code easier to read. The guard statement keeps us from making nested if statements, which makes the code difficult to read if there are many lines of code within a set curly braces. I would see a closing curly brace, and not be able to see the what the if condition is for that if clause (what's between the set of curly braces). Putting comments at the closing curly brace works, but that means I would still have to find the if condition at the beginning of the if clause. I could collapse the clause where the curly braces closes a clause, but then I have to find that collapsed clause, because Xcode scrolls the content of the editor upward, so that the beginning of the clause is hidden upwards toward the top, and I don't know how far up it is. This problem that the guard statement solves is also a problem with completion handlers, which we have to have with any asynchronous code. One approach to this problem is to avoid nested curly braces. How do I do that when I have to have asynchronous clause of code? If there is someway I can return a variable of type Result from a function the classical way instead of in a completion handler, I could avoid nested closures or clauses. One way I've found is to use the DispatchSemaphore or any statement to instructs code execution to wait for an asynchronous closure end and then return. There's something I don't like about this that I'm not sure what it is. Anytime there is a code instruction to wait, it makes me uncertain to its effectiveness. One thing that would help is if Xcode would show in the editor the beginning of collapsed code, so that when I click on the left side of the code editor to collapse a closure/clause when I'm seeing the bottom of the closure, Xcode would scroll downward so that the code editor shows me the code at the beginning of the clause, so that I wouldn't have to scroll upward to find the code that introduces the clause of code. I could file a bug report with Apple. Anyone have any contributions to any solutions to this problem? By the way, what is the Apple or Swift word for I'm calling a clause? What, for example, is the code that is enclosed between curly braces? Am I using the words clause and closure each time I used them?
3
0
1.6k
Aug ’22
Can I add a CKDatabaseOperation to the queue belonging to a CKContainer object using CKContainer.add(_:)?
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?
1
0
568
Aug ’22
Where do I find documentation for codes for exception types?
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.
1
0
1.6k
Aug ’22
What is the purpose of a line of code that says: '_ = viewController.view'?
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() }
2
0
314
Aug ’22
When will type Error not cast to type NSError?
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
2
0
494
Aug ’22
How do I get information on messages that have been sent in Messages app in iOS?
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?
0
0
1.1k
Jul ’22
Is this self-initializing variable initialized at app launch, or initialized when it is first called upon by an executing code?
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.
1
0
402
Jul ’22
How do I store FileManager.ubiquityIdentityToken?
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?
3
1
1.8k
Jul ’22
When does iOS purge local storage?
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.
0
0
804
Jul ’22