alickbass / CodableFirebase

Use Codable with Firebase
MIT License
691 stars 91 forks source link

Using Codable FieldValue and Codable Timestamp in framework #66

Closed lozflan closed 5 years ago

lozflan commented 5 years ago

Im using CodableFirebase with Firebase Firestore. Im using FieldValue and Timestamps so I've added the required following extension lines to my code.

extension DocumentReference: DocumentReferenceType {} extension GeoPoint: GeoPointType {} extension FieldValue: FieldValueType {} extension Timestamp: TimestampType {}

I have a simple IDRequest struct and a simple IDRequestStatus enum with associated values which conform to Codable. Everything works fine if the code for these 2 objects and the above extensions are contained within my app ie i can code and decode the objects successfully.

My app structure however is 2 related apps using a common custom framework so I want the code for the above objects to reside in the framework. If I move the code for the 2 above objects and the extensions from the app to the framework instead, CodableFirebase doesn't work and I get error:typeIsNotSupported error. I am only using FieldValue and Timestamp types in my code (not DocumentReference and GeoPoint).

Is CodableFirebase not compatible with use in custom frameworks?. Any help appreciated.

serjooo commented 5 years ago

I have personally never worked with frameworks; however, from what I've seen with code that I've read while working with Frameworks you need to declare the correct Access Control for some code to be available for the rest of the codebase. I think adding the public modifier to the extensions might help that extension propagate down the other projects if you have imported it.

lozflan commented 5 years ago

Hi serjooo, thx for your reply. I haven't been able to solve this. I tried that previously and adding the public modifier to the extensions in the framework doesn't work. It gives compiler error "'public' modifier cannot be used with extensions that declare protocol conformances".

serjooo commented 5 years ago

Oh yes Swift doesn't allow that.. Did you attempt at creating a class that satisfies both requirements and declare it public so that you can use it. For example:

public class FirestoreGeopoint: GeoPoint, GeoPointType {

    required override public init(latitude: Double, longitude: Double) {
        super.init(latitude: latitude, longitude: longitude)
    }

}

I know its extra work, but I'm not sure how else this could be solved personally.

serjooo commented 5 years ago

@lozflan any updates on this?

lozflan commented 5 years ago

Sorry. Been sidetracked. I’ll try your suggestion this weekend

serjooo commented 5 years ago

@lozflan closing this as thread has gone stale