Swift 2 - Sigabrt Error [closed] - ios

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.

Related

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().

Watch app starts with error clientIdentifier for interfaceControllerID not found

I'm having a smartwatch app on watchos2. The app always worked but now when it starts I immediately get this error:
Lop_WatchKit_Extension[17535:7854201] *********** ERROR -[SPRemoteInterface _interfaceControllerClientIDForControllerID:] clientIdentifier for interfaceControllerID:447E0002 not found
I found some topics here on stackoverflow but nothing solved the problem.
In my case, this was due to a retain cycle in one InterfaceController of mine.
If you get the logs similar to:
[default] -[SPRemoteInterface
_interfaceControllerClientIDForControllerID:]:0000: ComF: clientIdentifier for interfaceControllerID:XXXXXXXX not found
&/or...
[default] _SendRecordedValues:000: ComF:<-Plugin controller ID
XXXXXXXX has no client identifier
First, figure out which InterfaceController has the controller ID XXXXXXXX.
Have this in awake(withContext:)
override func awake(withContext context: Any?) {
//...
if let id = self.value(forKey: "_viewControllerID") as? NSString {
let strClassDescription = String(describing: self)
print("\(strClassDescription) has the Interface Controller ID \(id)")
}
//...
}
This logs:
[Target.Classname: 0xYYYYYYYY] has the Interface Controller ID
XXXXXXXX
Once you identify the InterfaceController causing these logs, you can continue to debug.
It could be different in your case but in mine I had created a retain cycle with self in one of my closures within which took awhile to locate but I eventually broke the retain cycle with a [weak self] capture.
Basically, the error logs appear when an InterfaceController is trying to execute some code but it has already been released.
What I already had:
DispatchQueue.main.async {
self.doSomethingThatDoesSomethingAsync()
}
What I fixed:
DispatchQueue.main.async { [weak self] in
self?.doSomethingThatDoesSomethingAsync()
}
If you use didSet on any IBOutlets it will also throw this error in the logs.
class MyInterfaceController: WKInterfaceController {
#IBOutlet var myLabel: WKInterfaceLabel! {
didSet {
myLabel.setTitle("Test")
}
}
How #nickromano sad, it's happens when you use didSet with IBOutlets. Cause it's calls before awake(withContext context: Any?)
We can suppress this error if wrap it in DispatchQueue.main.async
#IBOutlet var statusLabel: WKInterfaceLabel! {
didSet {
DispatchQueue.main.async {
self.statusLabel.setHidden(true)
}
}
This has happened to me a few times and more times than not, it is because of a timer that is still firing in a just-previously dismissed WKInterfaceController that I did not catch.
Best thing to do aside from comparing ID's like in #staticVoidMan's answer is to read the call stack. In my case I was able to identify that the old timer was still firing based off these hints:
8 Foundation 0x00007fff214be867 __NSFireTimer + 67
9 CoreFoundation 0x00007fff207a8e3f __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
10 CoreFoundation 0x00007fff207a8912 __CFRunLoopDoTimer + 926
Here is the original call stack (for reference):
<MyApp.InterfaceController: 0x7fb3e4d2d020> has the Interface Controller ID 1EB00002
2021-05-26 14:44:06.632758-0600 MyApp WatchKit Extension[73392:3546879] [default] -[SPRemoteInterface _interfaceControllerClientIDForControllerID:]:2464: ComF: clientIdentifier for interfaceControllerID:1EB00007 not found. callStack:(
0 WatchKit 0x00007fff38d1a268 -[SPRemoteInterface _interfaceControllerClientIDForControllerID:] + 220
1 WatchKit 0x00007fff38d1bfff __54+[SPRemoteInterface setController:key:property:value:]_block_invoke + 340
2 WatchKit 0x00007fff38d12323 spUtils_dispatchAsyncToMainThread + 30
3 WatchKit 0x00007fff38d1be60 +[SPRemoteInterface setController:key:property:value:] + 179
4 WatchKit 0x00007fff38d057af -[WKInterfaceObject _sendValueChanged:forProperty:] + 706
5 WatchKit 0x00007fff38d2a5f8 -[WKInterfaceObject _setImage:forProperty:] + 50
6 MyApp WatchKit Extension 0x000000010955531d $s26MyApp_WatchKit_Extension25ActivityIndicatorDelegateC06handleE5TimeryyF + 813
7 MyApp WatchKit Extension 0x000000010955537a $s26MyApp_WatchKit_Extension25ActivityIndicatorDelegateC06handleE5TimeryyFTo + 42
8 Foundation 0x00007fff214be867 __NSFireTimer + 67
9 CoreFoundation 0x00007fff207a8e3f __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
10 CoreFoundation 0x00007fff207a8912 __CFRunLoopDoTimer + 926
11 CoreFoundation 0x00007fff207a7ec5 __CFRunLoopDoTimers + 265
12 CoreFoundation 0x00007fff207a2546 __CFRunLoopRun + 1949
13 CoreFoundation 0x00007fff207a18be CFRunLoopRunSpecific + 567
14 GraphicsServices 0x00007fff25b49fd3 GSEventRunModal + 139
15 UIKitCore 0x00007fff43290f24 -[UIApplication _run] + 917
16 UIKitCore 0x00007fff43295c0b UIApplicationMain + 101
17 WatchKit 0x00007fff38d0de65 WKExtensionMain + 800
18 libdyld.dylib 0x00007fff20202db5 start + 1
19 ??? 0x0000000000000001 0x0 + 1
)
Have you changed the name of your module? If this is the case then you have to go through your storyboard and update it manually for all the Interfaces you have.
Edit with steps to fix:
Go to the storyboard and for each interface open the Identity inspector, then delete what's in Module and press enter, the new module should get auto-filled.

