0

So I have been working for the past couple of weeks trying to use relationships in order to have an array of object ingredient to an individual class of recipe. I've been watching this video. Now, By creating two extensions of recipe and ingredient classes, I'm getting a ton of errors all in my code, specifically saying

invalid use of (class structure)

or

ambiguous use of (class structure)

I have a Git Repo on GitHub that you can diagnose my code here if that is preferable.

If not, here are the extensions that I've made

Recipe Class:

import Foundation
import CoreData


extension Recipe {

@nonobjc public class func fetchRequest() -> NSFetchRequest<Recipe> {
    return NSFetchRequest<Recipe>(entityName: "Recipe")
}

@NSManaged public var ingredients: String?
@NSManaged public var instructions: String?
@NSManaged public var time: String?
@NSManaged public var title: String?
@NSManaged public var ingredient: [Ingredient]?

}

// MARK: Generated accessors for ingredient
extension Recipe {

@objc(addIngredientObject:)
@NSManaged public func addToIngredient(_ value: Ingredient)

@objc(removeIngredientObject:)
@NSManaged public func removeFromIngredient(_ value: Ingredient)

@objc(addIngredient:)
@NSManaged public func addToIngredient(_ values: NSSet)

@objc(removeIngredient:)
@NSManaged public func removeFromIngredient(_ values: NSSet)

}

And the ingredient class:

import Foundation
import CoreData


extension Ingredient {

@nonobjc public class func fetchRequest() -> NSFetchRequest<Ingredient>{
    return NSFetchRequest<Ingredient>(entityName: "Ingredient")
}

@NSManaged public var cost: Double
@NSManaged public var name: String?
@NSManaged public var unit: String?
@NSManaged public var recipe: NSSet?

}

// MARK: Generated accessors for recipe
extension Ingredient {

@objc(addRecipeObject:)
@NSManaged public func addToRecipe(_ value: Recipe)

@objc(removeRecipeObject:)
@NSManaged public func removeFromRecipe(_ value: Recipe)

@objc(addRecipe:)
@NSManaged public func addToRecipe(_ values: NSSet)

@objc(removeRecipe:)
@NSManaged public func removeFromRecipe(_ values: NSSet)

}
jeanggi90
  • 741
  • 9
  • 24

1 Answers1

0

You have to decide if you want to manage your CoreData class files by yourself or if you want Xcode to manage them for you. Even though you tell Xcode to manage them for you have created Recipe+CoreDataClass.swift and Ingredient+CoreDataClass.swift. That is also why you get this error:

 Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

This error tells you that there are several classes with the same name.

So either you delete your Recipe and Ingredient extension and let Xcode manage them for you or you create them by yourself but properly. If you want to do so follow these steps: https://stackoverflow.com/a/40868074/5464989

After I created these files manually your app seemed to work.

jeanggi90
  • 741
  • 9
  • 24