Reputation: 11
I am a beginner in Swift and I am currently building an app for a school project. When I was trying to test my app, it said 'build succeeded' but then suddenly closed down, and on the ViewController.swift screen it had a green line with the error:
'Thread 1: breakpoint 3.5'
I have searched online for any possible answers but I couldn't find any. Could someone be so kind to help me? Thank you!
UPDATE: Now there is an error saying 'Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)'. I have searched and I don't know how to fix this... Anyone?
Here is the code:
import UIKit
import AVFoundation
class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate
{
@IBOutlet weak var pickerView: UIPickerView!
var pickerDataSource = ["White", "Red", "Green", "Blue"];
override func viewDidLoad() {
super.viewDidLoad()
self.pickerView.dataSource = self;
self.pickerView.delegate = self;
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerDataSource.count;
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return pickerDataSource[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
if(row == 0)
{
self.view.backgroundColor = UIColor.whiteColor();
}
else if(row == 1)
{
self.view.backgroundColor = UIColor.redColor();
}
else if(row == 2)
{
self.view.backgroundColor = UIColor.greenColor();
}
else
{
self.view.backgroundColor = UIColor.blueColor();
}
};
var audioPlayer = AVAudioPlayer() // This is where the error occurs
@IBAction func PlaySound(sender: UISwipeGestureRecognizer) {
// Set the sound file name & extension
let alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("woosh", ofType: "mp3")!)
do {
// Preperation
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch _ {
}
do {
try AVAudioSession.sharedInstance().setActive(true)
} catch _ {
}
// Play the sound
do {
audioPlayer = try AVAudioPlayer(contentsOfURL: alertSound)
} catch _{
}
audioPlayer.prepareToPlay()
audioPlayer.play()
}
}
Upvotes: 1
Views: 336
Reputation: 672
I have a tableview with many thousands of lines with hundreds of lines of data being added each day.
Even though I have only just started using the breakboints to navigate to where I need to, the breakpoint was already set (maybe I did it by accident one day).
I got the same error when accessing the tableview when testing because when a breakpoint is set, it creates additional ones to the same line. (On my tableview it does anyway)
If you upload the new app either in the simulator or on your device and access the tableview while the app is not connected to Xcode, there is no issue.
You can either disable those additonal breakpoints or just disable the breakpoints which were made because even with the breakpoints disabled, you can still navigate to the necessary breakpoint by clicking the breakpoint in the breakpoint navigator on the left.
Upvotes: 0
Reputation: 4795
First of all go to the Breakpoint Navigator, as described in the picture(1) linked below and then, you will see a breakpoint somewhere in the app. Click on it and then just press the delete button on your keyboard. This should fix your issue.
Upvotes: 1