Using ForEach with a string array - [String] has no member 'identified'

前端 未结 4 1047
走了就别回头了
走了就别回头了 2021-01-22 08:58

I\'m using Xcode 11 beta 5 and what I had it doesn\'t work anymore. This is my code:

struct ModeView : View {
  @EnvironmentObject var state: IntentionState

  v         


        
相关标签:
4条回答
  • 2021-01-22 09:45

    ForEach syntax changed a little bit in Beta 5.

    Have you tried:

    ForEach(state.modes, id: \.self) { mode in
        Text(mode)
    }
    
    0 讨论(0)
  • 2021-01-22 09:46

    let suppose you have a name array like this:

    let names = ["mike","Jack","jill"]
    
    ForEach(names, id: \.self) { Text($0) }
    

    Text($0) - this will print all elements from your names array.

    Note:

    Use backslashsign.self instead .self, somehow backslash sign is not working here

    0 讨论(0)
  • 2021-01-22 09:50

    As per the apple release note, it's known issue from their end. We have to wait for another release.

    https://developer.apple.com/documentation/ios_ipados_release_notes/ios_ipados_13_beta_5_release_notes

    0 讨论(0)
  • 2021-01-22 10:04

    The identified(by:) method has been deprecated, the correct syntax is now:

    init(Data, id: KeyPath<Data.Element, ID>, content: (Data.Element) -> Content)

    or after moving the content into a closure :

    ForEach(state.modes, id: \.self) { mode in Text(mode) }
    
    0 讨论(0)
提交回复
热议问题