Xcode 6.1 with Swift: Terminating app due to uncaught exception 'NSUnknownKeyException' - ios

First of all, I am new to Swift/iOS development and just started learning. I am trying to create a simple app that plays/pauses music. The interface has a play and pause buttons, and slider to control the music volume. I have searched SO and found some similar posts, but haven't found them helpful in my situation.
When I build and start the app in Xcode, I got the errors:
2015-04-07 23:04:25.403 Music Player[8772:102170] *** Terminating app due
to uncaught exception 'NSUnknownKeyException', reason:
'[<Music_Player.ViewController 0x7f991ad3a160> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key play.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010a45bf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010bf9fbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010a45bb79 -[NSException raise] + 9
3 Foundation 0x000000010a8737b3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x000000010a3a5e80 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x000000010afacc7d -[UINib instantiateWithOwner:options:] + 1506
.....
22 UIKit 0x000000010ace7420 UIApplicationMain + 1282
23 Music Player 0x0000000109f24afe top_level_code + 78
24 Music Player 0x0000000109f24b3a main + 42
25 libdyld.dylib 0x000000010c779145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I use the AVAudioPlayer class to instantiate a player for playing and pausing music.
var player: AVAudioPlayer = AVAudioPlayer()
#IBAction func play(sender: AnyObject) {
var audioPath = NSString(string: NSBundle.mainBundle().pathForResource("music", ofType: "mp3")!) //file: music.mp3
var error: NSError? = nil
//instantiate the player
player = AVAudioPlayer(contentsOfURL: NSURL(string: audioPath), error: &error) //error pointer
player.prepareToPlay()
player.play()
}
#IBAction func pause(sender: AnyObject) {
player.pause()
}
I haven't done anything yet with the slider other than the below code:
#IBOutlet var slider: UISlider!
#IBAction func sliderChanged(sender: AnyObject) {
}
the GUI is attached below:

if let resourceUrl = NSBundle.mainBundle().URLForResource("1", withExtension: "mp3") {
if NSFileManager.defaultManager().fileExistsAtPath(resourceUrl.path!) {
var error: NSError? = nil
//instantiate the player
player = AVAudioPlayer(contentsOfURL: resourceUrl, error: &error)
player.prepareToPlay()
player.play()
}
}
Update your code like this for avoid crashing if file is not there.
this class is not key value coding-compliant for the key play.
Means If you have a control in your nib (xib file) that is linked to a property (IBOutlet) or method (IBAction) in your view controller, and you have either deleted or renamed the property or method, the runtime can't find it because it has been renamed and therefore crashes.
HERE I created complete working project for you.

Related

Core Data. ...is not key value coding-compliant for the key "(null)"

