Skip to content

Instantly share code, notes, and snippets.

@hfossli
Created February 18, 2021 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hfossli/fa774ae6f7959a6d9d0476233f8d6cd7 to your computer and use it in GitHub Desktop.
Save hfossli/fa774ae6f7959a6d9d0476233f8d6cd7 to your computer and use it in GitHub Desktop.
AutoID
struct AutoID: Hashable {
private var parent: AnyHashable?
private var file: String
private var line: UInt
private var column: UInt
init(parent: AnyHashable? = nil, file: String = #file, line: UInt = #line, column: UInt = #column) {
self.parent = parent
self.file = file
self.line = line
self.column = column
}
}
@hfossli
Copy link
Author

hfossli commented Feb 18, 2021

Can be used like this

environment: { env in
    AvatarEnvironment(cancellationId: AutoID(parent: env.cancellationId))
}
...
environment: { env in
    AvatarEnvironment(cancellationId: AutoID(parent: env.cancellationId))
}

Will be pretty much the same as writing

environment: { env in
    struct CancelId: Hashable {}
    return AvatarEnvironment(cancellationId: [env.cancellationId, CancelId()])
}
...
environment: { env in
    struct CancelId: Hashable {}
    return AvatarEnvironment(cancellationId: [env.cancellationId, CancelId()])
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment