Post

Replies

Boosts

Views

Activity

Reply to Challenge with Sort & Filter on List Array
Could you provide more explanation on the error. It's hard to try and guess here. Am getting a "Return from initializer without initializing all stored properties" error in Xcode on teh second to last line, after the init After which init ? You declare order, but I do not see where you initialise it: struct EditOrderView: View { @Environment(\.dismiss) private var dismiss let order: Order That could well be the problem. If so, you should initialise: let order = Order() Or using any initialiser you've defined (you don't show how Order is defined, so hard to be more specific. And please, when you get an answer (other threads), tell if that does not solve what is the remaining issue or what is it you don't understand. Otherwise don't forget to close the thread by marking the correct answer.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24
Reply to Half Donut Chart using SectorMark
For what it's worth… I achieved something by some trick: adding a new sector which value is the sum of the other meeting explicitly the colours of the sectors rotating the view by 90° But I lost the legend because of rotation… So that requires some more work. struct Score: Identifiable { let id = UUID() let type: String let value: Int let color: Color } struct ContentView: View { @State private var scores: [Score] = [ .init(type: "Hits", value: 1, color: .blue), .init(type: "Misses", value: 9, color: .green), .init(type: "", value: 10, color: .white) ] var body: some View { Chart(scores) { score in SectorMark( angle: .value("Values", score.value), innerRadius: .ratio(0.9), outerRadius: .ratio(0.7) ) .foregroundStyle(score.color) .foregroundStyle( by: .value("Type", score.type) ) } .rotationEffect(.degrees(-90)) } } To get the legend, even though rotated (and the colours are the default, not the defined ones)… So may be you should add the legend later in the VStack: var body: some View { VStack { Chart(scores) { score in SectorMark( angle: .value("Values", score.value), innerRadius: .ratio(0.9), outerRadius: .ratio(0.7) ) .foregroundStyle(score.color) .foregroundStyle( by: .value("Type", score.type) ) } .rotationEffect(.degrees(-90)) .chartLegend(position: .overlay) // Could try different parameters } .frame(width: 300, height: 400) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24
Reply to Picker with SwiftData challenges...
I assume the error occurs here ? Picker("Choose a Category?", selection: $category) { It is because category is initialised as nil. @State private var category: Category? You should initialise with a default value @State private var category: Category? = Category()
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24
Reply to Generates all possible subsets of a given set, excluding the empty set. (non sorted)
@ InvaDerZim In your example, you showed a result ["qual1#qual2#qual3", "qual1#qual2", "qual1#qual3", "qual2#qual3", "qual1", "qual2", "qual3"] which is a Set not a Set<Set> What is the expected result as Set<Set> ? @endecotp Just to give a reference, I tested with 23 letters (8 million combinations): Original Set: ["v", "g", "r", "p", "d", "c", "e", "s", "h", "m", "j", "a", "i", "l", "q", "o", "b", "f", "k", "n", "t", "w", "u"] Elapsed time: 12.271471977233887 seconds Modified Set: 8 388 607 Beyond, app crashes (memory limit because strings are explicitly built ?)
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’24
Reply to Crash on startup
Any thoughts on what could be causing it? First suspect would be a change in your code. Are you sure to have checked any change you made since last version. Could you post the crashlog here directly (I do not visit websites I don't know about) ? Is is iOS app, UIKit, SwiftUI ? Please provide some context.
Topic: UI Frameworks SubTopic: UIKit Tags:
Mar ’24
Reply to Generates all possible subsets of a given set, excluding the empty set. (non sorted)
I would do it with recursive calls. Of course, sets are unordered, so the result is unordered. func getSubSets(initialSet: Set<String>) -> Set<String> { var item: String? var partialSet = initialSet var returnedSet: Set<String> = initialSet for s in initialSet { item = s // "a" break } if let item { partialSet.remove(item) // We get an element out: partialSet = ["b", "c"] returnedSet.insert(item) // ["a"] // We add the subsets built with "a" + all subsets of partialSet let subSets = getSubSets(initialSet: partialSet) for aString in subSets { // "b", "c", "b#c"] returnedSet.insert(item + "#" + aString) } returnedSet = returnedSet.union(subSets) } return returnedSet } var initialSet : Set = ["a", "b", "c"] print("Original Set:", initialSet) let allSubs = getSubSets(initialSet: initialSet) print("Modified Set:", allSubs) This gives: Original Set: ["b", "a", "c"] Modified Set: ["b", "b#a", "b#a#c", "a#c", "c", "a", "b#c"]
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’24
Reply to How are you supposed to test on earlier iOS versions if Xcode is incompatible with them?
Xcode is not incompatible. I just built an app on iPad iOS 15.8 with Xcode 15.0.1 and target set as 14+. Problem usually due to a version of iOS too recent compared to Xcode. Inverse to what you describe. See this, could help: https://www.swiftdevjournal.com/dealing-with-failed-to-prepare-device-for-development-error-message-in-xcode/#:~:text=Why%20Are%20You%20Getting%20This,along%20with%20the%20iOS%20SDK.
Mar ’24
Reply to LineMark chart reverting Y axis
Did you try something like: ForEach(andamento, id: \.posizione) { item in LineMark( x: .value("Giornata", item.giornata), y: .value("Posizione", 20 - item.posizione) // May be need to adjust 20 to 21, if you want to end at 1 ) PointMark( x: .value("Giornata", item.giornata), y: .value("Posizione", 20 - item.posizione) )
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’24