Back to Sourcery

Hashable Reference

docs/hashable.html

2.3.01.1 KB
Original Source

I want to generate Hashable implementation

Template used to generate hashing for all types that conform to :AutoHashable, allowing us to avoid writing boilerplate code.

It adds :Hashable conformance to all types, except protocols (because it would require turning them into PAT’s). For protocols it’s just generating var hashValue comparator.

Stencil template

Available variable annotations:

  • skipHashing allows you to skip variable from being compared.
  • includeInHashing is only applied on enums and allows us to add some computed variable into hashing logic

Example output:

// MARK: - AdNodeViewModel AutoHashable
extension AdNodeViewModel: Hashable {

    internal var hashValue: Int {
        return combineHashes(remoteAdView.hashValue, hidesDisclaimer.hashValue, type.hashValue, height.hashValue, attributedDisclaimer.hashValue, 0)
    }
}

Copyright © 2016-2021 Pixle. All rights reserved.

Generated by jazzy ♪♫ v0.14.0, a Realm project.