I have this error after saving entites (DictionaryMarketSubcategoryEntity), than saving them again.
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<DictionaryMarketSubcategoryEntity 0x60000269e2b0> setValue:forUndefinedKey:]: the entity DictionaryMarketSubcategoryEntity is not key value coding-compliant for the key "(null)".'
*** First throw call stack:
(
0 CoreFoundation 0x00007ff8004278cb __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007ff80004dba3 objc_exception_throw + 48
2 CoreFoundation 0x00007ff80042753d -[NSException init] + 0
3 CoreData 0x00007ff8049b8a02 -[NSMergePolicy _mergeToManyUnionRelationshipsForObject:andObject:] + 945
4 CoreData 0x00007ff8049bcf29 -[NSMergePolicy resolveConstraintConflicts:error:] + 5412
5 CoreData 0x00007ff8049bb99a -[NSMergePolicy resolveConflicts:error:] + 210
6 CoreData 0x00007ff80497a534 -[NSManagedObjectContext save:] + 3215
7 FCDev 0x0000000101624e04 $s5FCDev13CoreDataStackC20saveContextIfChangedyyF + 1524
8 FCDev 0x0000000101573f8b $s5FCDev36CoreDataStorageServiceImplementationC5writeyyF + 43
9 FCDev 0x0000000101575710 $s5FCDev36CoreDataStorageServiceImplementationCAA0dE0A2aDP5writeyyFTW + 16
10 FCDev 0x0000000100a02291
Here is entity (DictionaryMarketSubcategoryEntity) that I save. It has child subcategories (DictionaryMarketSubcategoryEntity). If I comment and remove child, then everything OK. It seems that when I save array of DictionaryMarketCategoryEntity it save child entities (DictionaryMarketSubcategoryEntity) and after resaving them, the merge policy give a crash. Why?
Here is code of init:
extension DictionaryMarketCategoryEntity: JSONInitializable {
convenience init(json: JSON) {
self.init(context: AppInstances.shared.storage.context)
self.backgroundColor = json["backgroundColor"].stringValue
self.backgroundImagePath = json["backgroundImage"].stringValue
self.descriptionText = json["description"].stringValue
self.icon = json["icon"].stringValue
self.id = json["id"].stringValue
self.imagePath = json["image"].stringValue
self.parent = json["parent"].stringValue
self.span = json["span"].int16Value
self.title = json["title"].stringValue
self.type = json["type"].stringValue
let childrenJson = json["children"].arrayValue
let childrenEntities = childrenJson.map { DictionaryMarketSubcategoryEntity(json: $0) }
let childrenSet = NSSet(array: childrenEntities)
addToChildren(childrenSet)
}
}
extension DictionaryMarketSubcategoryEntity {
convenience init(json: JSON) {
self.init(context: AppInstances.shared.storage.context)
self.id = json["id"].stringValue
self.title = json["title"].stringValue
self.descriptionText = json["description"].stringValue
self.imagePath = json["image"].stringValue
self.backgroundImagePath = json["backgroundImage"].stringValue
self.backgroundColor = json["backgroundColor"].stringValue
self.icon = json["icon"].stringValue
self.parent = json["parent"].stringValue
self.span = json["span"].int16Value
self.type = json["type"].stringValue
}
}
I've added the parent relationship in subcategory. Then in main entity using addToChildrenEntities - the autogenerated by xcode function. After that the error has gone. It's not because the JSON. It seems that core data fail to merge if child entity (subcategory) doesn't know what is his parent entity.

AudioKit crash: required condition is false: !destNodeMixerConns.empty() && !isDestNodeConnectedToIONode

We are experiencing an exception in our project:
2019-08-08 10:18:28.703708-0600 AppName[99385:5069475] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: !destNodeMixerConns.empty() && !isDestNodeConnectedToIONode'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ee2e8db __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010e21bac5 objc_exception_throw + 48
2 CoreFoundation 0x000000010ee2e662 +[NSException raise:format:arguments:] + 98
3 AVFAudio 0x0000000111b94dbc _Z19AVAE_RaiseExceptionP8NSStringz + 156
4 AVFAudio 0x0000000111bf3937 _Z11_AVAE_CheckPKciS0_S0_b + 295
5 AVFAudio 0x0000000111b8cb8f _ZN18AVAudioEngineGraph8_ConnectEP19AVAudioNodeImplBaseS1_jjP13AVAudioFormat + 1031
6 AVFAudio 0x0000000111bfb598 _ZN17AVAudioEngineImpl7ConnectEP11AVAudioNodeS1_mmP13AVAudioFormat + 194
7 AVFAudio 0x0000000111bfb5ff -[AVAudioEngine connect:to:format:] + 83
8 AppName 0x000000010a424c10 $s8AudioKitAAC6outputAA6AKNodeCSgvWZTf4dd_n + 2576
9 AppName 0x000000010a4230fd $s8AudioKitAAC6outputAA6AKNodeCSgvsZ + 93
10 AppName 0x000000010a2ba3a3 $s6AppName7MaestroC17setUpTrackPlayers7fileURLy10Foundation0H0V_tF + 1235
Examining the common gotchas video I see a similar exception being thrown, required condition is false: !nodeMixerConns.empty() && !hasDirectConnToIONode, which is caused by allowing the variables to go out of scope rather than be retained in the class.
So this occurs when we create an AKPlayer, which is retained in a class, then we create an AKTimePitch with this player which is also retained in that class, and finally assign that to AudioKit.output which triggers the exception. After that we were storing the class that holds onto the player and time pitch in an array, so I tried to move this up after it's created in hopes that was the issue, but I see the same exception.
Interestingly, this code works fine initially when we load up the first song but crashes when we hit the next button to load up the next song.
final class Maestro : NSObject {
static let shared = Maestro()
var audioPlayers = [TrackPlayer]()
func setUpTrackPlayers(fileURL: URL) {
let playerOne = TrackPlayer(url: fileURL)
audioPlayers.append(playerOne)
AudioKit.output = playerOne.handleMixerChain() //boom
do {
try AudioKit.start()
} catch {
print("Maestro AudioKit.start error: \(error)")
}
}
func next() {
for player in audioPlayers {
player.stop()
}
audioPlayers.removeAll()
setUpTrackPlayers(fileURL: newSong.getFileUrl())
}
}
final class TrackPlayer {
let player : AKPlayer
lazy var timePitch = AKTimePitch()
init(url: URL) {
player = AKPlayer(url: url)!
}
func handleMixerChain(pitch: Double = 0.0, tempo: Double = 1.0) -> AKTimePitch {
timePitch = AKTimePitch(player)
timePitch.pitch = pitch
timePitch.rate = tempo
return timePitch
}
}
Any ideas? If you need any more info let me know. May be good to note we are updating from AudioKit 4.5.5 where we didn't experience this crash.
I've opened the project and it seems like you're being a bit too relaxed about your set up / tear down of the signal chain. You're setting up AudioKit's output using local variables, never tearing down this signal chain, and then coming back resetting the AudioKit output and telling AudioKit to start without ever calling AudioKit.stop().

Firebase storage error

FirebaseStorage Pod Version (1.0.1)
var storageRef: FIRStorageReference! = FIRStorage.storage().reference()
let uploadTask = storageRef.putData(UIImagePNGRepresentation(image)!, metadata: nil) { metadata, error in
if (error != nil) {
} else {
let downloadURL = metadata!.downloadURL
print(downloadURL)
}
}
I simply selected a image from ImagePicker and tried to save Image data to the firebase storage. As illustrated in firebase docs.(Docs Reference) Upload from data in memory section.
It's throwing following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'
*** First throw call stack:
(
0 CoreFoundation 0x02025494 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x03eb2e02 objc_exception_throw + 50
2 CoreFoundation 0x01f0c6d2 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 386
3 CoreFoundation 0x01f2095b +[NSDictionary dictionaryWithObjects:forKeys:count:] + 75
4 FirePlay 0x001e42bc -[FIRStorageUploadTask enqueue] + 815
5 FirePlay 0x001e010c -[FIRStorageReference putData:metadata:completion:] + 880
The same code used to work before. I am not sure what's the problem now.
Turns out that we can't put files in root storage node. need to create child node and then only you can save the file. It was clearly mentioned in the Firebase docs somehow I overlooked it.
E.g
let mountainsRef = storageRef.child("mountains.jpg")
let uploadTask = mountainsRef.putData(UIImagePNGRepresentation(image)!, metadata: nil) { metadata, error in
if (error != nil) {
} else {
let downloadURL = metadata!.downloadURL
print(downloadURL)
}
}

Swift 2 - Sigabrt Error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm creating a countdown timer for a game but I'm getting the SIGABRT error. I am coding in Swift 2. It countdowns from 45 seconds then has two other labels, one that is 5 seconds less, and the other 10 seconds less. The app opens up successfully in the simulator. Once I click on the screen then it crashes. I tried removing all the ties between the buttons/labels on the Storyboard to the ViewController.swift. Then, I re-"attached" them. The button has no text and is above everything. So, no matter where you tap on the screen, it will either start or reset. Once the button is clicked the NSTimer starts. Once the button is clicked again it resets the timer so its ready for the next time.
ViewController Code:
//
// ViewController.swift
// CS:GO C4 Timer
//
// Created by Panja on 11/14/15.
// Copyright © 2015 Panja. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
var Main:Int = 0
var Kit:Int = 0
var NoKit:Int = 0
#IBOutlet weak var MainTime: UILabel!
#IBOutlet weak var DiffuseKit: UILabel!
#IBOutlet weak var NoDiffuseKit: UILabel!
var TimerCount = 0;
var TimerRunning = false;
var Timer = NSTimer();
var Toggle = false;
func Countdown(){
//Time Left Before Bomb Explodes
TimerCount = 45;
TimerCount -= 1
if(TimerCount <= 0){
MainTime.text = "No Time"
}else{
MainTime.text = "\(TimerCount)"
Main = TimerCount
}
//Time Left To Diffuse With A Kit
Kit = Main - 5
if(Kit <= 0){
DiffuseKit.text = "No Time"
}else{
DiffuseKit.text = "\(Kit)"
}
//Time Left To Diffuse Without A Kit
NoKit = Main - 10
if(NoKit <= 0){
NoDiffuseKit.text = "No Time"
}else{
NoDiffuseKit.text = "\(NoKit)"
}
}
#IBAction func ToggleButton(sender: AnyObject) {
//If The Button Is At Its Default at 45 Seconds & Not Running
if(Toggle == false){
if TimerRunning == false{
Timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("Counting"), userInfo: nil, repeats: true)
TimerRunning = true;
Toggle = true;
}
//If Timer is Running & Needs To Be Stopped
}else if (Toggle == true){
if TimerRunning == true{
Timer.invalidate()
TimerRunning = false
TimerCount = 45;
MainTime.text = "45"
Toggle = false;
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Error From Debug Console:
2015-11-15 12:20:54.288 CS:GO C4 Timer[32688:6460757] -[CS_GO_C4_Timer.ViewController Counting]: unrecognized selector sent to instance 0x7f866bf19d00
2015-11-15 12:20:54.323 CS:GO C4 Timer[32688:6460757] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CS_GO_C4_Timer.ViewController Counting]: unrecognized selector sent to instance 0x7f866bf19d00'
*** First throw call stack:
(
0 CoreFoundation 0x00000001080849b5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000109c83deb objc_exception_throw + 48
2 CoreFoundation 0x000000010808cfdd -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000107fda9fa ___forwarding___ + 970
4 CoreFoundation 0x0000000107fda5a8 _CF_forwarding_prep_0 + 120
5 Foundation 0x000000010846b6f1 __NSFireTimer + 83
6 CoreFoundation 0x0000000107fe4de4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
7 CoreFoundation 0x0000000107fe4991 __CFRunLoopDoTimer + 1089
8 CoreFoundation 0x0000000107fa6331 __CFRunLoopRun + 1937
9 CoreFoundation 0x0000000107fa5918 CFRunLoopRunSpecific + 488
10 GraphicsServices 0x000000010c5ccad2 GSEventRunModal + 161
11 UIKit 0x00000001088a199e UIApplicationMain + 171
12 CS:GO C4 Timer 0x0000000107ea218d main + 109
13 libdyld.dylib 0x000000010a7de92d start + 1
14 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Main.Storyboard
Image of The Main Storyboard
Thread 1 - 12 Main
Picture of the Thread 1 file that shows when the application crashes
The problem is that Counting and Countdown are two different words.

SpriteKit playSoundFileNamed crash on iOS 8.3

I'm seeing some small amounts of SpriteKit playSoundFileNamed crashes from my app's crash log. The crashes happen on iOS 8.3.
0 CoreFoundation __exceptionPreprocess
1 libobjc.A.dylib objc_exception_throw
2 CoreFoundation -[NSException initWithCoder:]
3 SpriteKit +[SKPlaySound playSoundFileNamed:atPosition:waitForCompletion:]
4 SpriteKit +[SKAction(SKActions) playSoundFileNamed:waitForCompletion:]
...
And a few related crashes:
0 CoreFoundation __exceptionPreprocess
1 libobjc.A.dylib objc_exception_throw
2 CoreFoundation -[NSException raise:format:]
3 SpriteKit +[SKPlaySound playSoundFileNamed:atPosition:waitForCompletion:]
4 SpriteKit +[SKAction(SKActions) playSoundFileNamed:waitForCompletion:]
...
Does anyone know what causes this crash and how to fix it? Should I wrap every calls to playSoundFileNamed: in a try-catch block?
Edited
More information:
I'm using Swift. Trying to play my own sounds and I'm seeing the crashes coming from different sounds. I'm also seeing a couple reports from iOS 8.2 so this crash might not be iOS 8.3 specific.
The lines that play the sound:
var sound = SKAction.playSoundFileNamed("Sound/ABC.mp3", waitForCompletion: false)
self.runAction(sound)
I experienced a similar issue a while back. The issue was that the variable could not be made quickly enough to play as I was creating the variable each time the user tapped on the screen. Try defining the action in didMoveToView, and seeing if you still get the issue.
Hope that helps
Try this and let me know if its working.
var audioPlayer = AVAudioPlayer()
func playAudio() {
// Set the sound file name & extension
let alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("ABC", ofType: "mp3")!)
// Preperation
try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, withOptions: [])
try! AVAudioSession.sharedInstance().setActive(true)
// Play the sound
do {
try audioPlayer = AVAudioPlayer(contentsOfURL: alertSound)
audioPlayer.prepareToPlay()
audioPlayer.play()
} catch {
print("there is \(error)")
}
}
I had similar problem. My game (swift + spritekit) was crashing indeterministic on iOS 8.x. but on 9.x works perfect. Piece of log:
2015-12-15 21:27:40.827 MyGame[24055:2285857]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Resource assets/mfx/my_sound.m4a can not be loaded'
*** First throw call stack:
(
0 CoreFoundation 0x008ae746 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x02598a97 objc_exception_throw + 44
2 CoreFoundation 0x008ae66d +[NSException raise:format:] + 141
3 SpriteKit 0x011ca435 +[SKPlaySound playSoundFileNamed:atPosition:waitForCompletion:] + 628
4 SpriteKit 0x011601b4 +[SKAction(SKActions) playSoundFileNamed:waitForCompletion:] + 78
5 MyGame 0x0012eb25
Solution is: load all sounds only once, as a constants (let). Do not create variable each time you want to play the sound.
import SpriteKit
import AVFoundation
class Sounds
{
static let SOUND1 = SKAction.playSoundFileNamed("assets/sound1.m4a", waitForCompletion: false)
static let SOUND2 = SKAction.playSoundFileNamed("assets/sound2.m4a", waitForCompletion: false)
}
Then, in some SKSpriteNode for example:
func playSound1()
{
self.runAction(Sounds.SOUND1)
}
Find similar / same issue here: Skaction.playsoundfilenamed crashes when repeat - sprite kit

Resources