I am trying to use filter (I don't think map applies here, but I am not sure) to extract an element from an array of dictionaries which themselves contain dictionaries.
let participants = [
[
"id" : 1,
"team" : [
[
"name" : "John",
"job" : "teacher"
],
[
"name" : "Paul",
"job" : "coach"
],
[
"name" : "Mary",
"job" : "chef"
]
]
],
[
"id" : 7,
"team" : [
[
"name" : "Simon",
"job" : "engineer"
],
[
"name" : "Laura",
"job" : "writer"
],
[
"name" : "Peter",
"job" : "bartender"
]
]
],
[
"id" : 4,
"team" : [
[
"name" : "Igor",
"job" : "pianist"
],
[
"name" : "Mary",
"job" : "bartender"
],
[
"name" : "Denise",
"job" : "accountant"
]
]
]
]
I want to extract from the above array of dictionaries the element whose "team" value (which itself is an array of dictionaries) has an element whose "job" value is "writer". In other words, for the purpose of this exercise, I want the 2nd element of the participants array which is:
[
"id": 7,
"team": [
[
"name": "Simon",
"job": "engineer"
],
[
"name": "Laura",
"job": "writer"
],
[
"name": "Peter",
"job": "bartender"
]
]
]
How would I use map and/or filter to accomplish this?
Post
Replies
Boosts
Views
Activity
I was just prompted in Xcode to update/download iOS 17.2. I wasn't paying attention but I think it was downloading iOS 17.2 and then iOS 17.2 Simulator. The latter failed during "Verifying iOS 17.2 simruntime". I opened Xcode > Settings > Platforms and I see iOS 17.2, but I don't see iOS 17.2 Simulator.
Must I have both iOS 17.2 and iOS 17.2 Simulator?
Do I always have to have iOS xyz and iOS xyz Simulator present in the Platforms window?
What is the difference between the two? What's the iOS 17.2 for?
Color Literal used to be recognized in the Xcode IDE. As soon as you type "color", the autosuggestion dropdown shows "UIColor Color Literal" and you can simply select it without typing anything more. A small color square would appear where you can visually select your desired color.
There appears to no longer be any shortcut/ autosuggestion for color literal. Now, I have to type "#colorLiteral(" (yes, pound sign, uppercase L, and the left parenthesis) in order for the little color square to appear where I can select my color.
In addition, its behavior is inconsistent. That little color square appears only if I do something like:
If the color literals are arguments in a function call, the little color square doesn't appear anymore. Instead, the full-blown RGB function appears, in which case it is not possible to bring up the color selection popup to visually select your desired color:
Has this bug been reported to Apple, or is there an alternate way to work with color literals in Xcode 13.2.1?
Apps like Password Managers and such claim to encrypt your sensitive data, and only transmit and store your data on their servers in encrypted form, never in plain text. But how are we supposed to believe that? Just take their word for it? Who's to say that their developers won't accidentally (or intentionally!) make a mistake in their code at some point and get to see your sensitive data?
I am asking because I am currently writing an app using the Swift-Crypto package to do AES encryption. I save the user's data in encrypted form in Core Data on the device as well as mirror it on their iCloud account using CloudKit. When I submit the app to Apple for review, without looking at the source code, will they be able to verify 100% that my app actually and correctly encrypts all the data so that users can confidently trust that their data will be safe? How can we be sure?
Per the instructions in Apps with Multiple Xcode Projects to set up an app project with a nested framework project in Xcode, the project navigator looks like this:
When I make changes to files in the framework and/or files in the app, clicking on Source Control > Commit in the Xcode menu brings up the Commit window showing all the files I have modified (both the app and the framework) with a checkbox next to them.
How can I commit files for the app and the framework separately? Whatever commit message I write would be applied to both projects in the commit, which wouldn't be correct. What is the proper thing to do?
I have learned how to create my own framework for "iOS" and "iOS Simulator" and then creating a single xcframework that I can drop into any project that needs to use my xcframework. So if I am working on an app, I can go to the app's project navigator > General tab > Frameworks, Libraries, and Embedded Content section, and drag my xcframework from Finder into that section. It works just fine.
But while working on the app, if I realize I need to make a change to the framework, I'd have to launch the project for the framework, make my changes, then in Terminal, run xcodebuild archive, run xcodebuild -create-xcframework, then go back to my app, run Cmd-B / Cmd-R to build/run it. And if there are still issues in the framework code, I'd have to keep executing these steps over and over again.
Is there a way to somehow link my app project to the framework project such that I simply make changes to the framework code and run Cmd-B in the app code immediately?
Consider this:
class ViewController: UIViewController, UITextFieldDelegate {
var textfield: UITextField = {
let tf = UITextField(frame: CGRect(x: 0, y: 0, width: 140, height: 30))
}()
override func viewDidLoad() {
textfield.delegate = self
}
func textFieldDidBeginEditing(_ textField: UITextField) {
print("Inside textfield")
}
}
When I tap inside the textfield, textFieldDidBeginEditing() is called because the delegate handles that.
What happens if I want to subclass UITextField? How do I handle a tap event inside the subclassed textfield within the subclass? So for example:
class MyTextField: UITextField, UITextFieldDelegate {
required override init(frame: CGRect) {
self.delegate = self // CAN'T DO THIS!!!
}
func textFieldDidBeginEditing(_ textField: UITextField) {
print("Inside subclassed textfield")
// This function is NOT executed when I tap inside this subclassed textfield!!
}
}
The textFieldDidBeginEditing() within the subclass never gets called, I guess because the delegate is not properly set, and I don't know how to set it. It's not possible to do: self.delegate = self
Do I need to create a protocol for MyTextField? If so, how do I hook it all up? What would the code using MyTextField have to do? If I do:
var subTF = MyTextField(....)
subTF.delegate = self
Is that .delegate for class UITextField?? or is it for the subclass MyTextField?
I am able to use Xcode to clone a repo from github. I go to the repo, example: https://github.com/weitieda/cs193p-2020-swiftui, I click on the Code download button, I copy the repo's URL, I go back to Xcode and click on Source Control in the main menu, and click Clone, and paste the copied URL into the dialog box. The download completes, I see the project in the Finder, but the Xcode clone dialog box does not close and cannot be closed. The dialog box has a "Cancel" button, but clicking on it simply plays a "tock" sound but it doesn't close the dialog box. Because the dialog box is modal, I can't even quit Xcode normally. The only way I know to close the dialog box is to Force-Quit Xcode using Option-Command-ESC. Anyone else experience this? How to solve this?
I am unclear about the relationship between Merchant IDs and the banking info I provided on App Store Connect.
My understanding was that the banking info I set up in the App Store Connect (let's call it "My Bank") is so that when users of My App (an app that I wrote for me, by me, not for someone else) make a payment (using any suitable bank card) to purchase something from My App, their money is paid into My Bank. Do I need a Merchant ID for this use case specifically?
Let's say I create another app (let's call it XYZ App) but for a client company XYZ. They pay me to develop the app and put it out for the public to use. When users of XYZ App make a payment to purchase something from XYZ App, will their money be paid into My Bank also, and I arrange to transfer the money to company XYZ separately outside the app? Do I somehow set up separate banking info in App Store Connect for XYZ App's purchases? And must a separate Merchant ID be created for this use case?
I am also not understanding what happens if I use a payment gateway like Stripe. If have 10 different apps that use Stripe for payment, do I need 10 different Merchant IDs? Do all the successful payments from all these different apps go into my one single My Bank account? (And then I deal with transferring the money to the different companies myself later?)
Is there a step-by-step guide on this topic somewhere online? I can't seem to find a clear, complete tutorial on this online.