So I was trying to save an image in core data and created an NSManagedObject Subclass. After doing so I decided I didn't like it so I deleted the files, but now every time I run the project it creates a properties file with an error saying it can't find a UIImage in scope and the file isn't editable so I can't import UIKit. I've tried deleting the file in finder, deleting the whole project and then redownloading it from GitHub, but to no avail. Basically I want it to stop making the subclass every time I run the project.
Please help. Thanks!
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
So I'm looking to add a button to my app that would create and fill a reminder in the user's Reminders app, but I've found that I first need to request access to the user's Reminders app data. I've also found the way to do that has been changed with iOS 17 as explained here: https://developer.apple.com/documentation/eventkit/ekeventstore/4162273-requestfullaccesstoreminders
How do I use this function so that the prompt requesting for access to the user's Reminders app pops up at the launch of the app every time unless they've previously given permission?
Also what would be the function to create the reminder once I do have permissions? This is the code ChatGPT gave me to do so, but I just keep getting "Failed to create Reminder URL".
func createReminder() {
let reminderTitle = "Cocktail Groceries"
var subtaskStrings: [String] = []
for ingredient in shoppingList {
subtaskStrings.append(ingredient)
}
let subtasks = subtaskStrings.map { (ingredient) -> [String: Any] in
return [
"title": ingredient,
"completed": false
]
}
let reminderData: [String: Any] = [
"title": reminderTitle,
"subtasks": subtasks
]
if let reminderURL = createURL(for: "x-apple-reminder://", with: reminderData) {
UIApplication.shared.open(reminderURL)
} else {
print("Failed to create Reminder URL")
}
}
Also I intend on expanding this function to the notes app. But im taking one step at a time.
Any help would be GREATLY appreciated. Thanks!
So I want to implement the same feature many apple made have which is an gray list of options when something is held. An example of this is when you hold down an iMessage chat before you open it and it gives the options to “Pin”, “Hide Alerts”, and “Delete” and shown here:
Additionally when you hold down an app as if you were going to delete it a menu of options show up:
Using a button how can I do this on a long hold? Any help or any direction toward help is greatly appreciated. All the best!
I need to be able to search my list of recipes given a string. I’m unsure how to filter a data model in core data though. I tried a ForEach(container){ recipe in, but it said it gave me an error. Anyone know the correct way in the scrappy way doesn’t work? Thanks
data controller:
import Foundation
import CoreData
class DataController: ObservableObject {
let container = NSPersistentContainer(name: "RecipeModel")
init() {
container.loadPersistentStores { desc, error in
if let error = error {
print("Failed to load the data \(error.localizedDescription)")
}
}
}
func save(context: NSManagedObjectContext) {
do {
try context.save()
print("Data saved")
} catch {
print("The data could not be saved")
}
}
func addRecipe(title: String, ingredients: [String], instructions: [String], notes: String, context: NSManagedObjectContext){
let recipe = Recipe(context: context)
recipe.id = UUID()
recipe.date = Date()
recipe.title = title
recipe.ingredients = ingredients
recipe.instructions = instructions
recipe.notes = notes
save(context: context)
}
func editRecipe(recipe: Recipe, title: String, ingredients: [String], instructions: [String], notes: String, context: NSManagedObjectContext){
recipe.title = title
recipe.ingredients = ingredients
recipe.instructions = instructions
recipe.notes = notes
save(context: context)import Foundation
}
func updateDate(recipe: Recipe, context: NSManagedObjectContext){
recipe.date=Date()
save(context: context)
}
}
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!
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.
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?'
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! :)
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?
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?
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.
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!
How do I make it so that these two textfields aren't connected? They should have two separate backgrounds.
Anyone have any idea as to how to embed an SwiftUI View in a UITabBarController. From what I understand they were made to contain views made from UIKit and my views are made from SwiftUI so I’m not exactly sure how to use a UITabBarController in the storyboard with the views that I have. Any help would be greatly appreciated!
I've made a simplified version of what I'm trying to do in the included code, but basically I'm trying to make a view that edits a data model. This edit view shows up when a button in a context menu is clicked. The problem is no matter which one I open up the context menu on it always opens up whichever one I clicked first. The reference to the object in the .sheet never changes. How can I fix this??
Example Code:
import SwiftUI
class Object: Identifiable{
var id: UUID?
var title: String
var string: String
init(title: String, string: String) {
self.id = UUID()
self.title = title
self.string = string
}
}
struct ContentView: View {
@State private var showingEditView = false
@State private var objectList = [Object(title: "First", string: "Editor"), Object(title: "Second", string: "Addition"), Object(title: "Third", string: "Twelve")]
var body: some View {
NavigationView{
List{
Section("Objects"){
ForEach(objectList) { object in
NavigationLink(destination: ObjectView(obj: object)){
Text(object.title)
}
.sheet(isPresented: $showingEditView){
EditView(obj: object)
}
}
}
.contextMenu{
Button(action: {
self.showingEditView.toggle()
}){
Text("Edit Item")
}
}
}
.listStyle(InsetGroupedListStyle())
.cornerRadius(10)
.navigationBarTitle("My List")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct ObjectView: View {
@State var obj: Object
var body: some View {
NavigationView{
VStack{
Text(obj.string)
}
.navigationBarTitle(obj.title)
}
}
}
struct EditView: View {
@Environment(\.dismiss) var dismiss
@State var obj: Object
@State var word = ""
var body: some View {
NavigationView{
Form{
TextField("Change Word", text: $word)
.onAppear(perform: {
word = obj.string
})
}
.navigationBarItems(trailing:
Button(action: {
dismiss()
}){
Text("Done")
.bold()
})
}
}
}
Any help would be greatly appreciated. All the best!