I am new to swift. I want to get options in
fields: [{ config: { options: [{a: "one", b: "two"}] }}]
I have tried the following code but it brings an error "AnyObject? does not have a member named subscript".
I am new to swift. I want to get options in
fields: [{ config: { options: [{a: "one", b: "two"}] }}]
I have tried the following code but it brings an error "AnyObject? does not have a member named subscript".
AnyObject?
is really Optional<AnyObject>
, and subscripts are not defined on the Optional
type, however, I tried your code with a simulated fields dictionary and I had no issue, so may be your example has context not expressed here? Try making it ... as? AnyObject {
rather than ... as AnyObject! {
to see if that makes any difference. Also, simply quitting and reopening Xcode has shown to fix many of these types of issues :-)
I tried this and it works.
if let config: AnyObject? = fields[i]["config"] {
if let options: AnyObject? = config?["options"] {
println("options : \(options)")
}
}