1

Working with coredate I used the option codegen: category/extension to be able to create a file where I can put in the re-usable code for finding, updating or deleting database entries. I started the coredata entity first with the codegen option Class Definition and changed it to category/extension in a later stage.

Now I run against a compile error: 'Property cannot be declared public because its type uses an internal type'

The file name is a generated swift file called: Gameresults+Coredataproperties.swift

I got the error on the player: TournamentPlayer?

player and round are both relations to another entity.

import Foundation
import CoreData

extension GameResults {

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

    @NSManaged public var earnedRankingPoints: Int16
    @NSManaged public var framePoints: Int16
    @NSManaged public var highestBreak: Int16
    @NSManaged public var isWon: Bool
    @NSManaged public var player: TournamentPlayer?
    @NSManaged public var round: Rounds?

}

I could not believe that the error did come out of swift so I tried the clean build folder option, saving file, exiting XCode, etc. Nothing worked.

Any tips where to look at how to fix this?

Marcel
  • 29
  • 3

1 Answers1

0

Use the Manual/None option for the codegen.

There are a couple of things that you should consider here.

  1. when you use codegen it automatically creates all classes which are equivalent to your entities as public. I assume TournamentPlayer class is not public and you have definded it yourself. so based on default definition it is internal and the compiler gives you the error correctly. the only thing you can do here is changing the access level and because you're using the codegen and it means you want to change your model, so it's better to change your TournamentPlayer to public. Although it depends on the architecture of your application.

  2. The codegen is automatically regenrated whenever you change your model and is saved in DerivedData.

  3. If you want to take care of it yourself you set it to manual and you handle the code generation yourself manually.

check this article, it gives you a better understanding of codegen https://useyourloaf.com/blog/core-data-code-generation/

one more thing, when you change to manual/none you have to do a clean build otherwise it still uses the generated code in DerivedData

  • I get 19 errors when I do this :). I tried changing all entities, but that gave me 19 errors. Next I tried only the change from category/extention into manual/none. But that left me with 8 errors. Could you explain a bit more what you mean? – Marcel Feb 17 '18 at 14:02
  • I updated my answer, it was long to write it in comments. by the way what kind of errors do you get now? –  Feb 17 '18 at 14:51
  • Now getting the error in the other classe where Tournamentplayer has being used: Value of type 'TournamentPlayer' has no member ....xxxxx – Marcel Feb 18 '18 at 08:19
  • and the error: Cannot convert value of type 'NSFetchRequest' to specified type 'NSFetchRequest' – Marcel Feb 18 '18 at 08:42
  • have you generated the TournamentPlayer too? –  Feb 18 '18 at 10:54
  • TournamentPlayer is on Manul/Hold the rest is on class definition – Marcel Feb 18 '18 at 20:41
  • Which files should I create manually when I put the entity on Manual/Hold? – Marcel Feb 18 '18 at 20:43
  • I recommend generate all of them in manual mode and then change one entity at a time so you can pinpoint the problem. –  Feb 19 '18 at 18:31