xcode: Thread 1: Signal SIGABART in class AppDelegate: UIResponder, UIApplicationDelegate (game application)

Before marking as duplicate, please consider that I have searched the web and StackOverflow but I didn't find any solution for this specific problem (because all questions about this error are for apps, not games).
I am making a very basic Space Shooter game and I reached a stage where I want to make the hero (code below) shoot bullets; I created a function spawn_bullet to do this. After I wrote this function and called it in the function:
override func update(currentTime: CFTimeInterval),
I get the error: Thread 1: signal SIGABRT. Image is shown below
I believe that the error has something to do with the execution of the spawn_bullet function but I am not sure where it is, why it caused and how to fix it. Anyone has an idea to fix it and if possible to provide enough details for why it causes?
Thank you!
NOTE
English is not my first language (that's why it's bad)
Below I provide my code used in GameScene.swift:
import SpriteKit
class GameScene: SKScene {
var hero = SKSpriteNode(imageNamed: "hero")
var bullet = SKSpriteNode(imageNamed: "bullet")
var enemy = SKSpriteNode(imageNamed: "enemy")
var init_bullet_position = CGFloat(0)
var bullet_velocityY = CGFloat(5)
override func didMoveToView(view: SKView) {
/* Setup your scene here */
self.backgroundColor = UIColor(red: 0.7, green: 0.7, blue: 0.8, alpha: 1)
self.hero.anchorPoint = CGPointMake(0.5, 0)
self.hero.size.height = 50
self.hero.size.width = 30
self.hero.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMinX(self.frame) + self.hero.size.height)
self.bullet.anchorPoint = CGPointMake(0.5, 0)
self.bullet.size.height = 30
self.bullet.size.width = 15
self.bullet.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMinX(self.frame) + self.hero.size.height + self.hero.size.height / 4)
self.init_bullet_position = CGFloat(CGRectGetMinX(self.frame) + self.hero.size.height + self.hero.size.height / 4)
self.hero.zPosition = 1; //1 = front
self.addChild(bullet)
self.addChild(hero)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = touch.locationInNode!(self)
hero.position.x = location.x
if self.bullet.position.y == init_bullet_position{
self.bullet.position.x = location.x
}
}
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = touch.locationInNode!(self)
self.hero.position.x = location.x
if self.bullet.position.y == init_bullet_position{
self.bullet.position.x = location.x
}
}
}
func spawn_bullets(){
self.bullet.anchorPoint = CGPointMake(0.5, 0)
self.bullet.size.height = 30
self.bullet.size.width = 15
self.bullet.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMinX(self.frame) + self.hero.size.height + self.hero.size.height / 4)
self.addChild(bullet)
if self.bullet.position.y < self.frame.size.height{
self.bullet.position.y += self.bullet_velocityY
}
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
spawn_bullets()
}
}
Here is the exception message:
2016-07-14 23:07:54.564 Space shooter[14391:191912] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attemped to add a SKNode which already has a parent: <SKSpriteNode> name:'(null)' texture:[<SKTexture> 'bullet' (400 x 600)] position:{160, 62.5} scale:{1.00, 1.00} size:{15, 30} anchor:{0.5, 0} rotation:0.00'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ec4fd85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000111299deb objc_exception_throw + 48
2 CoreFoundation 0x000000010ec4fcbd +[NSException raise:format:] + 205
3 SpriteKit 0x000000010fb74903 -[SKNode insertChild:atIndex:] + 162
4 SpriteKit 0x000000010fb74840 -[SKNode addChild:] + 68
5 Space shooter 0x000000010ea62d23 _TFC13Space_shooter9GameScene13spawn_bulletsfT_T_ + 995
6 Space shooter 0x000000010ea62ef4 _TFC13Space_shooter9GameScene6updatefSdT_ + 36
7 Space shooter 0x000000010ea62f2c _TToFC13Space_shooter9GameScene6updatefSdT_ + 44
8 SpriteKit 0x000000010fb48072 -[SKScene _update:] + 312
9 SpriteKit 0x000000010fb6503a -[SKView _update:] + 932
10 SpriteKit 0x000000010fb6221a __59-[SKView _renderSynchronouslyForTime:preRender:postRender:]_block_invoke + 170
11 SpriteKit 0x000000010fb620e8 -[SKView _renderSynchronouslyForTime:preRender:postRender:] + 235
12 SpriteKit 0x000000010fb64ac2 -[SKView layoutSubviews] + 85
13 UIKit 0x000000010fdd8980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
14 QuartzCore 0x00000001151d7c00 -[CALayer layoutSublayers] + 146
15 QuartzCore 0x00000001151cc08e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
16 QuartzCore 0x00000001151cbf0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
17 QuartzCore 0x00000001151c03c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
18 QuartzCore 0x00000001151ee086 _ZN2CA11Transaction6commitEv + 486
19 QuartzCore 0x00000001151ee7f8 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
20 CoreFoundation 0x000000010eb74c37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
21 CoreFoundation 0x000000010eb74ba7 __CFRunLoopDoObservers + 391
22 CoreFoundation 0x000000010eb6a11c CFRunLoopRunSpecific + 524
23 UIKit 0x000000010fd18f21 -[UIApplication _run] + 402
24 UIKit 0x000000010fd1df09 UIApplicationMain + 171
25 Space shooter 0x000000010ea64e82 main + 114
26 libdyld.dylib 0x0000000111dc792d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
It occurs on this line:
self.addChild(bullet)
This is because bullet already has a parent.
To fix it, add this line before you add the child:
bullet.removeFromParent()
To answer the stated question:
Here's your error:
Attemped to add a SKNode which already has a parent
The problem is in your spawn_bullets() function. You're not actually instantiating new bullets in this function. You're just updating properties on self's instance of bullet, then trying to add it as a child of your scene. The second time this function is called, it crashes, because the bullet is already a child of the scene.
Instead, you should create new instances of your bullet node.
Regarding the underlying problem of creating unique bullets:
This is a whole separate topic in and of itself. I assume you only want to fire bullets at specific times, such as when you tap on something, so rather than spawning bullets from the update() function, which is called before each frame is rendered, I would call spawn_bullets() from a tap method, or other interaction. Secondly, you will want to create new instances of your bullet instead of updating a variable on your scene. These can be added, animated, and subsequently removed. Finally, take a look at the SKAction class for actually animating (and ultimately removing) the bullets. For example:
let newBullet = SKSpriteNode(imageNamed: "bullet")
newBullet.position = CGPoint(x: 10, y: 10)
self.addChild(newBullet)
let moveAction = SKAction.moveTo(CGPoint(x: 50, y: 10), duration: 0.4)
let removeAction = SKAction.removeFromParent()
newBullet.runAction(SKAction.sequence([moveAction, removeAction])) {
// Bullet is done and removed.
}
You can do a lot more with SKAction than is shown here. You can play audio files, follow paths, or even simply run a block.

Crash on iOS 8 when dispatch_group_wait() return because of timeout

I have two operations fetching a value. I only care about the sum both values. And I don't care about the value at all if it takes too long.
So I thought it would be an easy task for GCD using groups. Unfortunately, the below code only works fine on iOS 9. Each time I have no matching calls of dispatch_group_enter()/dispatch_group_leave() I get a crash.
The documentation states clearly that I have to match both call. But when I use a timeout on dispatch_group_wait(), it is impossible to have the same amount of leave calls as enter calls; that is the whole point of specifying a timeout.
So is this a known bug in iOS 8? Am I doing something wrong? Is there another solution to my initial problem that works on iOS 8 as well?
EDIT: Actually we can boil it down to this:
var sync_group: dispatch_group_t = dispatch_group_create();
dispatch_group_enter(sync_group);
let maxWait = dispatch_time(DISPATCH_TIME_NOW, Int64(60 * NSEC_PER_SEC))
let result = dispatch_group_wait(sync_group, maxWait)
sync_group = dispatch_group_create();
Works as expected on iOS 9 but does crash on iOS 8 on the last line because the old dispatch_group_t instance can not be release. Any easy workarounds?
EDIT 2: Turns out it is broken on iOS 9.0 too. It only works as as it should in iOS 9.1+.
Original Code:
let qualityOfServiceClass = QOS_CLASS_BACKGROUND
let backgroundQueue = dispatch_get_global_queue(qualityOfServiceClass, 0)
dispatch_async(backgroundQueue, {
/* We want this method to block until the network code succeeded. */
let sync_group: dispatch_group_t = dispatch_group_create();
/* Start async operation 1. */
dispatch_group_enter(sync_group);
self.someAsyncOperation1({(value: Int, finalValue: Bool) in
if (finalValue) {
valOp1 = value
dispatch_group_leave(sync_group);
}
})
/* Start async operation 2. */
dispatch_group_enter(sync_group);
self.someAsyncOperation2({(value: Int, finalValue: Bool) in
if (finalValue) {
valOp2 = value
dispatch_group_leave(sync_group)
}
})
/* Block current thread until all leaves were called. If it takes more then 60 sec we don't care and let go. */
let maxWait = dispatch_time(DISPATCH_TIME_NOW, Int64(60 * NSEC_PER_SEC))
let result = dispatch_group_wait(sync_group, maxWait)
if (result > 0) {
/* This will result in a crash when we leave the scope: SIGTRAP in dispatch_semaphore_dispose */
return
}
dispatch_async(dispatch_get_main_queue(), {
let newValue = valOp1 + valOp2
self.lastKnownNotificationCombinedCounter = newValue
success(newValue)
})
})
The actual crash loops like that:
Exception Type: SIGTRAP
Exception Codes: #0 at 0x3958a2a4
Thread 2 Crashed:
0 libdispatch.dylib 0x3958a2a4 _dispatch_semaphore_dispose$VARIANT$mp + 48
1 libdispatch.dylib 0x3958b491 _dispatch_dispose$VARIANT$mp + 30
2 libdispatch.dylib 0x3957ea8f -[OS_dispatch_object _xref_dispose] + 44
3 myApp 0x00176a24 block_destroy_helper67 + 354
4 myApp 0x00176ab8 0x2e000 + 1346232
5 myApp 0x00178334 0x2e000 + 1352500
6 libsystem_blocks.dylib 0x395d3adb _Block_release + 216
7 Foundation 0x2c4143b9 -[NSBlockOperation dealloc] + 58
8 libobjc.A.dylib 0x39036d57 objc_object::sidetable_release(bool) + 164
9 libobjc.A.dylib 0x390371a9 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 402
10 libdispatch.dylib 0x39589423 _dispatch_root_queue_drain + 1176
11 libdispatch.dylib 0x3958a1fb _dispatch_worker_thread3 + 104
12 libsystem_pthread.dylib 0x396fae25 _pthread_wqthread + 666
13 libsystem_pthread.dylib 0x396fab78 start_wqthread + 6
I came up with this workaround:
private let MAX_TRIES = 20;
func dispatch_group_wait_ios8Safe(group: dispatch_group_t, _ timeout: dispatch_time_t) -> Int {
if #available(iOS 9, *) {
/* Just forward the call. */
return dispatch_group_wait(group, timeout)
} else {
/* Forward the call to original function and store result. */
let firstResult = dispatch_group_wait(group, timeout)
var result = firstResult, tries = 0
while(result > 0 && tries < MAX_TRIES) {
dispatch_group_leave(group)
result = dispatch_group_wait(group, DISPATCH_TIME_NOW)
tries += 1
}
/* Return original result. */
return firstResult
}
}
So until someone comes up with a better solution I stick with this.

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

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.

Resources