Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: A better way to handle the Model protocol. #77

Open
2 tasks
xeokeri opened this issue Dec 2, 2018 · 0 comments
Open
2 tasks

Suggestion: A better way to handle the Model protocol. #77

xeokeri opened this issue Dec 2, 2018 · 0 comments

Comments

@xeokeri
Copy link

xeokeri commented Dec 2, 2018

Context and Description

Trying to create a project where the Query filtering components and the Model components, that are outside of the scope of SwiftKuery/SwiftKueryORM/etc..., are in individual frameworks. The framework that mainly interacts with the Models in my implementation, doesn't allow for the models to directly access the Query.framework. Query.framework has access to Models.framework, but Models.framework does not have access to Query.framework. Both have access to SwiftKuery/SwiftQueryORM/etc..

There are additional enhancements to filtering, beyond filtering by ID as well as additional updateOrInsert handling that I've worked on. Though, the models don't have access to this. To solve my problem, I'd need to flip it, so that Models.framework imports Query.framework, and then add an extension to the SwiftKueryORM.Model to be able to do the work that Query.framework is already doing. I would prefer that the models be agnostic to the Query.framework, but it seems that is not the way SwiftKueryORM.Model wants it. Spent 12 hours trying to find a way around it, but it seems that all the Self references in the Model.swift protocol and extension prevent that.

Environment Details

Running macOS 10.14.1, Xcode 10.1, Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)

Steps to Reproduce

  1. Create a method that returns Model.Type or a method that accepts a parameter as Model
  2. Swift errors will be displayed.

Expected vs. Actual Behaviour

  • Expected: Ability to pass Model to a method without having to use extensions on the model.
  • Actual: Error message displays saying the protocol can't be used as a parameter or even as a return type, such as Model.Type
public struct RandomModel : Model
    public fileprivate(set) var date: Date
    public fileprivate(set) var updated: Date
    public fileprivate(set) var uuid: UUID?
    // ...
}

public final class RandomClass {
    // error displayed for the return value.
    func modelType() -> Model.Type {
        return RandomModel.self
    }
    
    // error displayed for the parameter type.
    func handleModel(_ model: Model) {
        // ...
    }
}

Error Message Displayed

Protocol 'Model' can only be used as a generic constraint because it has Self or associated type requirements
@kilnerm kilnerm self-assigned this Jun 5, 2019
@kilnerm kilnerm added this to the 2019.12 milestone Jun 5, 2019
@kilnerm kilnerm modified the milestones: 2019.12, 2019.13 Jun 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants