0

I am using core data in my child app. Used podspec file to link my child app with parent app as development pods.

Child app is working file with core data. Here Child is an entity in core data.

But while building parent getting below errors as Cannot find 'Child' in scope

import CoreData
import Foundation
import SwiftUI

class CoreDataService {
    static let shared = CoreDataService()
    lazy var stack: CoreDataStackType = CoreDataStack()

    private init() {
        // private init
    }

    func insertChildItem(name: String) {
        guard let context = stack.context else { return }
        let child = Child(context: context) // ==> Cannot find 'Child' in scope
        child.id = UUID().uuidString
        child.name = name

        save()
    }

    func fetchChildList() -> [Child]? { // ==> Cannot find type 'Child' in scope
        let request = NSFetchRequest<Child>(entityName: "Child") // ==> Cannot find type 'Child' in scope
        guard let context = stack.context else { return nil}
        do {
            let items: [Child] = try context.fetch(request)
            return items // ==> Cannot find type 'Child' in scope
        } catch let error {
            print("Error fetching. \(error)")
            return nil
        }
    }

    private func save() {
        switch stack.save() {
        case .saved: print("Saved")
        case .rolledBack: print("RolledBack")
        case .hasNoChanges: print("HasNoChanges")
        }
    }
}

am I missing any configuration in Child/Parent app?

Solution Found reference:

  1. https://medium.com/@starecho/something-you-may-need-to-do-when-integrating-core-data-into-your-cocoapods-library-e8e8fad409b8

  2. error while build iOS app in Xcode : Sandbox: rsync.samba (13105) deny(1) file-write-create, Flutter failed to write to a file

enter image description here

enter image description here

3
  • 1
    Personally I prefer to set Codegen to Manual for my Core Data models so I have full control of them and even more so when having Core Data in a package or pod like this. Are you sure the files has been generated properly, maybe you need to do a clean build. Commented Mar 2, 2024 at 6:36
  • Hi @JoakimDanielson, yes I did clean build. I am not accessing core data entity into parent app. Core data apis are only in child app. And still getting this error in child app? You can see the errors are only showing in child app development pods. Commented Mar 3, 2024 at 2:04
  • Got the solution: There are 2 things to fix as - 1. Update your Xcode project build option ENABLE_USER_SCRIPT_SANDBOXING to 'No', 2. subspec.resources = 'ChildApp/**/*.{xcdatamodeld}' in podspec file. Thanks Commented Mar 3, 2024 at 2:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.