Skip to content
This repository was archived by the owner on Nov 15, 2020. It is now read-only.
This repository was archived by the owner on Nov 15, 2020. It is now read-only.

Refactoring for ModelProtocol protocol #3

@hachinobu

Description

@hachinobu

Hi, @malcommac

Thank you for providing a nice library.

Please tell me about the implementation of ModelProtocol.

If the object conforms to the Equatable protocol, i can use the default implementation of Extension so i do not need to write isEqual method.

Likewise, if the object conforms to the Hashable protocol, i do not want to write the identifier property.

Is there a problem with the code below?

extension ModelProtocol where Self: Hashable {
	
    public var identifier: Int {
        return self.hashValue
    }
    
    //remove code
//    public var hashValue: Int {
//        return self.identifier.hashValue
//    }
	
}

It seems that compatibility is good.

Synthesizing Equatable and Hashable conformance

I think that implementation will be easier.

best regards.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions