-1

this is actually a follow up to this question: how can I convert NSArray into specific String? Bryan's answer worked for me in previous version of Swift, but now when I moved to Swift 3, this code:

if (defaults.object(forKey: "fb_friends") != nil) {
    var friends = (defaults.objectForKey("fb_friends") as! NSMutableArray)
                    .map{$0["id"]!!}
                    .joinWithSeparator(",")
                friends+=",\(defaults.stringForKey("facebookId")!)"
                params["friends"] = friends 
            }

and especially this line .map{$0["id"]!!} throws me an error:

Type NSFastEnumerationIterator.Element (aka Any) has no subscript members

what might be the problem here?

Community
  • 1
  • 1
user3766930
  • 5,629
  • 10
  • 51
  • 104

1 Answers1

1

The error message is clear that you can no longer to access subscript members from Any in Swift 3.

In this case, you can cast it to NSDictionary.

var friends = (defaults.objectForKey("fb_friends") as! NSArray)
    .map{($0 as! NSDictionary)["id"] as! String}
    .joined(separator: ",")
Bryan Chen
  • 45,816
  • 18
  • 112
  • 143