(Swift, macOS, storyboards)
How to open a view (not a window) by clicking a menu item?
Let's suppose I have one window and two views:
I try to open with Menu item: "open view 1" and item: "open view 2":
(Here I asked the same question. Claude 31 solved very well with a button in one of the views. Here I am asking the same but with a button in the menu or menu item: https://developer.apple.com/forums/thread/690644 )
(Be aware that I am a beginner and I try to learn. Please explain in a simple way if possible)
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Is it possible to convert a var with the day of the week to a number? (and the other way around)
let diaSetmana = "Monday"
let diaSetmana2 = 2
I know how to convert from date():
let date = Date()
let calendar = Calendar.current
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "EEEE"
let dayString = dateFormatter.string(from: date)
I am asking for converting not from date() but from a var that I have a random day of the week
I have created a small app for macOS. I looked for information about how to submit it to the app store and read: "Build your apps using Xcode 13.1 or later…"
https://developer.apple.com/macos/submit/
I have an old iMac Late 2013. Unfortunately, the last version I can install is Catalina 10.15.7, and the last Xcode I can install is version 12.4. Does it mean that I cannot publish my app? Is there any way I can submit it? Is buying a new mac the only solution?
My iMac works well, and it is not easy for me to buy a new one.
I would appreciate any recommendation
Thank you
(Swift, macOS, storyboards)
//I have a JSON in a URL. Simplified it is something like this:
{
"id": 1,
"name": "Leanne Graham",
"with-hyphen": 123
}
//Outside the class ViewController:
struct User: Codable {
let id: Int
let name: String
let with: Int
}
//In the class ViewController:
@IBAction func getJson(_ sender: NSButton) {
let url = URL(string: "https://example.com")!
URLSession.shared.dataTask(with: url) { data, _, _ in
if let data = data {
let result = try? JSONDecoder().decode(User.self, from: data)
//let result2 = result!.name //it works
//let result3 = result!.with-hyphen //it does not work
//print (result3)
}
}.resume()
}
I can safe in a let the regular "id" and "name" but I do not know how to deal with the keys with hyphens, in the example: "with-hyphen"