I am trying to code an assignments apps in swift playgrounds 4 and I received this error when trying to make a function that deletes an assignment. Here is the function
func deleteAssignment(madeAssignmnet: assignmentClass){
if let index = Assignments.firstIndex(where: { assignmentClass -> Bool in
return madeAssignmnet.id = assignmentClass.id
}){
Assignments.remove(at: index)
}
}
what's the problem?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
So im trying to make an assignments app and i also have a completed tab. If there are no assignments that are supposed to be displayed in the upcoming view, then I want to display a text that says that there are no assignments. But even if an assignment is completed, it still counts as an assignment, I just have it set not to come up under the upcoming tab. What do I do?
import SwiftUI
struct AssignmentListView: View {
var Assignments: [assignmentClass]
var Classes: [classesClass]
@State var shouldBeCompleted: Bool
var noEventsText: String
var body: some View {
ScrollView{
VStack {
if Assignments.count == 0 {
Text(noEventsText)
.bold()
.fontWeight(.medium)
.multilineTextAlignment(.center)
.padding(.top, 50)
.padding(.horizontal, 5)
} else{
ForEach(Assignments) { madeAssignment in
if madeAssignment.isCompleted == shouldBeCompleted{
NavigationLink(destination: (AssignmentDetailView(madeAssignment: madeAssignment, classes: Classes))) {
AssignmentTileView(madeAssignment: madeAssignment, classes: Classes)
}
.buttonStyle(.plain)
}
}
}
}
}
}
}
if madeAssignment.isCompleted == shouldBeCompleted{
NavigationLink(destination: (AssignmentDetailView(madeAssignment: madeAssignment, classes: Classes))) {
AssignmentTileView(madeAssignment: madeAssignment, classes: Classes)
}
.buttonStyle(.plain)
} else if textShown != true {
Text(noEventsText)
.bold()
.fontWeight(.medium)
.multilineTextAlignment(.center)
.padding(.top, 50)
.padding(.horizontal, 5)
textShown = true
}
}
Above is the code I am going to be talking about. The error I get with this code is 'Type '()' Cannot conform to 'view''
I am making a view that shows a list of assignment tiles, and is specificys whether when it is displayed we want the completed assignments or not. When I say 'if madeAssignment.isCompleted == shouldBeCompleted', the computer is seeing whether the bool value of whether the assignment is completed or not is equal to 'shouldBeCompleted', a bool variable specified when I call this view in other views in my app telling the computer if we want a list of completed or not completed assignments returned. Then the else if is to say that if the assignment passed in the for each is not equal to should be completed, then it is asking whether text is shown (a variable created earlier in the view). Then I show no events text and set text shown to true because we never want the text to show again, because there only needs to be one text saying that there are no assignments supposed to be showing. Let me know what I am doing wrong. Thanks
So i found all the ekrecurrencerule and ekrecurrencedayofweek but I do not know how to display a ekrecurrencedayofweek picker? Can I have them like pick a number and then change it to ekrecurrencedayofweek?
I am building an app in Swift Playgrounds 4 and it suddenly stopped working without any errors. When I go to run the app it says, "Build failed because the Mach-O file couldn't be generated". I've tried looking for any errors but I can't find anything. I attached the whole project if anyone would be kind enough to look through it for me.
https://www.icloud.com/iclouddrive/0fa4WViSAUZGAbAhYxYL4XEUg#Smart_Work (I think you need to request access or something so I will approve if any of you will look through it for me)
Thanks!
***actually just comment if you would be willing to look at it and i’ll get it to you. the link doesn’t work
Hey! So I’m working on this shopping list and basically I have a list of tile views that have swipe actions. The bought and delete actions work perfectly, but I am unable to get the edit button to work. The edit button pulls up a form already filled with the item’s information so you can edit it. The code for the button works, when I make the tile itself a button and tap the tile the edit form comes up. Is there a limit to swipe actions that limit you pulling up a form in a swipe action? Here is the code for the list. Thanks! (Program is coded using swift ui and swift)
ForEach(Item) { madeItem in
FoodListTileView(foodItem: madeItem)
.swipeActions(edge: .leading){
Button {madeItem.justBought()
FoodDataController.shared.saveItem(madeItem: madeItem)
} label: {
Label("Just Bought", systemImage: "checkmark.square")
}
.tint(.green)
}
.swipeActions(edge: .trailing){
Button {FoodDataController.shared.deleteItem(madeItem: madeItem)} label : {
Label("Delete", systemImage:"trash")
}
.tint(.red)
Button(action: {showingCreateView = true}) {
Label("Edit", systemImage: "pencil.circle")
}
.sheet(isPresented: $showingCreateView){
AddItemView(Item: madeItem)
}
.tint(.orange)
}
// .sheet(isPresented: $showingCreateView) {
// AddItemView(Item: madeItem)
// }
}
}
.listStyle(.plain)