Post

Replies

Boosts

Views

Activity

Reply to What is the reason that my list is not functioning/ saving?
I do not get any errors Are you sure ? There is an error in your code: There misses a closing curly bracket at the end of struct Knowledge: Identifiable, Codable { addCard() is never called. Where and how do you add card ? What is your problem ? What do you get ? What do you expect ? So, to get something on screen, I created 2 knowledge in code, so that knowledgeArray is no more empty: init() { if let savedItems = UserDefaults.standard.data(forKey: "KnowledgeItems") { if let decodedItems = try? JSONDecoder().decode([Knowledge].self, from: savedItems) { knowledgeArray = decodedItems return } } let someKnowledge1 = Knowledge(id: UUID(), term: "First") let someKnowledge2 = Knowledge(id: UUID(), term: "Second") knowledgeArray = [someKnowledge1, someKnowledge2] }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’21
Reply to What is the reason that my list is not functioning/ saving?
You misused Environment Object. This should work: struct Knowledge: Identifiable, Codable { var id = UUID() var term: String var explanation: String? var tags: String? } class Deck: ObservableObject { @Published var knowledgeArray : [Knowledge] = [] init() { if let savedItems = UserDefaults.standard.data(forKey: "KnowledgeItems") { if let decodedItems = try? JSONDecoder().decode([Knowledge].self, from: savedItems) { knowledgeArray = decodedItems return } } knowledgeArray = [] } } struct AddCard: View { @Environment(\.presentationMode) var presentationMode @Environment(\.dismiss) var dismiss @State private var terms = "" @State private var tags = "" @State private var explanations = "" // @StateObject @EnvironmentObject var KN: Deck var body: some View { VStack { Form { TextField("Term", text: $terms) TextField("Explanation", text: $explanations) TextField("Tag", text: $tags) } Button("Save") { let item = Knowledge(term: terms, explanation: explanations , tags: tags) KN.knowledgeArray.append(item) let encoder = JSONEncoder() if let encoded = try? encoder.encode(KN.knowledgeArray) { let defaults = UserDefaults.standard defaults.set(encoded, forKey: "KnowledgeItems") } self.presentationMode.wrappedValue.dismiss() print("Button is working") } .padding() } } } struct cardList: View { @ObservedObject var decks = Deck() @State private var showingaddCard = false var body: some View { NavigationView { List { ForEach(decks.knowledgeArray) { cardName in Text(cardName.term) .font(.title) } .onDelete(perform: removeItems) } .toolbar { Button { showingaddCard = true } label: { Image(systemName: "plus") } } .navigationTitle("Card List") } .sheet(isPresented: $showingaddCard) { AddCard().environmentObject(decks) } } func removeItems(at offsets: IndexSet) { decks.knowledgeArray.remove(atOffsets: offsets) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’21
Reply to Unable to install iOS 15.1 on iPhone 6s
How much free storage available ? Repeated issues due to insufficient space: https://developer.apple.com/forums/thread/683104 I got this error with 15.1 and i had around 4 GB of space left after downloading the update, i deleted some apps so i had 10GB available and then i could install the update. Downloaded the new update and tried to install. I had about 4GB of space available after the download. I tried repeatedly to install the same but to no avail. I came upon this discussion and it was helpful. The post by AshishRajpal91 was the one to go with. I deleted a few apps and had about 6GB space and then tried again. I am now posting this reply post installation of ios 15. Have a nice day guys.
Topic: App & System Services SubTopic: Core OS Tags:
Nov ’21
Reply to Connect Label to View Controller
What is the name of the class where you want to declare the IBOutlet ? What is the class of the ViewController in which you have define the Label in storyboard ? They must be exactly the same: In this example you see: the class is named FirstViewController When you select the corresponding viewController in storyboard, you in Identity Inspector that its class is FirstViewController (and not the default UIViewController) That allowed to create a UILabel by control-drag from the Label in the view in the storyboard. Have you checked that the 2 names are exactly the same ?
Nov ’21
Reply to filter an object array based on another
I would do something like this: struct Option: Decodable, Hashable { var userCode: String var optType: String var optValue: String } struct Selected: Decodable, Hashable { var userCode: String var tradeCode: String var optType: String var optValue: String } struct ContentView: View { @State var options = [ Option(userCode: "1", optType: "Emotions", optValue: "Sad"), Option(userCode: "1", optType: "Emotions", optValue: "Happy"), Option(userCode: "1", optType: "Emotions", optValue: "Angry"), Option(userCode: "1", optType: "Emotions", optValue: "Calm") ] @State var selected = [ Selected(userCode: "1", tradeCode: "1", optType: "Emotions", optValue: "Sad"), Selected(userCode: "1", tradeCode: "1", optType: "Emotions", optValue: "Happy") ] var body: some View { Button("Options Not Selected") { let notSelectedOptions = options.filter() { !isOptionInSelected(for: $0) } print(notSelectedOptions) // Just to check // Here I need an array of the options NOT selected } } func isOptionInSelected(for option: Option) -> Bool { for select in selected { if option.userCode == select.userCode && option.optType == select.optType && option.optValue == select.optValue { return true } } return false } }
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’21
Reply to SwiftUI Dynamic List
I would do it differently: create a Label instead of TextField use onTapGesture modifier to display a List view where you will have all the options return the selected item in List change the Label Of course, that will not let you edit the label, but I understand you don't need it. You could also use a Picker for the selection: https://stackoverflow.com/questions/60048058/swiftui-tap-gesture-recogniser-only-called-once-when-it-effects-a-state-change
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’21
Reply to Button Style Before iOS 15.0 warning
Is it a SwiftUI project ?
Replies
Boosts
Views
Activity
Nov ’21
Reply to Change in Watch 7 in rounded corners of WKInterfaceLabel or WKInterfaceGroup
I filed a bug report Nov 2, 2021 at 5:53 PM – FB9735861
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to What is the reason that my list is not functioning/ saving?
I do not get any errors Are you sure ? There is an error in your code: There misses a closing curly bracket at the end of struct Knowledge: Identifiable, Codable { addCard() is never called. Where and how do you add card ? What is your problem ? What do you get ? What do you expect ? So, to get something on screen, I created 2 knowledge in code, so that knowledgeArray is no more empty: init() { if let savedItems = UserDefaults.standard.data(forKey: "KnowledgeItems") { if let decodedItems = try? JSONDecoder().decode([Knowledge].self, from: savedItems) { knowledgeArray = decodedItems return } } let someKnowledge1 = Knowledge(id: UUID(), term: "First") let someKnowledge2 = Knowledge(id: UUID(), term: "Second") knowledgeArray = [someKnowledge1, someKnowledge2] }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to What is the reason that my list is not functioning/ saving?
You need also to save to UserDefaults. With code like: let encoder = JSONEncoder() if let encoded = try? encoder.encode(knowledgeArray) { let defaults = UserDefaults.standard defaults.set(encoded, forKey: "KnowledgeItems") }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to What is the reason that my list is not functioning/ saving?
You misused Environment Object. This should work: struct Knowledge: Identifiable, Codable { var id = UUID() var term: String var explanation: String? var tags: String? } class Deck: ObservableObject { @Published var knowledgeArray : [Knowledge] = [] init() { if let savedItems = UserDefaults.standard.data(forKey: "KnowledgeItems") { if let decodedItems = try? JSONDecoder().decode([Knowledge].self, from: savedItems) { knowledgeArray = decodedItems return } } knowledgeArray = [] } } struct AddCard: View { @Environment(\.presentationMode) var presentationMode @Environment(\.dismiss) var dismiss @State private var terms = "" @State private var tags = "" @State private var explanations = "" // @StateObject @EnvironmentObject var KN: Deck var body: some View { VStack { Form { TextField("Term", text: $terms) TextField("Explanation", text: $explanations) TextField("Tag", text: $tags) } Button("Save") { let item = Knowledge(term: terms, explanation: explanations , tags: tags) KN.knowledgeArray.append(item) let encoder = JSONEncoder() if let encoded = try? encoder.encode(KN.knowledgeArray) { let defaults = UserDefaults.standard defaults.set(encoded, forKey: "KnowledgeItems") } self.presentationMode.wrappedValue.dismiss() print("Button is working") } .padding() } } } struct cardList: View { @ObservedObject var decks = Deck() @State private var showingaddCard = false var body: some View { NavigationView { List { ForEach(decks.knowledgeArray) { cardName in Text(cardName.term) .font(.title) } .onDelete(perform: removeItems) } .toolbar { Button { showingaddCard = true } label: { Image(systemName: "plus") } } .navigationTitle("Card List") } .sheet(isPresented: $showingaddCard) { AddCard().environmentObject(decks) } } func removeItems(at offsets: IndexSet) { decks.knowledgeArray.remove(atOffsets: offsets) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to I want to have my own IOS Applications.
You have to use Xcode, to develop either in Objective C or Swift (IMO, recommended). Then, to build the User Interface, you can choose UIKit (my preference) or SwiftUI (which I find harder to use). You have several tutorials from Apple : Intro to App development with Swift.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Unable to install iOS 15.1 on iPhone 6s
How much free storage available ? Repeated issues due to insufficient space: https://developer.apple.com/forums/thread/683104 I got this error with 15.1 and i had around 4 GB of space left after downloading the update, i deleted some apps so i had 10GB available and then i could install the update. Downloaded the new update and tried to install. I had about 4GB of space available after the download. I tried repeatedly to install the same but to no avail. I came upon this discussion and it was helpful. The post by AshishRajpal91 was the one to go with. I deleted a few apps and had about 6GB space and then tried again. I am now posting this reply post installation of ios 15. Have a nice day guys.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to How retrieve attendees associated with a calendar item?
This should help you: https://stackoverflow.com/questions/25294011/access-email-in-ekparticipant-ekattendee
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Regarding hiding the menu bar...
I don't understand what are my app, and 'special' Application Did you develop the special application ? Or is it a third party ? Then what is the link between the 2 ?
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to I keep getting an Abort() Called error
I try to run the program after putting Text("25%") in. Any ideas!  No ! How could we guess where you put Text("25%") ???? Please show the code.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to Connect Label to View Controller
What is the name of the class where you want to declare the IBOutlet ? What is the class of the ViewController in which you have define the Label in storyboard ? They must be exactly the same: In this example you see: the class is named FirstViewController When you select the corresponding viewController in storyboard, you in Identity Inspector that its class is FirstViewController (and not the default UIViewController) That allowed to create a UILabel by control-drag from the Label in the view in the storyboard. Have you checked that the 2 names are exactly the same ?
Replies
Boosts
Views
Activity
Nov ’21
Reply to filter an object array based on another
I would do something like this: struct Option: Decodable, Hashable { var userCode: String var optType: String var optValue: String } struct Selected: Decodable, Hashable { var userCode: String var tradeCode: String var optType: String var optValue: String } struct ContentView: View { @State var options = [ Option(userCode: "1", optType: "Emotions", optValue: "Sad"), Option(userCode: "1", optType: "Emotions", optValue: "Happy"), Option(userCode: "1", optType: "Emotions", optValue: "Angry"), Option(userCode: "1", optType: "Emotions", optValue: "Calm") ] @State var selected = [ Selected(userCode: "1", tradeCode: "1", optType: "Emotions", optValue: "Sad"), Selected(userCode: "1", tradeCode: "1", optType: "Emotions", optValue: "Happy") ] var body: some View { Button("Options Not Selected") { let notSelectedOptions = options.filter() { !isOptionInSelected(for: $0) } print(notSelectedOptions) // Just to check // Here I need an array of the options NOT selected } } func isOptionInSelected(for option: Option) -> Bool { for select in selected { if option.userCode == select.userCode && option.optType == select.optType && option.optValue == select.optValue { return true } } return false } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to What is the current method for changing the price of an existing app in apple store connect
What is it that doesn't work ? AFAIK, when you submit a new release of the app, you can change price in the Tarif and availability section.
Replies
Boosts
Views
Activity
Nov ’21
Reply to SwiftUI Dynamic List
I would do it differently: create a Label instead of TextField use onTapGesture modifier to display a List view where you will have all the options return the selected item in List change the Label Of course, that will not let you edit the label, but I understand you don't need it. You could also use a Picker for the selection: https://stackoverflow.com/questions/60048058/swiftui-tap-gesture-recogniser-only-called-once-when-it-effects-a-state-change
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21
Reply to What is the reason that my list is not functioning/ saving?
Thanks for feedback. Great it works. And don't forget to close the thread. . But why the state object did not work? This should give you further explanations: h t t p s : / / jaredsinclair.com/2020/05/07/swiftui-cheat-sheet.html
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Nov ’21