Questions tagged [identifiable]

Swift protocol used to uniquely identify instances.

Identifiable is a Swift protocol used to uniquely identify instances. You must implement the id computed-property to satisfy the protocol requirements.

Apple's description:

A class of types whose instances hold the value of an entity with stable identity.

Commonly used in conjunction with SwiftUI's ForEach.

37 questions
0
votes
1 answer

Protocol oriented Programming Swift - Identifiable

Lets say I want to model a fantasy-game with protocol oriented programming in swift. the code below produces the following error: Protocol 'Character' can only be used as a generic constraint because it has Self or associated type…
user14534957
  • 336
  • 3
  • 10
0
votes
0 answers

SWIFT. How to write a structure for data correctly IN XCODE

I ask for a hint on how to write the structure and data model correctly. I want a piece of data from the decoder. Is it possible to do this? Important! I was marked with a "???" a place where I don't know what to write. class TodayViewModel :…
Pavel M.
  • 21
  • 3
0
votes
2 answers

Crash on nested ForEach inside a LazyHStack

I have two nested ForEachs inside a LazyHStack LazyHStack { ForEach(items) { item in ForEach(item.urls, id: \.self) { Text($0.absoluteString) } } } This snippets compiles, but it immediately crashes with the…
Dree
  • 702
  • 9
  • 29
0
votes
1 answer

SwiftUI Edit Struct from List

I am attempting to have a list that when a cell it tapped it changes the hasBeenSeen Bool value within the State object itself. struct State: Identifiable { var id = UUID() let name: String var hasBeenSeen: Bool = false } struct…
Caleb Rudnicki
  • 345
  • 8
  • 17
-1
votes
1 answer

How to conform an Array to 'Identifiable'

I'm confused about how Identifiable arrays work. For instance, I have the following array returned as a response to a function: Optional (["Jane", "John", "Eric", "Erika", "Motto"]) Now, I want to show this as a list but we know that list items…
Mansidak
  • 136
  • 6
-1
votes
2 answers

How can I add a `view` type to my identifiable data?

I have the following data which is my identifiable. What I am trying to do is that I want to add a type of view as well so later I can give a Button that will link to those views. I don't know how to accomplish this. It says it doesn't accept view…
Yonus
  • 233
  • 2
  • 12
-2
votes
1 answer

What is the `Identifiable` in SwiftUI, and Where we used it

I didn't understand what is the Identifiable protocol, and how can we used it can you explain it for me for example struct MyStruct: Identifiable { let id: String } Which scene it used, I found it can be used for List selection
Duke
  • 47
  • 4
1 2
3