为什么我收到“EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子代码= 0x0)”

时间:2015-12-09 08:56:28

标签: xcode swift

我正在

  

“EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子代码= 0x0)”

在此代码中

else {
    let latitude = NSString(string: places[activePlace]["lat"]!).doubleValue
    let longitude = NSString(string: places[activePlace]["lon"]!).doubleValue
    let coordinate = CLLocationCoordinate2DMake(latitude, longitude)
    let latDelta:CLLocationDegrees = 0.01
    let lonDelta:CLLocationDegrees = 0.01
    let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)
    let region:MKCoordinateRegion = MKCoordinateRegionMake(coordinate, span)
    self.Map.setRegion(region, animated: true)
    let annotation = MKPointAnnotation()
    annotation.coordinate = coordinate

    annotation.title = places[activePlace]["name"]
    self.Map.addAnnotation(annotation)

on

 let latitude = NSString(string: places[activePlace]["lat"]!).doubleValue

这是我的活动地点变量女巫在上一个表视图

var activePlace = -1]

仍然在tableview中我有这个

 override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {

        activePlace = indexPath.row

        return indexPath

    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        if segue.identifier == "newPlace" {

            activePlace = -1


        }

在第二个视图控制器中(我有问题) 我在视图中有这个加载

manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest

if activePlace == -1 {

    manager.requestWhenInUseAuthorization()
    manager.startUpdatingLocation()


} else {



    let latitude = NSString(string: places[activePlace]["lat"]!).doubleValue

    let longitude = NSString(string: places[activePlace]["lon"]!).doubleValue

    let coordinate = CLLocationCoordinate2DMake(latitude, longitude)

    let latDelta:CLLocationDegrees = 0.01

    let lonDelta:CLLocationDegrees = 0.01

    let span:MKCoordinateSpan = MKCoordinateSpanMake(latDelta, lonDelta)

    let region:MKCoordinateRegion = MKCoordinateRegionMake(coordinate, span)

    self.Map.setRegion(region, animated: true)

    let annotation = MKPointAnnotation()

    annotation.coordinate = coordinate


    annotation.title = places[activePlace]["name"]

    self.Map.addAnnotation(annotation)

这段代码已经存在并且完美无缺,直到我添加了以下代码

@IBAction func addCurentLoc(sender: UIBarButtonItem) {

        var newCoordinate2 = self.Map.userLocation.location!.coordinate;

        var location = CLLocation(latitude: newCoordinate2.latitude, longitude: newCoordinate2.longitude)

        title = "new address"


        let annotation = MKPointAnnotation();
        annotation.title = title;
        annotation.coordinate = self.Map.userLocation.location!.coordinate;

        CLGeocoder().reverseGeocodeLocation(location) { (placemarks, error) -> Void in

            var title = ""

            if (error == nil) {

                if let p = placemarks?[0] {

                    var subThouroughfare:String = ""
                    var thouroughfare:String = ""

                    if p.subThoroughfare != nil {

                        subThouroughfare = p.subThoroughfare!

                    }

                    if p.thoroughfare != nil {

                        thouroughfare = p.thoroughfare!

                    }

                    title = "\(subThouroughfare) \(thouroughfare)"


                }

            }

            if title == "" {

                title = "Added \(NSDate())"

            }

            places.append(["name":title,"lat":"\(newCoordinate2.latitude)","lon":"\(newCoordinate2.longitude)"])

            let annotation = MKPointAnnotation()

            annotation.coordinate = newCoordinate2

            annotation.title = title

            self.Map.addAnnotation(annotation)

        }

        self.Map.addAnnotation(annotation);



        func mapView(mapView: MKMapView!,
            viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView!{
                if(annotation is MKUserLocation){
                    return nil;
                }

                let pinView: Void = mapView.addAnnotation(annotation);
                let pinAnnotationView = MKPinAnnotationView(annotation: annotation,reuseIdentifier:"MyIdentifier");
                return pinAnnotationView;

                       }



    }

我一直在寻找解决方案一段时间而无法找到,请注意我已经检查了这个答案

EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) on dispatch_semaphore_dispose

以及这个

what does Error "Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)" mean?

但是没有找到解决方案,谢谢你的帮助

编辑:请注意,此问题已被修改为更清晰,请询问您是否需要更多信息。

1 个答案:

答案 0 :(得分:0)

在你的第一行放一个断点然后输入lldb:

po places[activePlace] - 它返回值还是零?

如果返回值类型places[activePlace]["lat"]!

其中一个可能会返回nil,你得到的错误意味着你隐含地解开零。