Tag: fatal error

AVAudioPlayer working on Simulator but not on Real Device

While I play recorded Audio I get this error: fatal error: unexpectedly found nil while unwrapping an Optional value on this line of code: SoundPlayer = try AVAudioPlayer(contentsOfURL: getFileURL()) But it is working perfectly on Simulator except real device. ViewController.Swift: import UIKit import AVFoundation class ViewController: UIViewController, AVAudioPlayerDelegate, AVAudioRecorderDelegate { @IBOutlet var PlayBTN: UIButton! @IBOutlet […]

How can I fix “fatal error: can't index empty buffer”

I try to develop a custom autocompletion for a textfield. The code works but if I delete all my input, the debugger says: “fatal error: can’t index empty buffer” in the line where is written: if createdArrayInDependencyOfInput[indexOfArray] == textFieldText && indexOfArray >= 0 && currentCountOfInput >= 1 Here is the whole code: @IBOutlet weak var […]

Inter-app communication in iOS using URL scheme

I have two test apps: App1 & App2. App1 takes String from the text field and triggers method: @IBAction func openApp(sender: AnyObject) { let url1 = (“app2://com.application.started?displayText=”+textToSend.text!) let url2 = url1.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) UIApplication.sharedApplication().openURL(NSURL(string: url2!)!) } Which actually opens App2 which has only label which should change to the text sent through the url, code is within […]

How to ensure make sure I´m not accessing data until it´s loaded in?

I´m new at programming and I my code gets the error: fatal error: unexpectedly found nil while unwrapping an Optional value 2017-10-27 16:06:16.755817+0200 Inspireme1.0[836:85307] fatal error: unexpectedly found nil while unwrapping an Optional value (lldb) New error: fatal error: Index out of range 2017-10-27 19:08:05.488502+0200 Inspireme1.0[1262:771572] fatal error: Index out of range (lldb) I already […]

Unit Test fatalError in Swift

How to implement unit test for a fatalError code path in Swift? For example, I’ve the following swift code func divide(x: Float, by y: Float) -> Float { guard y != 0 else { fatalError(“Zero division”) } return x / y } I want to unit test the case when y = 0. Note, I […]

fatal error: swapping a location with itself is not supported with Swift 2.0

I have this extension which will create a new array which have group of arrays randomly from given array: extension Array { var shuffle:[Element] { var elements = self for index in 0..<elements.count { swap(&elements[index], &elements[ Int(arc4random_uniform(UInt32(elements.count-index)))+index ]) } return elements } func groupOf(n:Int)-> [[Element]] { var result:[[Element]]=[] for i in 0…(count/n)-1 { var tempArray:[Element] […]

Error while retrieving data from parse.com

Hello I want to get some data from my parse.com class called “Tags” in this class there are two 3 cols “objectID”, “username” and “tagtext”. I want to read a record finding by ID and afterwords I want to save “useername” and “tagtext” into two strings. I have done it like it is in the […]

swift can catch fatal error?

I am trying to use Swift 2.0 try-catch. I originally had the following code override func viewDidLoad() { var obj : Object?; Hi( obj ); } But it procdues an error func Hi( open : Open? ) -> Open? { open!.Hi(); <– here is error point. Fatal error ! print( “OK” ); return open; } […]