UPDATE 2019/07/23 16:37:00 - I've updated the main storyboard script below in the original content. After trying several things and running into new errors that had to be corrected I have come full circle back to the same error message. Updated script and stack trace below. This time the stracktrace is referencing a 'null value' most likely referring to the following line of code but removing it does not remove the error unless that's a simulator's cache issue:
guard (URL(string: "http://southeastgeorgiatoday.com") != nil) else {
return
}
UPDATE 2019/07/22 20:01:00 - I have made some progress working with the referencing outlets and I finally have the app loading but now instead of crashing during the load, it crashes during the click event when an UIButton is clicked to load a UIViewController which which is a WKWebView. So now instead of crashing at the app load, it crashes on the click and loading of the webview. I have updated the script and the stack trace info.
Created actions for UIButtons to load wkwebviews via outlets.
Here is my storyboard script showing one of the uibuttons within it, there is a total of six of them but for the purpose of troubleshooting I've only included now of them here. They are all pretty much written in the same fashion making sure to identify the appropriate button and web view where applicable.
import WebKit
import UIKit
class UIViewController_sega: UIViewController, WKNavigationDelegate {
#IBAction func UIButton_sega(_ sender: Any) {
performSegue(withIdentifier: "WKWebView_sega", sender: sender)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let UIButton_sega = sender as? UIButton, let destination = segue.destination as? UIViewController_sega {}
}
#IBOutlet var WKWebView_sega: WKWebView!
override func loadView() {}
override func viewDidLoad() {
super.viewDidLoad()
guard (URL(string: "http://southeastgeorgiatoday.com") != nil) else {
return
}
}
func WKWebView_sega(_ webView: WKWebView, didCommit navigation: WKNavigation!) {}
}
Here is my AppDelegate.swift file:
import UIKit
import CoreData
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
return true
}
func applicationWillTerminate(_ application: UIApplication) {
self.saveContext()
}
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "SoutheastGeorgiaToday")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()
func saveContext () {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
try context.save()
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
}
I get the "Thread 1: signal SIGABRT" at this line in the AppDelegate.swift file: (this still remains the case only it happens during the WKWebView load after the UIButton click; where as previously it was during the app load and this time stack trace is referencing the class of the WKWebView 'WKWebView_s'; not the UIButton class 'button_sega' )
class AppDelegate: UIResponder, UIApplicationDelegate {
Here is my stacktrace
2019-07-23 16:37:01.980409-0400 SoutheastGeorgiaToday[1598:33823] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not create a segue of class '(null)''
*** First throw call stack:
(
0 CoreFoundation 0x000000010ebe71bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010c01c735 objc_exception_throw + 48
2 CoreFoundation 0x000000010ebe6f42 +[NSException raise:format:arguments:] + 98
3 Foundation 0x000000010ba1f877 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
4 UIKitCore 0x000000011777555d -[UIStoryboardSegueTemplate segueWithDestinationViewController:] + 216
5 UIKitCore 0x0000000117775731 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 74
6 UIKitCore 0x00000001177756b9 -[UIStoryboardSegueTemplate _perform:] + 82
7 UIKitCore 0x000000011777597b -[UIStoryboardSegueTemplate perform:] + 157
8 UIKitCore 0x00000001175d4ecb -[UIApplication sendAction:to:from:forEvent:] + 83
9 UIKitCore 0x00000001170100bd -[UIControl sendAction:to:forEvent:] + 67
10 UIKitCore 0x00000001170103da -[UIControl _sendActionsForEvents:withEvent:] + 450
11 UIKitCore 0x000000011700f31e -[UIControl touchesEnded:withEvent:] + 583
12 UIKitCore 0x00000001171a8018 _UIGestureEnvironmentSortAndSendDelayedTouches + 5387
13 UIKitCore 0x00000001171a1fd1 _UIGestureEnvironmentUpdate + 1506
14 UIKitCore 0x00000001171a19ad -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 478
15 UIKitCore 0x00000001171a171d -[UIGestureEnvironment _updateForEvent:window:] + 200
16 UIKitCore 0x000000011761178a -[UIWindow sendEvent:] + 4058
17 UIKitCore 0x00000001175ef394 -[UIApplication sendEvent:] + 352
18 UIKitCore 0x00000001176c45a9 __dispatchPreprocessedEventFromEventQueue + 3054
19 UIKitCore 0x00000001176c71cb __handleEventQueueInternal + 5948
20 CoreFoundation 0x000000010eb4c721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x000000010eb4bf93 __CFRunLoopDoSources0 + 243
22 CoreFoundation 0x000000010eb4663f __CFRunLoopRun + 1263
23 CoreFoundation 0x000000010eb45e11 CFRunLoopRunSpecific + 625
24 GraphicsServices 0x0000000112e9f1dd GSEventRunModal + 62
25 UIKitCore 0x00000001175d381d UIApplicationMain + 140
26 SoutheastGeorgiaToday 0x000000010afca1c7 main + 71
27 libdyld.dylib 0x000000010f94b575 start + 1
28 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I have researched all references but they are all different and none of them mirror my exact situation and scenario. Like I said, I have tried the other articles and I see how they are similar, but it did not fix it so something is different; I just don't know what. When I do what it say I get other error messages that remove items changed and leave other items. What remains in my storyboard now removed all errors caused by the fix in the article individuals keep rerunning but then it still doesn't solve the thread 1 signal issue.
Related
I am attempting to create an app in Xcode. I have added a stepper and a text box, and added outlets to the ViewController for these. When making an action to capture the change in stepper value, my code crashes upon clicking the stepper if I include any code at all in my changing value function.
Here is my ViewController.swift file:
import UIKit
class ViewController: UIViewController {
#IBAction func stepperValueChanged(_ sender: UIStepper) {
let newVal = Int(sender.value).description
self.valueLabel.text = String(newVal)
}
#IBOutlet weak var stepper: UIStepper!
#IBOutlet weak var generate: UIButton!
#IBOutlet weak var valueLabel: UILabel!
#IBAction func buttonClicked(_ sender: UIButton) {
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
It says my main thread sends signal SIGABRT in the AppDelegate file, which I have not modified:
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
This is the console output:
2019-12-18 00:16:00.234618-0600 core[95979:16142343] -[NSLayoutConstraint setText:]: unrecognized selector sent to instance 0x600002c202d0
2019-12-18 00:16:00.240568-0600 core[95979:16142343] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSLayoutConstraint setText:]: unrecognized selector sent to instance 0x600002c202d0'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23c4f02e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50b97b20 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23c6ff94 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00007fff23c53dac ___forwarding___ + 1436
4 CoreFoundation 0x00007fff23c55f38 _CF_forwarding_prep_0 + 120
5 core 0x000000010c9fd5f3 $s4core14ViewControllerC19stepperValueChangedyySo9UIStepperCF + 643
6 core 0x000000010c9fd714 $s4core14ViewControllerC19stepperValueChangedyySo9UIStepperCFTo + 68
7 UIKitCore 0x00007fff47850dfa -[UIApplication sendAction:to:from:forEvent:] + 83
8 UIKitCore 0x00007fff4722ac22 -[UIControl sendAction:to:forEvent:] + 223
9 UIKitCore 0x00007fff4722af6c -[UIControl _sendActionsForEvents:withEvent:] + 398
10 UIKitCore 0x00007fff47be4a72 -[UIStepperHorizontalVisualElement _updateCount:] + 376
11 UIKitCore 0x00007fff47be473f -[UIStepperHorizontalVisualElement endTrackingWithTouch:withEvent:] + 33
12 UIKitCore 0x00007fff47258372 -[UIStepper endTrackingWithTouch:withEvent:] + 95
13 UIKitCore 0x00007fff47229e95 -[UIControl touchesEnded:withEvent:] + 427
14 UIKitCore 0x00007fff4788bc1d -[UIWindow _sendTouchesForEvent:] + 2604
15 UIKitCore 0x00007fff4788d524 -[UIWindow sendEvent:] + 4596
16 UIKitCore 0x00007fff47868427 -[UIApplication sendEvent:] + 356
17 UIKitCore 0x00007fff478e987e __dispatchPreprocessedEventFromEventQueue + 6847
18 UIKitCore 0x00007fff478ec344 __handleEventQueueInternal + 5980
19 CoreFoundation 0x00007fff23bb2221 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
20 CoreFoundation 0x00007fff23bb214c __CFRunLoopDoSource0 + 76
21 CoreFoundation 0x00007fff23bb1924 __CFRunLoopDoSources0 + 180
22 CoreFoundation 0x00007fff23bac62f __CFRunLoopRun + 1263
23 CoreFoundation 0x00007fff23babe16 CFRunLoopRunSpecific + 438
24 GraphicsServices 0x00007fff38438bb0 GSEventRunModal + 65
25 UIKitCore 0x00007fff4784fb48 UIApplicationMain + 1621
26 core 0x000000010c9ff63b main + 75
27 libdyld.dylib 0x00007fff51a1dc25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
What could be the problem?
I have a quick look in debug console and I found something wrong. it's related to constraints, You are trying to set text in NSLayoutConstraint, Which is logically incorrect. Because NSLayoutConstraint doesn't have any property to set text.
Please review your code once and find out where you are trying to do like [NSLayoutConstraint setText:] or you can share your code with me, I can have a look on your code and fix it for you.
Since the latest update, I get the error
"libc++abi.dylib: terminating with uncaught exception of type
NSException
(lldb)"
whenever I try to connect to parse
I can't even perform a simple task like create a user, as it will always crash. I suspect something changed after Xcode's recent update, and I cannot figure out what it is.
I suspect it could be the libc++abi.dylib library not been supported, but I don't know what to do about this.
Here's my View controller
import UIKit
import Parse
class ViewController: UIViewController {
#IBOutlet var username: UITextField!
#IBOutlet var password: UITextField!
func displayAlert(title: String, message: String) {
let alertcontroller = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertcontroller.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alertcontroller, animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
#IBAction func signup(_ sender: Any) {
if username.text == "" || password.text == "" {
displayAlert(title: "Error in Form", message: "Please fill in the information")
} else {
let user = PFUser()
user.username = username.text
user.password = password.text
}
}
Here's my App Delegate
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
//--------------------------------------
// MARK: - UIApplicationDelegate
//--------------------------------------
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Enable storing and querying data from Local Datastore.
// Remove this line if you don't want to use Local Datastore features or want to use cachePolicy.
Parse.enableLocalDatastore()
let parseConfiguration = ParseClientConfiguration(block: { (ParseMutableClientConfiguration) -> Void in
ParseMutableClientConfiguration.applicationId = "......"
ParseMutableClientConfiguration.clientKey = "......"
ParseMutableClientConfiguration.server = "........"
})
Parse.initialize(with: parseConfiguration)
Here's the error
019-05-22 12:51:10.776625+0200
ParseStarterProject-Swift[18144:1046582] [MC] System group container
for systemgroup.com.apple.configurationprofiles path is
/Users/ejike/Library/Developer/CoreSimulator/Devices/8AAB1103-8B3E-4584-BFAE-170720DE4BEF/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2019-05-22 12:51:10.780381+0200
ParseStarterProject-Swift[18144:1046582] [MC] Reading from private
effective user settings.
2019-05-22 12:51:23.291890+0200
ParseStarterProject-Swift[18144:1046582] *** Terminating app due to
uncaught exception 'NSInternalInconsistencyException', reason: 'The
class PFUser must be registered with registerSubclass before using
Parse.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000107dad6fb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000107351ac5 objc_exception_throw + 48
2 CoreFoundation 0x0000000107dad555 +[NSException raise:format:] + 197
3 ParseStarterProject-Swift 0x0000000105f5a7e1 -[PFObject init] + 189
4 ParseStarterProject-Swift 0x0000000105f26533 $sSo6PFUserCABycfcTO +
19
5 ParseStarterProject-Swift 0x0000000105f25bdf $sSo6PFUserCABycfC + 31
6 ParseStarterProject-Swift 0x0000000105f25647
$s25ParseStarterProject_Swift14ViewControllerC6signupyyypF + 1383
7 ParseStarterProject-Swift 0x0000000105f25c3c
$s25ParseStarterProject_Swift14ViewControllerC6signupyyypFTo + 76
8 UIKitCore 0x0000000114799204 -[UIApplication
sendAction:to:from:forEvent:] + 83
9 UIKitCore 0x00000001141eec19 -[UIControl sendAction:to:forEvent:] +
67
10 UIKitCore 0x00000001141eef36 -[UIControl
_sendActionsForEvents:withEvent:] + 450
11 UIKitCore 0x00000001141edeec -[UIControl touchesEnded:withEvent:] +
583
12 UIKitCore 0x00000001147d1eee -[UIWindow _sendTouchesForEvent:] +
2547
13 UIKitCore 0x00000001147d35d2 -[UIWindow sendEvent:] + 4079
14 UIKitCore 0x00000001147b1d16 -[UIApplication sendEvent:] + 356
15 UIKitCore 0x0000000114882293
__dispatchPreprocessedEventFromEventQueue + 3232
16 UIKitCore 0x0000000114884bb9 __handleEventQueueInternal + 5911
17 CoreFoundation 0x0000000107d14be1
CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
18 CoreFoundation 0x0000000107d14463 __CFRunLoopDoSources0 + 243
19 CoreFoundation 0x0000000107d0eb1f __CFRunLoopRun + 1231
20 CoreFoundation 0x0000000107d0e302 CFRunLoopRunSpecific + 626
21 GraphicsServices 0x000000010cf112fe GSEventRunModal + 65
22 UIKitCore 0x0000000114797ba2 UIApplicationMain + 140
23 ParseStarterProject-Swift 0x0000000105f27dab main + 75
24 libdyld.dylib 0x00000001091a3541 start + 1
25 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type
NSException
(lldb)
I am a bit new in the development of native apps for iOS. I am working on Swift 4 and when trying to move to another screen from my login, I am generating the following error:
BanGuayaPrototype[11289:1143773] -[BanGuayaPrototype.ViewController getTextId:]: unrecognized selector sent to instance 0x7fe5f69027d0 2018-01-10 14:40:06.213350-0500
BanGuayaPrototype[11289:1143773] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BanGuayaPrototype.ViewController getTextId:]: unrecognized selector sent to instance 0x7fe5f69027d0'
* First throw call stack: (
0 CoreFoundation 0x000000010d42512b exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000108ce3f41 objc_exception_throw + 48
2 CoreFoundation 0x000000010d4a6024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKit 0x0000000109a52f51 -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x000000010d3a7f78 ___forwarding_ + 1432
5 CoreFoundation 0x000000010d3a7958 _CF_forwarding_prep_0 + 120
6 UIKit 0x0000000109820972 -[UIApplication sendAction:to:from:forEvent:] + 83
7 UIKit 0x000000010999fc3c -[UIControl sendAction:to:forEvent:] + 67
8 UIKit 0x000000010999ff59 -[UIControl _sendActionsForEvents:withEvent:] + 450
9 UIKit 0x000000010a548407 -[UITextField _resignFirstResponder] + 155
10 UIKit 0x0000000109a52939 -[UIResponder _finishResignFirstResponder] + 286
11 UIKit 0x000000010a548026 -[UITextField _finishResignFirstResponder] + 48
12 UIKit 0x0000000109a529e8 -[UIResponder resignFirstResponder] + 140
13 UIKit 0x000000010a547ef6 -[UITextField resignFirstResponder] + 135
14 UIKit 0x00000001098d6463 -[UIView(Hierarchy) _removeFirstResponderFromSubtree] + 167
15 UIKit 0x00000001098d6a73 UIViewWillBeRemovedFromSuperview + 72
16 UIKit 0x00000001098d685d -[UIView(Hierarchy) removeFromSuperview] + 95
17 UIKit 0x000000010999b591 __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke.674 + 858
18 UIKit 0x0000000109994b5b -[UIPresentationController transitionDidFinish:] + 111
19 UIKit 0x0000000109c1cc1e -[_UICurrentContextPresentationController transitionDidFinish:] + 44
20 UIKit 0x0000000109998f4f __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 183
21 UIKit 0x000000010a58d088 -[_UIViewControllerTransitionContext completeTransition:] + 102
22 UIKit 0x0000000109991dba -[UITransitionView notifyDidCompleteTransition:] + 251
23 UIKit 0x0000000109991a31 -[UITransitionView _didCompleteTransition:] + 1397
24 UIKit 0x00000001099940c8 -[UITransitionView _transitionDidStop:finished:] + 104
25 UIKit 0x00000001098b56c4 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 343
26 UIKit 0x00000001098b5d23 -[UIViewAnimationState animationDidStop:finished:] + 293
27 UIKit 0x00000001098b5dd7 -[UIViewAnimationState animationDidStop:finished:] + 473
28 QuartzCore 0x00000001096696bd _ZN2CA5Layer23run_animation_callbacksEPv + 323
29 libdispatch.dylib 0x000000010e54733d _dispatch_client_callout + 8
30 libdispatch.dylib 0x000000010e5525f9 _dispatch_main_queue_callback_4CF + 628
31 CoreFoundation 0x000000010d3e7e39 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9
32 CoreFoundation 0x000000010d3ac462 __CFRunLoopRun + 2402
33 CoreFoundation 0x000000010d3ab889 CFRunLoopRunSpecific + 409
34 GraphicsServices 0x0000000110ff39c6 GSEventRunModal + 62
35 UIKit 0x000000010981f5d6 UIApplicationMain + 159
36 BanGuayaPrototype 0x00000001083a31d7 main + 55
37 libdyld.dylib 0x000000010e5c3d81 start + 1
38 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
Below are the classes involved:
ViewController.swift
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var getText: UITextField!
var cliente = Cliente()
#IBAction func onGoButtonLH(_ sender: Any) {
let idTxt:String? = getText.text
if idTxt == "1234" {
self.performSegue(withIdentifier: "LoginToComercial", sender: self)
}else{
let urlString = "http://localhost:8080/RestServiceBgPrototype/cognitiva/clientService/"+idTxt!
guard let url = URL(string: urlString) else { return }
URLSession.shared.dataTask(with: url) { (data, response, error) in
if error != nil {
print(error!.localizedDescription)
}
guard let data = data else { return }
//Implement JSON decoding and parsing
do {
let decoder = JSONDecoder()
self.cliente = try! decoder.decode(Cliente.self, from: data)
OperationQueue.main.addOperation{
self.performSegue(withIdentifier: "LoginToHome", sender: self.cliente)
}
}
}.resume()
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "LoginToHome") {
let homeViewController = segue.destination as? HomeViewController
let cliente = sender as! Cliente
homeViewController?.cliente = cliente
}
}
}
HomeViewController.swift
class HomeViewController: UIViewController {
#IBOutlet weak var userLabel: UILabel!
var cliente = Cliente()
override func viewDidLoad() {
super.viewDidLoad()
let nombreCliente:String = cliente.nombre
let fullNameArr = nombreCliente.components(separatedBy:(" "))
let nombre = fullNameArr[2]
let apellido = fullNameArr[0]
self.userLabel.text = "Hola, "+nombre.capitalized+" "+apellido.capitalized
}
}
Any idea why I get this error?
To debug crash while it's happening and inspect what is the reason.
You can do this:
In your Breakpoint navigator at the bottom click plus button and add exception breakpoint
That will add to your project all exception break point.
It means when ever your app crashes is will stop on a line which generate crash.
Then we can figure out what to do next.
However, you are using force unwrap a lot, for instance:
let cliente = sender as! Cliente
if error != nil {
print(error!.localizedDescription)
}
It's better to do like this
if let error = error {
print(error.localizedDescription)
}
Please try not to use !. In case if your application encounter nil instead of object program will crash.
To answer your question. Your application do crash trying to send message getTextId to an object of type BanGuayaPrototype.ViewController.
This selector is not recognised. That's the root of your crash.
How did that happen?
For now what I can think. You have an object:
let obj: BanGuayaPrototype
and what are you trying to do is to call a method getTextId on this object.
This type of error is common in ObjectiveC. Occurs when you can try to send message to an object. If given object are unable to handle message program is crashing.
I'm designing my first App, and am fairly new to Swift.
My app will build successfully, but won't go past the launch screen and gives the error "libc++abi.dylib: terminating with uncaught exception of type NSException". The other similar questions I found on this I attempted the fix but could not get it to work.
I am unsure if the problem is on my launch screen or on the view controller.
There is also a warning about "The use of Swift 3 #objc inference in Swift 4 mode is deprecated."
Is this what's causing the error?
Thanks in advance.
Launch Screen Code (App Delegate):
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
View Controller Code:
import UIKit
class ViewController: UIViewController, UISearchBarDelegate {
//connection that ties search bar in view to input for viewcontroller
#IBOutlet weak var searchbar: UISearchBar!
override func viewDidLoad() {
super.viewDidLoad()
searchbar.delegate = self
}
//activates keyboard etc when searchbar clicked
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
searchBar.resignFirstResponder()
//(dncode) is string that will equal text as entered into search bar
let dncode = String()
searchBar.text! = dncode
if let url = URL (string: "https://www.example.com/(dncode)")
{
//this section to check and auto open URL in default browser "Safari"
if #available(iOS 10.0, *)
{
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
}
}
Log:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<DNAppBeta.ViewController 0x7fe1edd095e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key SearchBar.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010d5ad1cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000109189f41 objc_exception_throw + 48
2 CoreFoundation 0x000000010d5ad119 -[NSException raise] + 9
3 Foundation 0x0000000108bac1e3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 292
4 UIKit 0x000000010a17f41f -[UIViewController setValue:forKey:] + 87
5 UIKit 0x000000010a46e9dd -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x000000010d55057d -[NSArray makeObjectsPerformSelector:] + 317
7 UIKit 0x000000010a46d393 -[UINib instantiateWithOwner:options:] + 1856
8 UIKit 0x000000010a1864e0 -[UIViewController _loadViewFromNibNamed:bundle:] + 383
9 UIKit 0x000000010a186e0c -[UIViewController loadView] + 177
10 UIKit 0x000000010a18713d -[UIViewController loadViewIfRequired] + 195
11 UIKit 0x000000010a18799a -[UIViewController view] + 27
12 UIKit 0x000000010a055ae3 -[UIWindow addRootViewControllerViewIfPossible] + 122
13 UIKit 0x000000010a0561eb -[UIWindow _setHidden:forced:] + 294
14 UIKit 0x000000010a069098 -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x0000000109fdb521 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4711
16 UIKit 0x0000000109fe0751 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1720
17 UIKit 0x000000010a3a5e00 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 924
18 UIKit 0x000000010a778840 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
19 UIKit 0x000000010a3a59f9 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 249
20 UIKit 0x000000010a3a6257 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 668
21 UIKit 0x000000010ad19dd9 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 262
22 UIKit 0x000000010ad19c92 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 444
23 UIKit 0x000000010a9fb87e __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 420
24 UIKit 0x000000010abf8e8e _performActionsWithDelayForTransitionContext + 100
25 UIKit 0x000000010a9fb67a -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 231
26 UIKit 0x000000010a777e9d -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
27 UIKit 0x0000000109fdefd2 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 523
28 UIKit 0x000000010a5b389b -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 369
29 FrontBoardServices 0x00000001145761b4 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 338
30 FrontBoardServices 0x000000011457eca9 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 235
31 libdispatch.dylib 0x000000010e60243c _dispatch_client_callout + 8
32 libdispatch.dylib 0x000000010e607af4 _dispatch_block_invoke_direct + 592
33 FrontBoardServices 0x00000001145aa6ce __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
34 FrontBoardServices 0x00000001145aa384 -[FBSSerialQueue _performNext] + 464
35 FrontBoardServices 0x00000001145aa8f3 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
36 CoreFoundation 0x000000010d5502b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
37 CoreFoundation 0x000000010d5efd31 __CFRunLoopDoSource0 + 81
38 CoreFoundation 0x000000010d534c19 __CFRunLoopDoSources0 + 185
39 CoreFoundation 0x000000010d5341ff __CFRunLoopRun + 1279
40 CoreFoundation 0x000000010d533a89 CFRunLoopRunSpecific + 409
41 GraphicsServices 0x00000001116e79c6 GSEventRunModal + 62
42 UIKit 0x0000000109fe223c UIApplicationMain + 159
43 DoughNationAppBeta 0x000000010886a557 main + 55
44 libdyld.dylib 0x000000010e67ed81 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The problem is that
#IBOutlet weak var searchbar: UISearchBar! was
#IBOutlet weak var SearchBar: UISearchBar! before.
So when you attached search bar's IBoutlet in Interface Builder the name of the property was SearchBar. After that, you changed the name of the property in the code, and now you need to open interface builder and make a new connection with iboutlet. This will fix your issue.
I am probably trying to make the easiest app ever but I am unable to get it to work. The the app has two buttons. One that plays a short noise and the other is a donate button. I can get the noise to work but not the link or viceversa or neither. And one of the overrides keeps becoming an error and I dont know why so I put it as a comment so that the app would build. the error that comes up is that it asks me to remove the word override. Here is the code:
import UIKit
import AVFoundation
class ViewController: UIViewController {
let soundFilenames = ["WeahV2"]
var audioPlayers = [AVAudioPlayer]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// Set up audio player
for sound in soundFilenames {
do {
// Try to do something
let url = NSURL(fileURLWithPath: Bundle.main.path( forResource: sound, ofType: "mp3")!)
let audioPlayer = try AVAudioPlayer(contentsOf: url as URL)
audioPlayers.append(audioPlayer)
}
catch {
//catch the error that is thrown
audioPlayers.append(AVAudioPlayer())
}
}
}
//override func didReceiveMemoryWarning() {
// super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
//}
#IBAction func buttonTapped(_ sender: UIButton) {
// get the audio player that corresponds with the button tapped
let audioPlayer = audioPlayers[sender.tag]
audioPlayer.play()
}
#IBAction func Donate( sender: AnyObject) {
if let url = URL(string: "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=5Q29GRLXF4W9C&lc=CA&item_name=BiBoCo¤cy_code=CAD&bn=PP-DonationsBF%3Abtn_donateCC_LG.gif%3ANonHosted") {
UIApplication.shared.open(url, options: [:]) {
boolean in
// do something with the boolean
}
}
}
}
Here is the output information( might be an error for all i know, i dont know how to understand it):
2017-03-08 17:10:34.256692 The Weah[22117:1032077] [aqme] 255: AQDefaultDevice (1): skipping input stream 0 0 0x0
2017-03-08 17:10:36.241162 The Weah[22117:1032029] [aqme] 177: timed out after 0.012s (126 127); suspension count=0 (IOSuspensions: )
2017-03-08 17:10:36.264895 The Weah[22117:1032077] [aqme] 255: AQDefaultDevice (128): skipping input stream 0 0 0x0
2017-03-08 17:10:36.498 The Weah[22117:1030634] -[The_Weah.ViewController Donate:]: unrecognized selector sent to instance 0x7fef9a806b20
2017-03-08 17:10:37.037 The Weah[22117:1030634] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[The_Weah.ViewController Donate:]: unrecognized selector sent to instance 0x7fef9a806b20'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ca9dd4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010c4ff21e objc_exception_throw + 48
2 CoreFoundation 0x000000010cb0df04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010ca23005 ___forwarding___ + 1013
4 CoreFoundation 0x000000010ca22b88 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010cec38bc -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x000000010d049c38 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x000000010d049f51 -[UIControl _sendActionsForEvents:withEvent:] + 444
8 UIKit 0x000000010d048e4d -[UIControl touchesEnded:withEvent:] + 668
9 UIKit 0x000000010cf31545 -[UIWindow _sendTouchesForEvent:] + 2747
10 UIKit 0x000000010cf32c33 -[UIWindow sendEvent:] + 4011
11 UIKit 0x000000010cedf9ab -[UIApplication sendEvent:] + 371
12 UIKit 0x000000010d6cc72d __dispatchPreprocessedEventFromEventQueue + 3248
13 UIKit 0x000000010d6c5463 __handleEventQueue + 4879
14 CoreFoundation 0x000000010ca42761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x000000010ca2798c __CFRunLoopDoSources0 + 556
16 CoreFoundation 0x000000010ca26e76 __CFRunLoopRun + 918
17 CoreFoundation 0x000000010ca26884 CFRunLoopRunSpecific + 420
18 GraphicsServices 0x00000001116eda6f GSEventRunModal + 161
19 UIKit 0x000000010cec1c68 UIApplicationMain + 159
20 The Weah 0x000000010bbb56bf main + 111
21 libdyld.dylib 0x0000000111ce168d start + 1
22 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
When exactly the app stops working?
Does it happen when you interact with an UI element, like one of the buttons?
I'm assuming there is a "Donate" button on the UI... Make sure that the connection from the button to the action is correctly wired.
One of the easiest ways to double-check the wiring is from the interface builder itself.
Click on the Connections Inspector button:
Search for any ! sign. If there are any, delete the connection and re-create it.
If the above doesn't do the trick, please share your project so I can help on debugging it.
(Regarding the didReceiveMemoryWarning override, you can safely delete it for now.)