Post

Replies

Boosts

Views

Activity

Reply to How to create an array using a loop
There were several mistakes: [(id: String, name: String)] This is not a good definition of a dictionary, which is just [key:value], no labels var output = [id: "testID", name: "testName"] It does not make sense. If you wrote var output = ["id": "testID", "name": "testName"] that would be a dictionary with 2 elements, but that's not what you need here In your loop, you replace output at each iteration. So at the end you get only the 4th input. for i in 1...4 { var output = [id: "testID", name: "testName"] } Here is a correct code. I created a type alias for better readability. typealias MyDict = [String: String] // A dictionary is defined as [key:Value] var quotes: [MyDict] { var allQuotes = [MyDict]() // Creates an empty array for i in 1...4 { var newOutput = ["testID" : "testName \(i)", "secondID" : "secondName \(i)"] // a dict with 2 pairs allQuotes.append(newOutput) // We append the new output to the array of Dicts } return allQuotes } print(quotes) And you get the expected array: [["secondID": "secondName 1", "testID": "testName 1"], ["testID": "testName 2", "secondID": "secondName 2"], ["testID": "testName 3", "secondID": "secondName 3"], ["secondID": "secondName 4", "testID": "testName 4"]] Note that as always in dictionaries, the order of pairs is never guaranteed If you ask for an item: print(quotes[0]["testID"]) you get an optional (as the value for the key is nil if there is no value) Optional("testName 1") So you should write: print(quotes[0]["testID"] ?? "not found") and get: testName 1
5d
Reply to Why is this causing my app to crash?
You did not give enough information on the crash. What message ? Where exactly ? Your code is not complete to be tested: roomOrBlank missing I completed with: func roomOrBlank(course: Course) -> String { if course.room == "None" { return "" } else { return course.room } } currentCourse missing Rose, Lemon, White… missing: why not pass directly a Color as parameter instead of String ? So I tested by removing those lines and it does not crash. struct courseListView: View { var localcourse: Course var localtime: String func roomOrBlank(course: Course) -> String { if course.room == "None" { return "" } else { return course.room } } var body: some View { HStack{ Image(systemName: localcourse.listIcon) .foregroundColor(Color(localcourse.colour)) .padding(.leading, 5) Text(localcourse.name) .bold() Spacer() Text(localtime) Text(roomOrBlank(course: localcourse)).bold().padding(.trailing, 5) } .padding(.bottom, 1) // .background(currentCourse.name==localcourse.name ? Color(localcourse.colour).colorInvert(): nil) } } It does not seem the crash comes from removed line, as I tested with: .background(false ? Color(localcourse.colour).colorInvert(): nil) without causing a crash Anyway, you marked your own answer as correct. As it is not really an answer, we understand you closed the thread and don't need any more help.
5d
Reply to Settings.bundle
Did you register UserDefaults: UserDefaults.standard.register(defaults: defaults) // connect to Root.pList This is usually done in func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
1w
Reply to Launching A New Build
The change itself is very simple and rapid: archive a new build (even with no change at all in code), just change version and build numbers in Appstore Connect, reorder the screenshots. If no new screenshot needed, it should take about 5 minutes for each localization submit the new version. After this there is no more work, unless the submission is rejected. So, the raw time is very limited, less than 1 hour. But, as @endecotp pointed out, the real workload may depend on extra tasks like testing, documenting, updating web pages for the app…  Only you can know.
1w
Reply to Image & Text inside picker.
If you use directly Image, it does not work. You have to use the Image built from a resized UIImage. That would be worth a bug report. Get a solution here: https://www.hackingwithswift.com/forums/swift/remove-or-resize-an-image-when-selecting-an-item-in-a-picker-view/23940 Here is the full code. Fiat 500e is an image in Assets struct ContentView: View { struct Data: Identifiable, Hashable { var id = UUID() var name: String var condition: Bool } @State var selection = "Easy" var datas: [Data] = [Data(name: "Easy", condition: true), Data(name: "Medium", condition: false), Data(name: "Hard", condition: true)] var myImage: UIImage = UIImage(named: "Fiat 500e") ?? UIImage() var resizedImage: UIImage { return myImage.scalePreservingAspectRatio(targetSize: CGSize(width: 50, height: 25)) } var body: some View { Picker("Title: ", selection: $selection) { ForEach(datas, id: \.self) { data in HStack { Text(data.name) if data.condition { Image(systemName: "globe") } else { Image(uiImage: resizedImage) .resizable() .scaledToFit() } } .tag(data.name) .padding() } } } } extension UIImage { func scalePreservingAspectRatio(targetSize: CGSize) -> UIImage { // Determine the scale factor that preserves aspect ratio let widthRatio = targetSize.width / size.width let heightRatio = targetSize.height / size.height let scaleFactor = min(widthRatio, heightRatio) // Compute the new image size that preserves aspect ratio let scaledImageSize = CGSize( width: size.width * scaleFactor, height: size.height * scaleFactor ) // Draw and return the resized UIImage let renderer = UIGraphicsImageRenderer( size: scaledImageSize ) let scaledImage = renderer.image { _ in self.draw(in: CGRect( origin: .zero, size: scaledImageSize )) } return scaledImage } } The image displayed in selection is now resized (it was automatically resized in Picker): In Picker. After selection.
1w