So I was making a relationship between two entities in my data model and got a good ways in when I tried to run it and got a bunch of weird errors. Did I do something wrong to make this happen and if so what do I need to do? I've troubleshooted enough to realize that it happens as soon as I create a new entity. These are the errors.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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!
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?
I'm currently (obviously) building an app and I decided I prefer the dark mode theme more than default. Is there any way I could set it so that dark mode is the default color of the app?
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:
I’ve been looking for how to do this for AGES and I’ve finally found and app made in Swift that has it.
So I really need a bar that stays at the bottom of my screen even when scrolling or changing views that has buttons on it that takes the user to a different view. And I don’t mean like a NavigationLink with a back button and a sliding transition. I mean I want it to open a whole new view and save the user’s location in the other view so when they press the button to return to the previous view they continue where they left off.
This is the GitHub app and they’ve executed exactly what I need:
To be clear this is what I’m talking about:
If anyone has a repository or a YouTube tutorial that has something like this I would be SO grateful. Thanks! :)
Anyone have a really good YouTube tutorial on how to implement an image as binary data in core data? Thanks!
I'm trying to filter an array containing Recipes that have a property called title of type String that is required.
These are the variables used in the line of code:
@State private var searchingFor = ""
@State private var filteredRecipes = [Recipe]()
This is the line of code giving me the error:
filteredRecipes=filteredRecipes.filter{$0.title.contains(searchingFor)}
The error: "Value of optional type 'String?' must be unwrapped to refer to member 'contains' of wrapped base type 'String'"
Any ideas on how I need to rewrite that line of code so that I don't get that error? ie. how do I unwrap 'String?'
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!
So I have a core data entity titled recipe. I'm trying to make a search bar to search the list of recipes and my method of doing so is doing a fetch request of all objects and converting it to an array of those objects and then filtering the array and displaying the results. Any idea as to how to convert a type fetch results to an array?
PS: as I'm typing this it occurred to me I could just do a for each loop and add them to the array as I go, but is there a quicker way to do this? Like a function? Thanks!!!
So I have an entity in my core data model called recipe. I need to create another entity containing a recipe and a date that the recipe is assigned to. Can I do this similar to the way I've done it in the image and just save a Recipe object in the initialization of PlannedRecipe object in the Persistence file?
Basically I just need to know how to add a entity in an entity using this core data model and persistence file.
Persistence file:
import CoreData
struct PersistenceController {
static let shared = PersistenceController()
let container: NSPersistentCloudKitContainer
init(inMemory: Bool = false) {
container = NSPersistentCloudKitContainer(name: "ReciPrep")
if inMemory {
container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
}
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
container.viewContext.automaticallyMergesChangesFromParent = true
}
func addPlannedRecipe(recipe: Recipe,date: Date, context: NSManagedObjectContext){
let plannedRecipe = PlannedRecipe(context: context)
plannedRecipe.id = UUID()
plannedRecipe.date = Date()
plannedRecipe.recipe = recipe //Giving me an error: "Cannot assign value of type 'Recipe' to type 'Data?'"
save(context: context)
}
func save(context: NSManagedObjectContext){
do {
try context.save()
} catch {
let nsError = error as NSError
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
}
}
}
I guess this problem can be solved if I can convert a recipe into binary data or some other savable data in an entity.
Any help would be greatly appreciated.
Whenever I open a text field almost anywhere I get this common toolbar above my keyboard with two arrows that iterate through text fields and a done button. Not just on Apple related things, but even when I search on google. Which leads me to believe this is a default object and that google did not take the time to make an identical keyboard toolbar as all of Apple’s. So how do I get this default toolbar?
toolbar:
I am trying to implement a search bar in my recipe storage app. I got recommended using the .filter function that I didn’t know could be used on FetchedResults. So I did and now I’m getting errors, but not ones saying that it isn’t in the scope so I believe this is possible, just now sure how.
The ForEach loop containing the filter:
•ForEach(recipes.filter({$0.title.contains(searchingFor)})) { recipe in
Note: Recipes is just a FetchedResults type and searchingFor is just a string that comes from the search bar.
The errors:
•Value of optional type 'String?' must be unwrapped to refer to member 'contains' of wrapped base type 'String'
•Chain the optional using '?' to access member 'contains' only for non-'nil' base values
•Force-unwrap using '!' to abort execution if the optional value contains 'nil'
Any help is greatly appreciated.
So I've made a function using FetchRequest to search, but im getting an error: "Accessing StateObject's object without being installed on a View. This will create a new instance each time." The function takes a string and searches the core data for objects containing that string. The string is obtained from a .searchable object and the function is ran as a ForEach parameter.
This is the function:
func searchResults(searchingFor: String) -> FetchedResults<Recipe> {
@FetchRequest(sortDescriptors: [SortDescriptor(\.date, order: .reverse)], predicate: NSPredicate(format: "title CONTAINS[c] %@",searchingFor)) var searchRecipes: FetchedResults<Recipe>
return searchRecipes
}
Is there a better way to do this or can I do it this way and tweak it a little bit? I really just need to have a search bar that returns a FetechedResults type so I can use it in a ForEach loop. Any help is greatly appreciated.
So I’ve looked this up so many times and tried every way I’ve found using a @State variable and nothing works. I need a button that toggles between SystemImage: “Star” to SystemImage: “Star.fill” when clicked. And I want it to happen when it’s clicked. Everything I’ve tried only changes when I close and reopen the view because it happens on appearance. Is there any way to make it change instantly? Thanks for any help!