"<Class> does not conform to protocol 'ImportableUniqueObject'" when updating to CoreStore 3.1.0 #130

Closed
opened 2025-12-29 15:25:12 +01:00 by adam · 2 comments
Owner

Originally created by @wbuchner on GitHub (Mar 29, 2017).

Im updating from Swift 2 -> 3.1.0 and run across an issue I need some help with.
My class is below. It works beautifully in Swift 2.0 and I haven't had any issues. I am experiencing an issue with some warnings, and the Xcode telling me that I am not fully complying with the protocol. I can't see anything missing.
Can you please see what I cannot? I would appreciate it.

This is the warning I am getting
screenshot 2017-03-29 21 58 06

public class Contact: SEManagedObject, ImportableUniqueObject {

    public typealias ImportSource = [String:AnyObject]
    public typealias UniqueIDType = NSObject

    /**
     Description
     
     - parameter data: the dictionary with the data to save
     - returns
     */
    class func storeContact(
        data: [NSDictionary],
        success: @escaping (SaveResult) -> Void,
        failure: @escaping (SaveResult) -> Void) {

        //  swiftlint:disable:next identifier_name
        CoreStore.beginAsynchronous { (AsynchronousDataTransaction) in
           let result = try! AsynchronousDataTransaction.importUniqueObjects(
                Into(Contact.self), sourceArray: (data as? [[String:AnyObject]])!
            )
        }
    }
    public func update(from source: Contact.ImportSource, in transaction: BaseDataTransaction) throws {

    }

    //  swiftlint:disable:next function_body_length
    public static func shouldUpdate(from source: Contact.ImportSource,
                                    in transaction: BaseDataTransaction) -> Bool {
        // all insert code here
        return true
    }

    public static func shouldInsert(from source: Contact.ImportSource,
                                    in transaction: BaseDataTransaction) -> Bool {
        return true
    }

    public var uniqueIDValue: NSObject {
        get { return self.identification! as NSObject }
        set {
            self.identification = (newValue as? String)!
        }
    }

    public func didInsert(from source: Contact.ImportSource, in transaction: BaseDataTransaction) throws {
        
    }
    public static var uniqueIDKeyPath: String {
        return "identification"
    }
 
   public static func uniqueID(from source: Contact.ImportSource,
                         in transaction: BaseDataTransaction) throws -> Contact.UniqueIDType? {
        let contact = source["contact"]
        return contact!["Id"] as? NSString
    }
}
Originally created by @wbuchner on GitHub (Mar 29, 2017). Im updating from Swift 2 -> 3.1.0 and run across an issue I need some help with. My class is below. It works beautifully in Swift 2.0 and I haven't had any issues. I am experiencing an issue with some warnings, and the Xcode telling me that I am not fully complying with the protocol. I can't see anything missing. Can you please see what I cannot? I would appreciate it. This is the warning I am getting ![screenshot 2017-03-29 21 58 06](https://cloud.githubusercontent.com/assets/241315/24451576/23ad0520-14cb-11e7-8ef0-5c8cb339399a.png) ```swift public class Contact: SEManagedObject, ImportableUniqueObject { public typealias ImportSource = [String:AnyObject] public typealias UniqueIDType = NSObject /** Description - parameter data: the dictionary with the data to save - returns */ class func storeContact( data: [NSDictionary], success: @escaping (SaveResult) -> Void, failure: @escaping (SaveResult) -> Void) { // swiftlint:disable:next identifier_name CoreStore.beginAsynchronous { (AsynchronousDataTransaction) in let result = try! AsynchronousDataTransaction.importUniqueObjects( Into(Contact.self), sourceArray: (data as? [[String:AnyObject]])! ) } } public func update(from source: Contact.ImportSource, in transaction: BaseDataTransaction) throws { } // swiftlint:disable:next function_body_length public static func shouldUpdate(from source: Contact.ImportSource, in transaction: BaseDataTransaction) -> Bool { // all insert code here return true } public static func shouldInsert(from source: Contact.ImportSource, in transaction: BaseDataTransaction) -> Bool { return true } public var uniqueIDValue: NSObject { get { return self.identification! as NSObject } set { self.identification = (newValue as? String)! } } public func didInsert(from source: Contact.ImportSource, in transaction: BaseDataTransaction) throws { } public static var uniqueIDKeyPath: String { return "identification" } public static func uniqueID(from source: Contact.ImportSource, in transaction: BaseDataTransaction) throws -> Contact.UniqueIDType? { let contact = source["contact"] return contact!["Id"] as? NSString } } ```
adam added the question label 2025-12-29 15:25:12 +01:00
adam closed this issue 2025-12-29 15:25:12 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Mar 29, 2017):

@wbuchner Hi, starting CoreStore 3.0.3 the ImportSource does not need to be NSObject.
You can use typealias UniqueIDType = String or NSString directly.

Also, var uniqueIDValue now has a default protocol implementation (you can remove it completely from your code) as long as you specify the var uniqueIDKeyPath correctly.

Please check ImportableUniqueObject.swift for the actual changes and ImportableAttributeType.swift for a list of supported UniqueIDType types.

@JohnEstropia commented on GitHub (Mar 29, 2017): @wbuchner Hi, starting CoreStore 3.0.3 the `ImportSource` does not need to be `NSObject`. You can use `typealias UniqueIDType = String` or `NSString` directly. Also, `var uniqueIDValue` now has a default protocol implementation (you can remove it completely from your code) as long as you specify the `var uniqueIDKeyPath` correctly. Please check ImportableUniqueObject.swift for the actual changes and ImportableAttributeType.swift for a list of supported `UniqueIDType` types.
Author
Owner

@wbuchner commented on GitHub (Mar 29, 2017):

Thank you John!

@wbuchner commented on GitHub (Mar 29, 2017): Thank you John!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#130