'init(_:content:)' is deprecated: Use the 'IdentifiedArray'-based version, instead. #1458
-
Hi, there. Currently I am trying to build my Project using TCA and to avoid repetition of The below codes seem to work fine, but I get the warning that says Umm...is there some way to avoid the deprecation warning? // CertificationSectionView.swift
.
.
.
ForEachStore(self.store.scope(
state: { $0.certificationUploadStates },
action: { .certificationUploadAction(index: $0, action: $1)}
)
) { certificationUploadStore in
CertificationUploadView(store: certificationUploadStore)
CertificationUploadView(store: certificationUploadStore)
} // CertificationSectionCore.swift
struct CertificationSectionState: Equatable {
var title: String
var mandatoryNumber: Int
var certificationUploadStates: [CertificationUploadState]
var isCertificationEnough: Bool = false
}
enum CertificationSectionAction: Equatable {
case certificationUploadAction(index: Int, action: CertificationUploadAction)
case onValidation(index: Int)
}
struct CertificationSectionEnvironment { } |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Sorry, should have read documents more carefully. Need id, not index. |
Beta Was this translation helpful? Give feedback.
-
Hey @inwoodev. Indeed, To avoid the warning, you should convert your |
Beta Was this translation helpful? Give feedback.
Hey @inwoodev. Indeed,
ForEachStore
andforEach
reducer don't support non-keyed collections likeArray
s for quite some time now. Because indices are not a stable identifier inArray
, actions could be addressed to the wrong child reducer if one element of the array was removed for example.To avoid the warning, you should convert your
[CertificationUploadState]
to anIdentifiedArray
which is more or less like anOrderedDictionary
, where each element is identified by an identifier instead of an index. IfCertificationUploadState
isIdentifiable
, you can directly create anIdentifiedArrayOf<CertificationUploadState>
that will use this value'sid
as a key. If it's not the case, and while you …