strange EXC_BREAKPOINT swift - ios

I've got the following crash report :
Crashed: com.apple.main-thread
EXC_BREAKPOINT 0x00000001000b6b44
0 Spersy 0x1000b6b44 specialized BL_BaseTabBarController.(setUpTabBar in _D18ECB1BE2DA6194F4E8C8A0FD1C1668)(BL_BaseTabBarController) -> (forSelectedActionSignContainer : UIImageView) -> () (BL_BaseTabBarController.swift)
1 Spersy 0x1000b3ae0 #objc BL_BaseTabBarController.cameraControllerSelected(BL_BaseTabBarController) -> () -> () (BL_BaseTabBarController.swift:112)
2 UIKit 0x186050be8 -[UIApplication sendAction:to:from:forEvent:] + 100
3 UIKit 0x186050b64 -[UIControl sendAction:to:forEvent:] + 80
4 UIKit 0x186038870 -[UIControl _sendActionsForEvents:withEvent:] + 436
5 UIKit 0x186050454 -[UIControl touchesEnded:withEvent:] + 572
6 UIKit 0x186008c0c _UIGestureRecognizerUpdate + 8988
7 CoreFoundation 0x180e70728 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
8 CoreFoundation 0x180e6e4cc __CFRunLoopDoObservers + 372
9 CoreFoundation 0x180e6e8fc __CFRunLoopRun + 928
10 CoreFoundation 0x180d98c50 CFRunLoopRunSpecific + 384
11 GraphicsServices 0x182680088 GSEventRunModal + 180
12 UIKit 0x186082088 UIApplicationMain + 204
13 Spersy 0x1000ed850 main (AppDelegate.swift:19)
14 libdispatch.dylib 0x1809368b8 (Missing)
And propagating to code, user tapps the tabbar button ( i'm using custom tabbar ) :
#IBAction func cameraControllerSelected()
{
setUpTabBar(forSelectedActionSignContainer: cameraSign)
}
And the following code executes :
private func setUpTabBar ( forSelectedActionSignContainer imageView : UIImageView ) -> Void
{
var viewControllerIndex = 0
if ( imageView == feedSign )
{
feedSign.hidden = false
exploreSign.hidden = true
cameraSign.hidden = true
chatSign.hidden = true
profileSign.hidden = true
viewControllerIndex = 0
}
if ( imageView == exploreSign )
{
feedSign.hidden = true
exploreSign.hidden = false
cameraSign.hidden = true
chatSign.hidden = true
profileSign.hidden = true
viewControllerIndex = 1
}
if ( imageView == cameraSign )
{
feedSign.hidden = true
exploreSign.hidden = true
cameraSign.hidden = false
chatSign.hidden = true
profileSign.hidden = true
viewControllerIndex = 2
}
if ( imageView == chatSign )
{
feedSign.hidden = true
exploreSign.hidden = true
cameraSign.hidden = true
chatSign.hidden = false
profileSign.hidden = true
viewControllerIndex = 3
}
if ( imageView == profileSign )
{
feedSign.hidden = true
exploreSign.hidden = true
cameraSign.hidden = true
chatSign.hidden = true
profileSign.hidden = false
viewControllerIndex = 4
}
if ( !shouldDismissTopOrReload(viewControllerAtIndex: viewControllerIndex))
{
displayViewController(atIndex: viewControllerIndex)
signOnScreen = imageView
}
}
And it appears only on release builds, on debug everything fine. Is an optimising compiler issue? Cause i have the same procedure setUpTabbar() with no arguments. Other functions - such as shouldDismissTopOrReload(viewControllerAtIndex: viewControllerIndex) and displayViewController(atIndex: viewControllerIndex) are reliable, and well-covered by tests. Any ideas? I've got almost 200 crashes!!

Related

Why Does CarPlay Crash In Real Car?

I have an audio app and have implemented CarPlay, I've followed this guide to add CarPlay support: https://blog.fethica.com/add-carplay-support-to-swiftradio/#
The app uses the com.apple.developer.playable-content entitlement and Media Player framework, which as far as I know, has been the only way to add CarPlay to audio apps on iOS 13 and below, but is still backwards compatible with iOS 14 (despite there being a new carplay audio framework for iOS 14). All my CarPlay logic is written in an extension of my main AppDelegate (could this be problematic?)
In the simulator, everything has been working fine and the audio plays in the external simulated car display. But my team tested the app in a real car and the application crashes immediately when opened from the car display.
I have the crash log here when tested on iPhone 11 Pro on iOS 14.4:
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x00000001b88d13cc
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [27455]
Triggered by Thread: 5
Thread 0 name:
Thread 0:
0 libsystem_kernel.dylib 0x00000001d6aa6f5c __ulock_wait + 8
1 libdispatch.dylib 0x00000001a8746794 _dlock_wait + 56 (lock.c:326)
2 libdispatch.dylib 0x00000001a87466c0 _dispatch_once_wait + 124 (lock.c:382)
3 UIKitCore 0x00000001ab1080f8 -[_UIApplicationConfigurationLoader _loadInitializationContext] + 152 (once.h:84)
4 UIKitCore 0x00000001ab108444 -[_UIApplicationConfigurationLoader applicationInitializationContext] + 32 (_UIApplicationConfigurationLoader.m:161)
5 UIKitCore 0x00000001ab0ef05c -[_UIScreenInitialDisplayConfigurationLoader initialDisplayContext] + 180 (UIScreen.m:371)
6 UIKitCore 0x00000001ab0ef348 +[UIScreen initialize] + 128 (UIScreen.m:626)
7 libobjc.A.dylib 0x00000001bdb67c58 CALLING_SOME_+initialize_METHOD + 24 (objc-initialize.mm:384)
8 libobjc.A.dylib 0x00000001bdb6e318 initializeNonMetaClass + 716 (objc-initialize.mm:554)
9 libobjc.A.dylib 0x00000001bdb6f910 initializeAndMaybeRelock(objc_class*, objc_object*, mutex_tt<false>&, bool) + 280 (objc-runtime-new.mm:2221)
10 libobjc.A.dylib 0x00000001bdb7e498 lookUpImpOrForward + 956 (objc-runtime-new.mm:2237)
11 libobjc.A.dylib 0x00000001bdb68524 _objc_msgSend_uncached + 68
12 UIKitCore 0x00000001ab33ef48 -[_UIRemoteKeyboards keyboardWindow] + 52 (_UIRemoteKeyboards.m:2036)
13 UIKitCore 0x00000001ab33cf6c -[_UIRemoteKeyboards allowedToShowKeyboard] + 96 (_UIRemoteKeyboards.m:1588)
14 UIKitCore 0x00000001ab33bda8 -[_UIRemoteKeyboards checkConnection] + 64 (_UIRemoteKeyboards.m:1315)
15 UIKitCore 0x00000001ab338b60 -[_UIRemoteKeyboards init] + 156 (_UIRemoteKeyboards.m:797)
16 UIKitCore 0x00000001ab338ab4 __43+[_UIRemoteKeyboards sharedRemoteKeyboards]_block_invoke + 20 (_UIRemoteKeyboards.m:785)
17 libdispatch.dylib 0x00000001a8745db0 _dispatch_client_callout + 20 (object.m:559)
18 libdispatch.dylib 0x00000001a87475c8 _dispatch_once_callout + 32 (once.c:52)
19 UIKitCore 0x00000001ab338a9c +[_UIRemoteKeyboards sharedRemoteKeyboards] + 176 (once.h:84)
20 UIKitCore 0x00000001ab50ccac _UIApplicationMainPreparations + 1348 (UIApplication.m:4644)
21 UIKitCore 0x00000001ab50c740 UIApplicationMain + 140 (UIApplication.m:4704)
22 MyAppName 0x000000010458fb04 main + 68 (UITextField+Extension.swift:22)
23 libdyld.dylib 0x00000001a87866b0 start + 4
Thread 1:
0 libsystem_pthread.dylib 0x00000001f4608764 start_wqthread + 0
Thread 2:
0 libsystem_pthread.dylib 0x00000001f4608764 start_wqthread + 0
Thread 3 name:
Thread 3:
0 libsystem_kernel.dylib 0x00000001d6a822d0 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x00000001d6a81660 mach_msg + 76 (mach_msg.c:103)
2 libdispatch.dylib 0x00000001a875e888 _dispatch_mach_send_and_wait_for_reply + 528 (mach.c:812)
3 libdispatch.dylib 0x00000001a875ec24 dispatch_mach_send_with_result_and_wait_for_reply + 56 (mach.c:1998)
4 libxpc.dylib 0x00000001f4626e68 xpc_connection_send_message_with_reply_sync + 240 (connection.c:848)
5 BoardServices 0x00000001c2599958 -[BSXPCServiceConnectionMessage _sendSynchronously:] + 332 (BSXPCServiceConnectionMessage.m:129)
6 BoardServices 0x00000001c259a2cc -[BSXPCServiceConnectionMessage sendSynchronouslyWithError:] + 256 (BSXPCServiceConnectionMessage.m:182)
7 BoardServices 0x00000001c2584afc __71+[BSXPCServiceConnectionProxy createImplementationOfProtocol:forClass:]_block_invoke + 824 (BSXPCServiceConnectionProxy.m:274)
8 UIKitServices 0x00000001acb7fc6c -[UISApplicationSupportClient applicationInitializationContextWithParameters:] + 272 (UISApplicationSupportClient.m:77)
9 UIKitCore 0x00000001ab108278 __63-[_UIApplicationConfigurationLoader _loadInitializationContext]_block_invoke_2 + 228 (_UIApplicationConfigurationLoader.m:135)
10 UIKitCore 0x00000001ab108188 __UIAPPLICATION_IS_LOADING_INITIALIZATION_INFO_FROM_THE_SYSTEM__ + 28 (_UIApplicationConfigurationLoader.m:30)
11 UIKitCore 0x00000001ab108160 __63-[_UIApplicationConfigurationLoader _loadInitializationContext]_block_invoke + 100 (_UIApplicationConfigurationLoader.m:106)
12 libdispatch.dylib 0x00000001a8745db0 _dispatch_client_callout + 20 (object.m:559)
13 libdispatch.dylib 0x00000001a87475c8 _dispatch_once_callout + 32 (once.c:52)
14 UIKitCore 0x00000001ab1080f8 -[_UIApplicationConfigurationLoader _loadInitializationContext] + 152 (once.h:84)
15 UIKitCore 0x00000001ab108408 __70-[_UIApplicationConfigurationLoader startPreloadInitializationContext]_block_invoke + 28 (_UIApplicationConfigurationLoader.m:154)
16 libdispatch.dylib 0x00000001a874424c _dispatch_call_block_and_release + 32 (init.c:1454)
17 libdispatch.dylib 0x00000001a8745db0 _dispatch_client_callout + 20 (object.m:559)
18 libdispatch.dylib 0x00000001a8756a68 _dispatch_root_queue_drain + 656 (inline_internal.h:2548)
19 libdispatch.dylib 0x00000001a8757120 _dispatch_worker_thread2 + 116 (queue.c:6777)
20 libsystem_pthread.dylib 0x00000001f46017d8 _pthread_wqthread + 216 (pthread.c:2223)
21 libsystem_pthread.dylib 0x00000001f460876c start_wqthread + 8
Thread 4:
0 libsystem_pthread.dylib 0x00000001f4608764 start_wqthread + 0
Thread 5 name:
Thread 5 Crashed:
0 FrontBoardServices 0x00000001b88d13cc -[FBSSceneParameters initWithSpecification:] + 228 (FBSSceneParameters.m:34)
1 FrontBoardServices 0x00000001b88d1320 -[FBSSceneParameters initWithSpecification:] + 56 (FBSSceneParameters.m:34)
2 FrontBoardServices 0x00000001b88d1dd8 -[FBSSceneParameters initWithXPCDictionary:] + 128 (FBSSceneParameters.m:150)
3 BaseBoard 0x00000001ad165af4 _BSXPCDecodeObject + 1892 (BSXPCCoder.m:583)
4 BaseBoard 0x00000001ad1639c0 _BSXPCDecodeObjectForKey + 268 (BSXPCCoder.m:459)
5 BoardServices 0x00000001c2585f30 +[BSXPCServiceConnectionProxy decodeArguments:outArgs:fromMessage:forConnection:] + 1608 (BSXPCServiceConnectionProxy.m:592)
6 BoardServices 0x00000001c2583ab0 -[BSXPCServiceConnectionProxy invokeMessage:onTarget:] + 276 (BSXPCServiceConnectionProxy.m:342)
7 BoardServices 0x00000001c258a994 __63-[BSXPCServiceConnectionEventHandler connection:handleMessage:]_block_invoke + 536 (BSXPCServiceConnectionEventHandler.m:261)
8 BoardServices 0x00000001c25a0284 BSXPCServiceConnectionExecuteCallOut + 316 (BSXPCServiceConnection.m:1049)
9 BoardServices 0x00000001c258a708 -[BSXPCServiceConnectionEventHandler connection:handleMessage:] + 172 (BSXPCServiceConnectionEventHandler.m:250)
10 BoardServices 0x00000001c259f668 -[BSXPCServiceConnection _connection_handleMessage:fromPeer:withHandoff:] + 572 (BSXPCServiceConnection.m:834)
11 libdispatch.dylib 0x00000001a874424c _dispatch_call_block_and_release + 32 (init.c:1454)
12 libdispatch.dylib 0x00000001a8745db0 _dispatch_client_callout + 20 (object.m:559)
13 libdispatch.dylib 0x00000001a874d10c _dispatch_lane_serial_drain + 580 (inline_internal.h:2548)
14 libdispatch.dylib 0x00000001a874dc90 _dispatch_lane_invoke + 460 (queue.c:3862)
15 libdispatch.dylib 0x00000001a874cfd8 _dispatch_lane_serial_drain + 272 (inline_internal.h:2589)
16 libdispatch.dylib 0x00000001a874dc90 _dispatch_lane_invoke + 460 (queue.c:3862)
17 libdispatch.dylib 0x00000001a8757d78 _dispatch_workloop_worker_thread + 708 (queue.c:6601)
18 libsystem_pthread.dylib 0x00000001f4601814 _pthread_wqthread + 276 (pthread.c:2210)
19 libsystem_pthread.dylib 0x00000001f460876c start_wqthread + 8
Thread 6 name:
Thread 6:
0 libsystem_kernel.dylib 0x00000001d6a822d0 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x00000001d6a81660 mach_msg + 76 (mach_msg.c:103)
2 IOKit 0x00000001b3b68340 io_hideventsystem_copy_property + 172 (IOHIDEventSystemMIGUser.c:3056)
3 IOKit 0x00000001b3b22c60 IOHIDEventSystemClientCopyProperty + 128 (IOHIDEventSystemClient.c:1097)
4 IOKit 0x00000001b3b22354 __IOHIDEventSystemClientRefresh + 1148 (IOHIDEventSystemClient.c:539)
5 IOKit 0x00000001b3b230cc IOHIDEventSystemClientCreateWithType + 856 (IOHIDEventSystemClient.c:749)
6 BackBoardServices 0x00000001ac0dda88 ___getHIDEventSystemClient_block_invoke + 288 (BKSHIDEvent.m:93)
7 libdispatch.dylib 0x00000001a8745db0 _dispatch_client_callout + 20 (object.m:559)
8 libdispatch.dylib 0x00000001a87475c8 _dispatch_once_callout + 32 (once.c:52)
9 BackBoardServices 0x00000001ac0dd964 BKSHIDEventRegisterEventCallbackOnRunLoop + 152 (once.h:84)
10 UIKitCore 0x00000001ab5babe4 -[UIEventFetcher threadMain] + 416 (UIEventFetcher.m:720)
11 Foundation 0x00000001a9ee7a34 __NSThread__start__ + 864 (NSThread.m:724)
12 libsystem_pthread.dylib 0x00000001f45ffcb0 _pthread_start + 320 (pthread.c:881)
13 libsystem_pthread.dylib 0x00000001f4608778 thread_start + 8
Thread 7:
0 libsystem_pthread.dylib 0x00000001f4608764 start_wqthread + 0
Thread 5 crashed with ARM Thread State (64-bit):
x0: 0x000000020ba16880 x1: 0x000000020ba16880 x2: 0x0000000000000000 x3: 0x00000000000008fd
x4: 0x0000000000000000 x5: 0x00000001bdb9873e x6: 0x000000000000006e x7: 0x0000000000000fb0
x8: 0x85f836c8121c001f x9: 0x85f836c8121c001f x10: 0x0000000000005403 x11: 0x0000000281a71540
x12: 0x00000000000000aa x13: 0x0000000000000001 x14: 0x00000000000000ac x15: 0x0000000000000182
x16: 0x00000002c6d90f88 x17: 0x0000000208ac3dc8 x18: 0x0000000000000000 x19: 0x0000000000000000
x20: 0x0000000281472eb0 x21: 0x0000000000000000 x22: 0x0000000000000000 x23: 0x00000001f75f31f5
x24: 0x000000020ba160d8 x25: 0x0000000000000000 x26: 0x00000001f7ff3288 x27: 0x000000020ba160b0
x28: 0x0000000000000000 fp: 0x000000016bb2e130 lr: 0x86106081b88d1320
sp: 0x000000016bb2e100 pc: 0x00000001b88d13cc cpsr: 0x60000000
esr: 0xf2000000 Address size fault
What could be causing the app to crash in a real car but work fine in the simulator? Here is part of my AppDelegate where I call a function to setup carplay:
import UIKit
import AVFoundation
import AVKit
import GoogleInteractiveMediaAds
import MediaPlayer
import GoogleMobileAds
import UserNotifications
import WebKit
import SafariServices
import Hero
import Firebase
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
static let reachable = "Reachable"
static let unReachable = "UnReachable"
let reachability = try! Reachability()
var iOSStream: String?
var preRolladUrl: String?
var window: UIWindow?
var adType: String?
var adServer: String?
var adFeed: String?
var miniPlayer: PlayerPopupControlViewController?
var selectedStation: Players!
// CarPlay
var playableContentManager: MPPlayableContentManager?
let carplayPlaylist = CarPlayPlaylist()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UINavigationBar.appearance().barTintColor = UIColor.black
UINavigationBar.appearance().tintColor = UIColor.black
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
UINavigationBar.appearance().isTranslucent = false
if UserDefaults.standard.object(forKey: UserDefaultsConstants.resumeRadioInBackground) == nil {
UserDefaults.standard.set(true, forKey: UserDefaultsConstants.resumeRadioInBackground)
UserDefaults.standard.synchronize()
}
self.setupBaseURL()
// Override point for customization after application launch.
self.startObservingReachability()
UIApplication.shared.beginReceivingRemoteControlEvents()
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback)
try AVAudioSession.sharedInstance().setActive(true)
} catch {
AppLogger.error(error)
}
UNUserNotificationCenter.current().delegate = self
UserDefaults.standard.set(false, forKey: UserDefaultsConstants.isMiniPlayerDisplayed)
UserDefaults.standard.synchronize()
SettingsDataManager.sharedInstance.selectedStation = SettingsDataManager.sharedInstance.getSelectedStationFromUserDefaults()
registerForPushNotifications()
setupCarPlay()
FirebaseApp.configure()
return true
}
AppDelegate+CarPlay.swift
import Foundation
import MediaPlayer
extension AppDelegate{
func setupCarPlay() {
playableContentManager = MPPlayableContentManager.shared()
playableContentManager?.delegate = self
playableContentManager?.dataSource = self
self.carplayPlaylist.setupCommandCenter()
}
}
extension AppDelegate: MPPlayableContentDelegate {
// This is called when user selects a 'playable' item (MPContentItem)
func playableContentManager(_ contentManager: MPPlayableContentManager, initiatePlaybackOfContentItemAt indexPath: IndexPath, completionHandler: #escaping (Error?) -> Void) {
self.carplayPlaylist.playerData = SettingsDataManager.sharedInstance.playerData ?? []
// guard let miniPlayer = self.miniPlayer else {return}
DispatchQueue.main.async {
// App should play music either from the radio stream or podcasts
if indexPath.count == 2 {
if(indexPath[0] == 0) {
// When user selects playable item within Radio tab
if (self.carplayPlaylist.playerData.count > 0) {
if let stationURL = URL(string: self.carplayPlaylist.playerData[indexPath[1]].streams?.iOS ?? "") {
self.carplayPlaylist.play(playURL: stationURL)
SettingsDataManager.sharedInstance.selectedStation = self.carplayPlaylist.playerData[indexPath[1]]
}
}
}
}
completionHandler(nil)
// Workaround to make the Now Playing working on the simulator:
#if targetEnvironment(simulator)
UIApplication.shared.endReceivingRemoteControlEvents()
UIApplication.shared.beginReceivingRemoteControlEvents()
#endif
}
}
func beginLoadingChildItems(at indexPath: IndexPath, completionHandler: #escaping (Error?) -> Void) {
carplayPlaylist.load { error in
completionHandler(error)
}
}
}
extension AppDelegate: MPPlayableContentDataSource {
func numberOfChildItems(at indexPath: IndexPath) -> Int {
if indexPath.indices.count == 0 {
// This returns the number of tabs at the top of the CarPlay display
return 1 // changed to 1 to allow only radio streams
} else if indexPath.indices.count == 1 {
// This returns the number of rows within each tab
if indexPath[0] == 0 {
// Radio Stations rows
return carplayPlaylist.playerData.count
} else {
// Podcasts feed rows
return 0 // Return 0 while podcasts are disabled
}
} else {
return 0
}
}
func contentItem(at indexPath: IndexPath) -> MPContentItem? {
let playerData = carplayPlaylist.playerData
// let podCastsFeeds = carplayPlaylist.podCastSettings?.podcasts_feeds
if indexPath.count == 1 {
// Tab section
let item: MPContentItem
if (indexPath[0] == 0) {
// Radio Stations Tab Section
item = MPContentItem(identifier: "Radio")
item.title = "Radio"
item.artwork = MPMediaItemArtwork(boundsSize: #imageLiteral(resourceName: "NavIcon-Broadcast").size, requestHandler: { _ -> UIImage in
return #imageLiteral(resourceName: "NavIcon-Broadcast")
})
} else {
// Podcast Tab Section
item = MPContentItem(identifier: "Podcasts")
item.title = "Podcasts"
item.artwork = MPMediaItemArtwork(boundsSize: #imageLiteral(resourceName: "NavIcon-Podcasts").size, requestHandler: { _ -> UIImage in
return #imageLiteral(resourceName: "NavIcon-Podcasts")
})
}
item.isContainer = true
item.isPlayable = false
return item
} else if indexPath.count == 2, indexPath.item < playerData.count, indexPath[0] == 0 {
// Radio station items section
let station = playerData[indexPath.item]
let item = MPContentItem(identifier: "\(station.name)")
item.title = station.name
item.subtitle = station.call_letters
item.isPlayable = true
item.isStreamingContent = true
item.downloadImageAndSetArtwork(from: station.logo ?? "", completion: {})
return item
} else {
return nil
}
}
}
///extension to downlaod the image from the api
extension MPContentItem {
func getData(from url: URL, completion: #escaping (Data?, URLResponse?, Error?) -> ()) {
URLSession.shared.dataTask(with: url, completionHandler: completion).resume()
}
func downloadImageAndSetArtwork(from address: String, completion: #escaping () -> Void) {
let defaultImage = #imageLiteral(resourceName: "NavIcon-Music")
let defaultArtwork = MPMediaItemArtwork(boundsSize: defaultImage.size, requestHandler: { _ -> UIImage in
return defaultImage
})
guard let url = URL(string: address) else {
self.artwork = defaultArtwork
return
}
getData(from: url) {
data, response, error in
guard let data = data, error == nil else {
AppLogger.error("Image Error")
self.artwork = defaultArtwork
return
}
DispatchQueue.main.async() {
guard let image = UIImage(data: data) else {
self.artwork = defaultArtwork
return
}
self.artwork = MPMediaItemArtwork(boundsSize: image.size, requestHandler: { _ -> UIImage in
return image
})
completion()
}
}
}
}
CarPlayPlaylist.swift
import Foundation
//import UIKit
import AVKit
import MediaPlayer
class CarPlayPlaylist {
let radioPlayer = FRadioPlayer.shared
var playerData: [Players] = []
var podCastItemsArray: [[Item]] = []
var podCastSettings: Podcast_settings?
var podCastFeedNameArray:[String] = []
var isFromCarPlay: Bool = false
var playButtonStatus: Bool = false
var currentPodcastItem: Item?
func load(_ completion: #escaping (Error?) -> Void) {
// if (self.podCastFeedNameArray.count == 0 && self.podCastItemsArray.count == 0) {
// getPodcastDataFromSettingsDataManager()
//
// let podcastFeedsCount = self.podCastSettings?.podcasts_feeds?.count ?? 0
// podCastItemsArray = [[Item]](repeating: [], count: podcastFeedsCount)
// }
self.playerData = SettingsDataManager.sharedInstance.playerData ?? []
completion(nil)
}
func play (playURL: URL) {
isFromCarPlay = true
self.radioPlayer.radioURL = playURL
self.radioPlayer.play()
}
func setupCommandCenter () {
MPNowPlayingInfoCenter.default().nowPlayingInfo = [MPMediaItemPropertyTitle: "Current Playing song"]
MPNowPlayingInfoCenter.default().nowPlayingInfo![MPNowPlayingInfoPropertyPlaybackRate] = 0.0
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.playCommand.isEnabled = true
commandCenter.pauseCommand.isEnabled = true
commandCenter.playCommand.addTarget { [weak self] (event) -> MPRemoteCommandHandlerStatus in
self?.radioPlayer.play()
// NotificationCenter.default.post(name: NSNotification.Name(rawValue: NotificationCenterConstants.carPlayDidPlay), object: nil, userInfo: nil)
return .success
}
commandCenter.pauseCommand.addTarget { [weak self] (event) -> MPRemoteCommandHandlerStatus in
self?.radioPlayer.pause()
// NotificationCenter.default.post(name: NSNotification.Name(rawValue: NotificationCenterConstants.carPlayDidPause), object: nil, userInfo: nil)
return .success
}
}
}
extension CarPlayPlaylist {
func addCommandCenterNotificationObservers() {
NotificationCenter.default.addObserver(self, selector: #selector(commandCenterDidPlay), name: NSNotification.Name(rawValue: NotificationCenterConstants.commandCenterDidPlay), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(commandCenterDidPause), name: NSNotification.Name(rawValue: NotificationCenterConstants.commandCenterDidPause), object: nil)
}
func removeCommandCenterObservers() {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NotificationCenterConstants.commandCenterDidPlay), object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: NotificationCenterConstants.commandCenterDidPause), object: nil)
}
#objc func commandCenterDidPlay() {
// Playback rate should change the playback status
MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyPlaybackRate] = 0.0
}
#objc func commandCenterDidPause() {
// Playback rate should change the playback status
MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyPlaybackRate] = 1.0
}
}

AudioKit crashes

I'm trying to create an app that:
Records my microphone and saves the output to a file
Plays the last recorded file
The playback should be manipulated with effects such as pitch-shift
So far I've got 1+2 down, but when I try to assign the AudioKit.output to my timePitch (or PitchShifter for that matter), I get an exception (see below). Can anyone help me out? Seems like if I set output to anything else than player, it crashes..
Disclaimer: I'm new to Swift, so please go easy on me and forgive my bad code
2017-11-08 16:39:58.637075+0100 mysoundplayer[41113:759865] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'player started when in a disconnected state'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108a3c1ab __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001047ddf41 objc_exception_throw + 48
2 CoreFoundation 0x0000000108a41372 +[NSException raise:format:arguments:] + 98
3 AVFAudio 0x000000010b3bb00e _Z19AVAE_RaiseExceptionP8NSStringz + 158
4 AVFAudio 0x000000010b4131ce _ZN21AVAudioPlayerNodeImpl9StartImplEP11AVAudioTime + 204
5 AVFAudio 0x000000010b412482 -[AVAudioPlayerNode playAtTime:] + 82
6 AudioKit 0x0000000103a2270d _T08AudioKit13AKAudioPlayerC4playySo11AVAudioTimeCSg2at_tFTf4gn_n + 1933
7 AudioKit 0x0000000103a1c78d _T08AudioKit13AKAudioPlayerC5startyyF + 45
8 mysoundplayer 0x00000001035dd3b8 _T010mysoundplayer14ViewControllerC14playLoadedFileyyF + 1832
9 mysoundplayer 0x00000001035dca1e _T010mysoundplayer14ViewControllerC4playySo8UIButtonCF + 46
10 mysoundplayer 0x00000001035dca6c _T010mysoundplayer14ViewControllerC4playySo8UIButtonCFTo + 60
11 UIKit 0x000000010507c275 -[UIApplication sendAction:to:from:forEvent:] + 83
12 UIKit 0x00000001051f94a2 -[UIControl sendAction:to:forEvent:] + 67
13 UIKit 0x00000001051f97bf -[UIControl _sendActionsForEvents:withEvent:] + 450
14 UIKit 0x00000001051f81e7 -[UIControl touchesBegan:withEvent:] + 282
15 UIKit 0x00000001050f1916 -[UIWindow _sendTouchesForEvent:] + 2130
16 UIKit 0x00000001050f32de -[UIWindow sendEvent:] + 4124
17 UIKit 0x0000000105096e36 -[UIApplication sendEvent:] + 352
18 UIKit 0x00000001059d9434 __dispatchPreprocessedEventFromEventQueue + 2809
19 UIKit 0x00000001059dc089 __handleEventQueueInternal + 5957
20 CoreFoundation 0x00000001089df231 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x0000000108a7ee41 __CFRunLoopDoSource0 + 81
22 CoreFoundation 0x00000001089c3b49 __CFRunLoopDoSources0 + 185
23 CoreFoundation 0x00000001089c312f __CFRunLoopRun + 1279
24 CoreFoundation 0x00000001089c29b9 CFRunLoopRunSpecific + 409
25 GraphicsServices 0x000000010cc289c6 GSEventRunModal + 62
26 UIKit 0x000000010507a5e8 UIApplicationMain + 159
27 mysoundplayer 0x00000001035e12a7 main + 55
28 libdyld.dylib 0x000000010aa49d81 start + 1
29 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Source code:
import AudioKit
import AudioKitUI
import UIKit
class ViewController: UIViewController {
var micMixer: AKMixer!
var recorder: AKNodeRecorder!
var player: AKAudioPlayer!
var tape: AKAudioFile!
var timePitch: AKTimePitch!
var pitchShifter: AKPitchShifter!
var mainMixer : AKMixer!
var loadedFile: AKAudioFile!
let mic = AKMicrophone()
var state = State.readyToRecord
enum State {
case readyToRecord
case recording
case readyToPlay
case playing
}
#IBAction func toggleRecord(_ sender: UIButton) {
switch state {
case .recording:
sender.setTitle("record", for: .normal)
state = .readyToRecord
do {
try player.reloadFile()
} catch {
print("Error reloading!")
}
let recordedDuration = player != nil ? player.audioFile.duration : 0
if recordedDuration > 0.0 {
recorder.stop()
let randomfilename:String = NSUUID().uuidString + ".m4a"
print("Filename: \(randomfilename)")
player.audioFile.exportAsynchronously(name: randomfilename, baseDir: .documents, exportFormat: .m4a, callback: {file, exportError in
if let error = exportError {
print("Export failed \(error)")
} else {
print("Export succeeded")
self.loadedFile = file
}
})
}
case .readyToRecord:
do {
try recorder.record()
sender.setTitle("stop", for: .normal)
state = .recording
} catch { print("Error recording!") }
default:
print("no")
}
}
#IBAction func play(_ sender: UIButton) {
playLoadedFile()
}
#IBAction func valueChanged(_ sender: UISlider) {
timePitch.pitch = Double(sender.value)
}
func playLoadedFile() {
do {
try player.replace(file: loadedFile)
player.start()
} catch { print("Error playing!") }
}
func exportedAudioFile(filename: String) {
print("yay")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
AKAudioFile.cleanTempDirectory()
AKSettings.bufferLength = .medium
AKSettings.defaultToSpeaker = true
//inputPlot.node = mic
micMixer = AKMixer(mic)
mainMixer = AKMixer(player,timePitch)
pitchShifter = AKPitchShifter(player)
timePitch = AKTimePitch(player)
recorder = try? AKNodeRecorder(node: micMixer)
if let file = recorder.audioFile {
player = try? AKAudioPlayer(file: file)
}
AudioKit.output = timePitch // works with player
AudioKit.start()
print("mainMixer status: \(mainMixer.isStarted)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
It looks like mainMixer isn't connected to anything. Try changing AudioKit.output = timePitch to AudioKit.output = mainMixer.
As for best practices, get rid of any try?s. Use a do try catch and at least print the error.
if let file = recorder.audioFile {
do{
player = try AKAudioPlayer(file: file)
} catch {
print(error)
}
}
You’re attaching the player to the mixer before you create it. At the time where you give player to AKMixer(), it is nil. Move the mixer creation after the player assignment.

Swift Error libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

I am new in Swift and I need your help.
lazy var profileImageView: UIImageView = {
let imageView = UIImageView()
imageView.image = UIImage(named: "Userprofile")
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleAspectFill
var tap = UITapGestureRecognizer(target: self, action: Selector(("handleSelectProfileImageView")))
imageView.addGestureRecognizer(tap)
imageView.isUserInteractionEnabled = true
return imageView
}()
func handleSelectProfileImageView() {
let picker = UIImagePickerController()
picker .delegate = self
picker.sourceType = UIImagePickerControllerSourceType.photoLibrary
self.present(picker, animated: true)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
profileImageView.image = image
}else
{
//ERROR
}
self.dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
print("canceled picker")
dismiss(animated: true, completion: nil)
}
}
And then I get this error:
017-01-04 19:39:18.889 ChatUp[7484:136643] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ChatUp.LoginController handleSelectProfileImageView]: unrecognized selector sent to instance 0x7fe94cc0c0c0'
* First throw call stack:
(
0 CoreFoundation 0x000000010a41ad4b exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000109e7c21e objc_exception_throw + 48
2 CoreFoundation 0x000000010a48af04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010a3a0005 ___forwarding_ + 1013
4 CoreFoundation 0x000000010a39fb88 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010b48d409 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 57
6 UIKit 0x000000010b4951a8 _UIGestureRecognizerSendTargetActions + 109
7 UIKit 0x000000010b492c77 _UIGestureRecognizerSendActions + 227
8 UIKit 0x000000010b491f03 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 891
9 UIKit 0x000000010b47df7e _UIGestureEnvironmentUpdate + 1395
10 UIKit 0x000000010b47d9c3 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 521
11 UIKit 0x000000010b47cba6 -[UIGestureEnvironment _updateGesturesForEvent:window:] + 286
12 UIKit 0x000000010afc2c1d -[UIWindow sendEvent:] + 3989
13 UIKit 0x000000010af6f9ab -[UIApplication sendEvent:] + 371
14 UIKit 0x000000010b75c72d dispatchPreprocessedEventFromEventQueue + 3248
15 UIKit 0x000000010b755463 __handleEventQueue + 4879
16 CoreFoundation 0x000000010a3bf761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
17 CoreFoundation 0x000000010a3a498c __CFRunLoopDoSources0 + 556
18 CoreFoundation 0x000000010a3a3e76 __CFRunLoopRun + 918
19 CoreFoundation 0x000000010a3a3884 CFRunLoopRunSpecific + 420
20 GraphicsServices 0x000000010e329a6f GSEventRunModal + 161
21 UIKit 0x000000010af51c68 UIApplicationMain + 159
22 ChatUp 0x000000010845d42f main + 111
23 libdyld.dylib 0x000000010d1c368d start + 1
24 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

NSUnknownKeyException on app startup [duplicate]

This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 7 years ago.
Program starts up and then an error is thrown and it brings me to the appDelegate.swift file --class AppDelegate: UIResponder, UIApplicationDelegate { -- thread 1:signal sigabort
Here is the code:
import UIKit
class ViewController: UIViewController {
let filemgr = NSFileManager.defaultManager()
let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
#IBOutlet weak var address: UITextField!
#IBOutlet weak var street: UITextField!
#IBOutlet weak var city: UITextField!
#IBOutlet weak var state: UITextField!
#IBOutlet weak var zip: UITextField!
#IBOutlet weak var status: UILabel!
var database = NSString() // <-- CRASHING HERE
override func viewDidLoad() {
super.viewDidLoad()
let docsDir = dirPaths[0]
let databasePath = docsDir.stringByAppendingString("/contacts.db") // This seems to work
if !filemgr.fileExistsAtPath(databasePath as String) {
let contactDB = FMDatabase(path: databasePath as String)
if contactDB == nil {
print("Error DB")
}
if contactDB.open() {
let sql = "CREATE TABLE IF NOT EXISTS Houses (ID INTEGER PRIMARY KEY AUTOINCREMENT, Address TEXT, Street TEXT, City TEXT, State TEXT, Zip TEXT)"
if !contactDB.executeStatements(sql) {
print("Error DB")
}
else {
print("Error DB")
}
}
}
}
#IBAction func saveData(sender: AnyObject) {
let docsDir = dirPaths[0]
let databasePath = docsDir.stringByAppendingString("/contacts.db") // This seems to work
if !filemgr.fileExistsAtPath(databasePath as String) {
let contactDB = FMDatabase(path: databasePath as String)
if contactDB.open() {
let sql = "insert into Houses (Address, State, City, State, Zip) values ('\(address),\(street),\(city),\(state),\(zip))"
let result = contactDB.executeUpdate(sql, withArgumentsInArray: nil)
if !result {
status.text = "Failed to add house"
print("DB Error")
}
else {
status.text = "Added House"
address.text = ""
street.text = ""
city.text = ""
state.text = ""
zip.text = ""
}
}
else {
print("DB Error")
}
}
}
#IBAction func findContact(sender: AnyObject) {
let docsDir = dirPaths[0]
let databasePath = docsDir.stringByAppendingString("/contacts.db")
if !filemgr.fileExistsAtPath(databasePath as String) {
let contactDB = FMDatabase(path: databasePath as String)
if contactDB.open() {
let sql = "SELECT address, street, state, state, zip WHERE ID = 1" // Change this later
let results:FMResultSet? = contactDB.executeQuery(sql,withArgumentsInArray: nil)
if results?.next() == true {
address.text = results?.stringForColumn("Address")
street.text = results?.stringForColumn("Street")
city.text = results?.stringForColumn("City")
state.text = results?.stringForColumn("State")
zip.text = results?.stringForColumn("Zip")
}
else {
status.text = "Record not found"
address.text = ""
street.text = ""
city.text = ""
state.text = ""
zip.text = ""
}
contactDB.close()
}
else {
print("DBError")
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Here are the errors:
2015-11-10 00:34:33.385 SQLiteDatabaseExample[3656:218507] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key name.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000106aa8f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000106522deb objc_exception_throw + 48
2 CoreFoundation 0x0000000106aa8b89 -[NSException raise] + 9
3 Foundation 0x000000010488fa6b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x0000000104e6e04c -[UIViewController setValue:forKey:] + 88
5 UIKit 0x000000010509ba71 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001069e9a80 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x000000010509a454 -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x0000000104e74c16 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x0000000104e75542 -[UIViewController loadView] + 178
10 UIKit 0x0000000104e758a0 -[UIViewController loadViewIfRequired] + 138
11 UIKit 0x0000000104e76013 -[UIViewController view] + 27
12 UIKit 0x0000000104d4f51c -[UIWindow addRootViewControllerViewIfPossible] + 61
13 UIKit 0x0000000104d4fc05 -[UIWindow _setHidden:forced:] + 282
14 UIKit 0x0000000104d614a5 -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x0000000104cdb396 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
16 UIKit 0x0000000104ce19c3 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1750
17 UIKit 0x0000000104cdeba3 -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x0000000108776784 -[FBSSerialQueue _performNext] + 192
19 FrontBoardServices 0x0000000108776af2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
20 CoreFoundation 0x00000001069d5011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x00000001069caf3c __CFRunLoopDoSources0 + 556
22 CoreFoundation 0x00000001069ca3f3 __CFRunLoopRun + 867
23 CoreFoundation 0x00000001069c9e08 CFRunLoopRunSpecific + 488
24 UIKit 0x0000000104cde4f5 -[UIApplication _run] + 402
25 UIKit 0x0000000104ce330d UIApplicationMain + 171
26 SQLiteDatabaseExample 0x00000001047a05ad main + 109
27 libdyld.dylib 0x000000010824f92d start + 1
28 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Check your ViewController's IBOutlets connections and remove any unwanted connection.It can happen when you delete the outlet code in your class.

Deleting a row in UITableView causes NSInternalInconsistencyException with computed property

I have a computed property as an instance variable:
var favorites: [PFObject]
get { return Array(ObjectManager.favorites) }
}
where ObjectManager.favorites is a Set static var on the ObjectManager class.
Below are my table view methods:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return favorites.count
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
//delete it from the original set
ObjectManager.removeFavoriteObject(favorites[indexPath.row])
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
println(favorites.count)
// Delete the row from the data source
}
//If there are no longer any fav objects, then there is no need to display the Edit button.
if favorites.isEmpty {
self.navigationItem.rightBarButtonItem = nil
}
}
This results in the following exception being trigger when I call deleteRowsAtIndexPaths.
2015-06-08 21:00:35.320 MedConf[56258:707923] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3347.44/UITableView.m:1623
2015-06-08 21:00:35.396 MedConf[56258:707923] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
*** First throw call stack:
(
0 CoreFoundation 0x00000001114aec65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000110defbb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001114aeaca +[NSException raise:format:arguments:] + 106
3 Foundation 0x0000000110a0498f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 UIKit 0x0000000111b30c53 -[UITableView _endCellAnimationsWithContext:] + 12678
5 UIKit 0x0000000121f59f1b -[UITableViewAccessibility deleteRowsAtIndexPaths:withRowAnimation:] + 48
6 MedConf 0x000000010f1cebb3 _TFC7MedConf28FavoritesTableViewController9tableViewfS0_FTCSo11UITableView18commitEditingStyleOSC27UITableViewCellEditingStyle17forRowAtIndexPathCSo11NSIndexPath_T_ + 195
7 MedConf 0x000000010f1ced87 _TToFC7MedConf28FavoritesTableViewController9tableViewfS0_FTCSo11UITableView18commitEditingStyleOSC27UITableViewCellEditingStyle17forRowAtIndexPathCSo11NSIndexPath_T_ + 87
8 UIKit 0x0000000111b56226 -[UITableView animateDeletionOfRowWithCell:] + 132
9 UIKit 0x0000000111b353fd __52-[UITableView _swipeActionButtonsForRowAtIndexPath:]_block_invoke + 72
10 UIKit 0x0000000111a54da2 -[UIApplication sendAction:to:from:forEvent:] + 75
11 UIKit 0x0000000111b6654a -[UIControl _sendActionsForEvents:withEvent:] + 467
12 UIKit 0x0000000111b65919 -[UIControl touchesEnded:withEvent:] + 522
13 UIKit 0x0000000111dffa10 _UIGestureRecognizerUpdate + 9487
14 UIKit 0x0000000111aa1686 -[UIWindow _sendGesturesForEvent:] + 1041
15 UIKit 0x0000000111aa22b2 -[UIWindow sendEvent:] + 666
16 UIKit 0x0000000111a68581 -[UIApplication sendEvent:] + 246
17 UIKit 0x0000000111a75d1c _UIApplicationHandleEventFromQueueEvent + 18265
18 UIKit 0x0000000111a505dc _UIApplicationHandleEventQueue + 2066
19 CoreFoundation 0x00000001113e2431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
20 CoreFoundation 0x00000001113d82fd __CFRunLoopDoSources0 + 269
21 CoreFoundation 0x00000001113d7934 __CFRunLoopRun + 868
22 CoreFoundation 0x00000001113d7366 CFRunLoopRunSpecific + 470
23 GraphicsServices 0x0000000113603a3e GSEventRunModal + 161
24 UIKit 0x0000000111a53900 UIApplicationMain + 1282
25 MedConf 0x000000010f1debf7 main + 135
26 libdyld.dylib 0x0000000113bff145 start + 1
27 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I'm not sure what the cause of the exception is, as it gets thrown even if I comment out line where I remove the object from the data source: ObjectManager.removeFavoriteObject(favorites[indexPath.row]).
Below is the removeFavoriteObject method.
static func removeFavoriteObject( objectToRemove: PFObject ) {
if contains(favorites, objectToRemove) {
if let favObject = objectToRemove as? Attendee {
favObject.isFavorite = false
} else if let favObject = objectToRemove as? Event {
favObject.isFavorite = false
} else if let favObject = objectToRemove as? Session {
favObject.isFavorite = false
}
}
favorites.remove(objectToRemove)
}
Try this
static func removeFavoriteObject( objectToRemove: PFObject ) {
if contains(favorites, objectToRemove) {
favorites.remove(objectToRemove)
if let favObject = objectToRemove as? Attendee {
favObject.isFavorite = false
} else if let favObject = objectToRemove as? Event {
favObject.isFavorite = false
} else if let favObject = objectToRemove as? Session {
favObject.isFavorite = false
}
}
}
try passing index of object to that removeFavoriteObject static method:
ObjectManager.removeFavoriteObject(indexPath.row)
and as you are passing element index from favourites array, it must be there. So no need to check using 'if'.
static func removeFavoriteObject( index: Int ) {
var objectToRemove = favorites[index]
if let favObject = objectToRemove as? Attendee {
favObject.isFavorite = false
}
else if let favObject = objectToRemove as? Event {
favObject.isFavorite = false
}
else if let favObject = objectToRemove as? Session {
favObject.isFavorite = false
}
favorites.removeAtIndex(index)
}
tableview.beginUpdates()
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
tableview.endUpdates()
Hope this helps

Resources