in Swift 1.2
in Swift 2.0 (error) , so I change my code as follows.
let url = NSURL(string:"http://dl-8.one2up.com/onetwo/content/2015/6/15/9c3b51249fbbe20ca9d841401e276d97.php")
let allContactsData = NSData(contentsOfURL:url!)
do{
var allContacts : AnyObject! = try NSJSONSerialization.JSONObjectWithData(allContactsData!, options: NSJSONReadingOptions())
}catch{
print(error)
}
if let json = allContacts as? Array<AnyObject> {
print(json)
for index in 0...json.count-1 {
let contact : AnyObject? = json[index]
let collection = contact! as! Dictionary<String, AnyObject>
let name : AnyObject? = collection["AnimeName"]
let cont : AnyObject? = collection["Episodes"]
names.append(name as! String)
episodes.append(cont as! String)
}
}
print(names)
print(episodes)
But that doesn't work.
if let json = allContacts as? Array< AnyObject >
error : Use of unresolved identifier 'allContacts'