URLRepresentableEntity with custom properties

I am trying to implement URLRepresentableEntity on my AppEntity

I am following along with the WWDC video here

All compiles fine when I use the ID as in the video:

extension SceneEntity: URLRepresentableEntity {
  static var urlRepresentation: URLRepresentation {
    "https://example.com/scene/\(.id)"
  }
}

but my URLs need to use a different property on the Entity. The WWDC video clearly states: "Notice that I'm using the entity’s identifier as an interpolated value. You can use an entity’s ID or any of its properties with the @Property attribute as interpolations in the URL string."

So I annotated my entity with the @Property attribute and expected that to work but it doesn't compile.

struct SceneEntity: AppEntity {
  let id: UUID
  @Property(title: "Slug") var slug: String
}


extension SceneEntity: URLRepresentableEntity {
  static var urlRepresentation: URLRepresentation {
    "https://example.com/scene/\(.slug)"
  }
}

Type 'EntityURLRepresentation<SceneEntity>.StringInterpolation.Token' has no member 'slug'

How can I use this API with a property that is not the ID?

Answered by prathameshk in 827474022

Hey I don't know if you're still looking for the answer, but in case someone else is, the solution is to use they key path to the projected value of any property marked with @Property, like "https://example.com/scene/\(.$slug)" in your example

Accepted Answer

Hey I don't know if you're still looking for the answer, but in case someone else is, the solution is to use they key path to the projected value of any property marked with @Property, like "https://example.com/scene/\(.$slug)" in your example

Hey I don't know if you're still looking for the answer, but in case someone else is, the solution is to use the key path to the projected value of any property marked with @Property, like "https://example.com/scene/(.$slug)" in your example.

Hey I don't know if you're still looking for the answer, but in case someone else is, the solution is to use the key path to the projected value of any property marked with @Property, like "https://example.com/scene/\(\.$slug)" in your example.

URLRepresentableEntity with custom properties
 
 
Q