The code that causes the cells in the table view to display dictionary-type arrays does not know where to retrieve dictionary key arrays or data.Could you let me know?Thank you for your reply.
The errors are as follows:
①Ambiguous reference to member 'subscript' (line 109)
②Value of type '[String:Bool]]' has no member 'updateValue' (line 123, 148)
③Value of type '[String:Bool]]' has no member 'keys'' (line 152)
I searched online and tried, but I couldn't find anything I could solve.
CCannot use instance member… 」 error creating table view
Unlike the Swift language-specific errors mentioned in the previous question, if this is caused by misunderstanding about the data type, it will be difficult to find a solution even if you search by error message.
In your code,
tableData has a data type of
[[String:Bool]] (this is the same as
Array<Dictionary>String,Bool>>), and it is called
Dictionary as an element.
Once the element type is left behind,
tableDatais an array (
You have five dictionary data in
checkListItem5), but you will not be able to choose a Swift language or iOS framework to access
tableData as a dictionary.
Am Ambiguous reference to member's subscription'
*The line number is not displayed in StackOverflow code sample, and the number seems to be much different. If you specify the line where the error occurs in the form of a comment in the source code such as
//<-1, it will definitely be easier to see the error.
So は means this part?
As I wrote earlier,
tableData is an array type with the element
Bool dictionary type, so it is an integer value (
(indexPath as NSIndexPath).section, by the way,
indexPath.section).omitted in ) only means that the integer value
(indexPath as NSIndexPath).row (also
indexPath.row is acceptable).
If you say ambiguous as the error message says, I think there's a way to eliminate ambiguity and clarify it, but Swift's error message around here is still developing and should be read to mean "there are errors related to the data type regarding 'subscript'.
VValue of type'[[String:Bool]]'has no member 'updateValue'
Do you mean here:
Exactly what I wrote at the beginning is true, but
updateValue(_:forKey:) is a method defined for dictionary types and cannot be used for array types.The array type
[String:Bool] has no methods or properties such as
updateValue (collectively referred to as member).
*By the way, if you simply want to update the Swift dictionary value, you don't usually use
VValue of type'[[String:Bool]]'has no member 'keys'
Do you mean this?
It's almost the same thing over and over again, but
tableData is an array type, but using
keys (which is a dictionary type property), the same error as と is displayed.
The problem is that
tableData has five elements in an array, but you can access it as if it were a dictionary (as if one were automatically selected), so you can choose one of the
tableData and use it as a dictionary.
In addition, I added corrections to the relevant parts, but specifically the following are the following:
viewDidLoad()The following three methods are subject to correction.
There may still be other errors in the details, but I think the above correction will prevent the errors you mentioned in this question.Try it.
© 2022 OneMinuteCode. All rights reserved.