错误:
2017-07-13 16:02:03.635000 bihamkapp [1461:1448858] *终止应用 由于未捕获的异常'NSGenericException',原因:'* 集合< __ NSArrayM:0x17005f680>在被诅咒时发生了变异 列举“。 ***首先抛出调用堆栈:(0x1820b91b8 0x180af055c 0x1820b8c00 0x100176584 0x100176030 0x18c1fb934 0x1001484bc 0x101103ae4 0x18530ef24 0x18530edd0 0x182326094 0x18204ee50 0x182067218 0x1820669cc 0x1820644b0 0x181f922b8 0x183a46198 0x187fd97fc 0x187fd4534 0x10007dfac 0x180f755b8)libc ++ abi.dylib:终止于 NSException(lldb)
类型的未捕获异常
代码:
func callWS(){
let url = URL(string: "some url")
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config)
let task = session.dataTask(with: url!, completionHandler: {
(data, response, error) in
if error != nil
{
print("Error")
}
else
{
if let content = data
{
do
{
let myJSON = try JSONSerialization.jsonObject(with: content, options: JSONSerialization.ReadingOptions.mutableContainers) as? [[String:AnyObject]]
self.myCopyJSON = myJSON!
for post in self.myCopyJSON {
var icon = post["type"]
if let checkNull = post["type"] as? NSDictionary {
print(checkNull)
}
else{
let tipRadara:Int = icon as! Int
switch tipRadara
{
case 1:
icon = "radar_stacionarni" as AnyObject
case 2:
icon = "radar_najavljeni" as AnyObject
default:
icon = "" as AnyObject
}
let title = post["title"]
let coordinates = post["coordinates"]
let text = post["text"]
if((coordinates?.length)! > 0 && (title?.length)! > 0 && (icon?.length)! > 0){
let coord_2 = coordinates?.components(separatedBy: ",")
let coord_1_part: String = coord_2![0]
let coord_2_part: String = coord_2![1]
var stanjeMarker: NMAMapMarker?
let coordinates: NMAGeoCoordinates = NMAGeoCoordinates(latitude: Double(coord_1_part)!, longitude: Double(coord_2_part)!)
stanjeMarker = NMAMapMarker(geoCoordinates: coordinates)
let pdfImageIcon: UIImage = UIImage.imageWithPDFNamed(icon as! String, fitSize: CGSize(width:100, height:100))!
stanjeMarker?.icon = pdfImageIcon
stanjeMarker?.title = title as! String
stanjeMarker?.textDescription = text as! String
self.mapView.add(stanjeMarker!)
}
else {
print("else length > 0")
}
}
}
}
catch {
}
}
}
})
task.resume()
}
override func viewDidLoad() {
super.viewDidLoad()
mapView.useHighResolutionMap = true
mapView.zoomLevel = 7
mapView.set(geoCenter: NMAGeoCoordinates(latitude: 43.915886, longitude: 17.67907600000001), animation: .none)
mapView.copyrightLogoPosition = NMALayoutPosition.bottomCenter
self.mapView.delegate = self
callWS()
}