Post

Replies

Boosts

Views

Activity

Airdrop CoreData
I need to share a singular instance of an object created in core data. Every video I've found that showed how to do this used outdated code and I was wondering if anyone had a working way to either create the airdrop button (because I don't even know how to do that yet, or make it so that the data is share is a duplicate of the object from the sharers device. Thanks! This is the entity that needs to be shared via airdrop:
0
0
309
Jun ’22
List Background
Does anyone have any clue as to how to get rid of the grey background of my list? I've actually tried everything I could find online. .background(Color.clear), .backgroundStyle(.clear), init(){...}. nothing. I even tried replicating it in a new project and it didn't even show up there. Any idea as to how to get rid of this?
1
0
483
Jun ’22
NavBar Format
How has GitHub formatted their navigation bar like this? The title is aligned with the back button and add button, the search bar is inside instead of under, and they have buttons alone the bottom that filter the list. Is there a view object that shortcuts this? If you understand even one part of that I would appreciate that information. Thanks!
0
0
342
Jun ’22
Enlarged TextField
I need to enlarge my text field. So I tried using a frame, but that only put dead space around it. The problem with that is I want to be able to click anywhere inside the boarder and it pull up the keyboard. So I tried padding and that did the same thing. Also I need the text to start a new line after it fills the first one and to go for as long as they type. Thanks!
1
0
405
Jun ’22
Unknown Errors From Inverse Relationship. Please Help!!!
I had the idea of adding a list feature in my app where users can create a list and add multiple recipes to the app so first and only thing I did was add an entity to my data model called "List" that contains a string: title and an array of Recipes: recipes (I remembered to put "NSSecureUnarchiveFromData" in Transformer and put [Recipe] for custom class). Afterwards I made the relationship in both entities and made them inverse. I made no other changes to my code. But I ran it just to make sure nothing went wrong and lo and behold: 7 never before seen errors, but only in one file. Before adding this entity this same code compiled just fine. This is the file and these are the errors I'm getting. Any help would be greatly appreciated. import SwiftUI struct RecipeView: View {     @Environment (\.managedObjectContext) var managedObjContext     @Environment(\.dismiss) var dismiss          var recipe: FetchedResults<Recipe>.Element     @State var isFavorite: Bool     @State var servings = -1          var body: some View {         VStack(alignment: .leading){ //Error: Trailing closure passed to parameter of type 'CGFloat?' that does not accept a closure             if (recipe.notes! != ""){                 Section{                     Text(recipe.notes!)                         .font(.headline)                 }                 .padding(.horizontal)             }             HStack{                 Spacer()                 Text("Total Time: "+calcTime(time:Int(recipe.totalTime!) ?? 0))                 Spacer()                 Text("Servings: "+recipe.servings!)                 Spacer()             }             .padding(.vertical)             Grid{                 GridRow{                     Button {                         isFavorite.toggle()                         recipe.isFavorite.toggle()                         PersistenceController().save(context: managedObjContext)                     } label: {                         HStack{                             Image(systemName: isFavorite ? "star.fill" : "star")                                 .foregroundStyle(.yellow)                             Text(isFavorite ? "Unfavorite" : "Favorite")                                 .foregroundColor(Color(UIColor.lightGray))                         }                         .frame(width: 300,height: 50)                         .background(Color(UIColor(hexString: "#202020")))                         .border(Color(UIColor(hexString: "#202020")))                         .cornerRadius(5)                     }                     Button {                         print("implement list functionality")                     } label: {                         Image(systemName: "plus")                             .frame(width: 50,height: 50)                             .background(Color(UIColor(hexString: "#202020")))                             .border(Color(UIColor(hexString: "#202020")))                             .cornerRadius(5)                     }                 }             }             .padding(.horizontal)             List{                 NavigationLink(destination: ingredientsView(ingredients: recipe.ingredients!)){                     HStack{                         Text("List of Ingredients")                         Spacer()                         Text(String(recipe.ingredients!.count))                             .foregroundColor(.gray)                     }                 }                 .frame(height: 50)                 NavigationLink(destination: instructionsView(instructions: recipe.instructions!)){                     HStack{                         Text("List of Instructions")                         Spacer()                         Text(String(recipe.instructions!.count))                             .foregroundColor(.gray)                     }                 }                 .frame(height: 50)             }             .listStyle(.grouped)             .scrollDisabled(true)             Spacer()         }         .navigationBarTitle(recipe.title!)         .navigationBarItems(trailing: shareButton)         .onAppear{             PersistenceController().updateDate(recipe: recipe, context: managedObjContext)         }         Spacer()     }     var shareButton: some View{         Button(action: {             print("Implement airdrop feature")         }){             Image(systemName: "square.and.arrow.up")                 .foregroundStyle(.blue)         }     } } struct ingredientsView: View{     @State var ingredients: [String]     var body: some View{         List{ // Error: Trailing closure passed to parameter of type 'NSManagedObjectContext' that does not accept a closure             Section(""){                 ForEach(ingredients,id: \.self){ String in                     NavigationLink(destination:                                     NavigationView{                         Text(String)                             .frame(alignment:.center)                             .font(.title)                     }){                         Text(String).lineLimit(1)                     }                 }             }         }         .frame(alignment: .center) //Error: Cannot infer contextual base in reference to member 'center' //Error: Value of type 'List' has no member 'frame'         .cornerRadius(10)         .navigationTitle("Ingredients List")     } } struct instructionsView: View{     @State var instructions: [String]     var body: some View{         List{ // Error: Trailing closure passed to parameter of type 'NSManagedObjectContext' that does not accept a closure             Section(""){                 ForEach(instructions,id: \.self){ String in                     NavigationLink(destination:                                     NavigationView{                         Text(String)                             .frame(alignment:.center)                             .font(.title)                     }){                         Text(String).lineLimit(1)                     }                 }             }         }         .frame(alignment: .center) //Error: Cannot infer contextual base in reference to member 'center' //Error: Value of type 'List' has no member 'frame'         .cornerRadius(10)         .navigationTitle("Instructions List")     } }
2
1
1.5k
Jun ’22
FetchedResults to Array (Error)
So I've found a way to convert fetched results to an array of the same data type, and not only that but filter them with the fetch request given a string: func searchResults(searchingFor: String)->[Recipe]{     var filteredRecipeList=[Recipe]()     @FetchRequest(sortDescriptors: [SortDescriptor(\.date, order: .reverse)], predicate: NSPredicate(format: "title CONTAINS[c] %@",searchingFor)) var filteredResults: FetchedResults<Recipe>     for recipe in filteredResults {         filteredRecipeList.append(recipe)     }     return filteredRecipeList } To clarify, this would ideally return an array with a list of Recipes that contain the given string in the title. In theory this should work just fine, but I'm getting a weird error. I've never seen an error like this and I'm not sure how to understand it. It is purple with a yellow warning. The error says "Accessing StateObject's object without being installed on a View. This will create a new instance each time." How do I get around this issue to accomplish what I'm trying to accomplish. Thanks in advance for any help whatsoever. I'll upvote anyone with any bit of helpful information. Have a good one!
2
1
2.3k
Jun ’22
Time Wheel Picker
I need a wheel picker for hours and minutes. I've found stuff online but it does have the "Hours" and "Minutes" right after and it isn't as compact. Is there a newer way to accomplish this to look exactly like it does in the timer app?
2
0
1.8k
Jun ’22
Optional Type Date
I'm sorry I know this is basic swift, but how do I get I make the selection an optional return? I know it's with ?? "" with a string, but I don't know how to do it with a date type. Also how do I get a navigationBarTitle to work on this view? The "My Calendar" doesn't show up when I run the code. import SwiftUI struct ReciPrep: View {     @State private var date: Date? = ni     @Environment(\.calendar) var calendar          @State private var showingAddView = false     var body: some View {         VStack{             DatePicker("Calendar", selection: $date, in: Date.now...,displayedComponents: [.date]) //Error: Cannot convert value of type 'Binding<Date?>' to expected argument type 'Binding<Date>'                 .datePickerStyle(.graphical)             Spacer()         }         .navigationBarTitle("My Calendar")     } } Any help would be greatly appreciated. Have a good day!
2
0
2.5k
Jun ’22