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)
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.
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.
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 a new Swift programmer. I'm building my first app with TableViewController + NavigationController.
In my app, I can see this:
If I click on Plus button I can see this View:
Then I compile all field and then I click on OK button. But I have this error:
2017-04-20 16:23:48.158 ArduinoHomeKit_bis[3238:795882] -[LuciKit id]: unrecognized selector sent to instance 0x61000026a700
2017-04-20 16:23:48.162 ArduinoHomeKit_bis[3238:795882] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LuciKit id]: unrecognized selector sent to instance 0x61000026a700'
*** First throw call stack:
(
0 CoreFoundation 0x0000000107745b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001045c0141 objc_exception_throw + 48
2 CoreFoundation 0x00000001077b5134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00000001076cc840 ___forwarding___ + 1024
4 CoreFoundation 0x00000001076cc3b8 _CF_forwarding_prep_0 + 120
5 ArduinoHomeKit_bis 0x0000000103fc0603 _TFC18ArduinoHomeKit_bis28ListaLuciTableViewController14tornaAllaListafCSo17UIStoryboardSegueT_ + 435
6 ArduinoHomeKit_bis 0x0000000103fc098a _TToFC18ArduinoHomeKit_bis28ListaLuciTableViewController14tornaAllaListafCSo17UIStoryboardSegueT_ + 58
7 UIKit 0x0000000105903bbf -[UIStoryboardUnwindSegueTemplate _performWithDestinationViewController:sender:] + 214
8 UIKit 0x0000000105903ab6 -[UIStoryboardUnwindSegueTemplate _perform:] + 83
9 UIKit 0x000000010566ea1f -[UIStoryboardSegueTemplate perform:] + 157
10 UIKit 0x0000000104ea8d22 -[UIApplication sendAction:to:from:forEvent:] + 83
11 UIKit 0x00000001052e35c7 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 149
12 UIKit 0x0000000104ea8d22 -[UIApplication sendAction:to:from:forEvent:] + 83
13 UIKit 0x000000010502d25c -[UIControl sendAction:to:forEvent:] + 67
14 UIKit 0x000000010502d577 -[UIControl _sendActionsForEvents:withEvent:] + 450
15 UIKit 0x000000010502d6eb -[UIControl _sendActionsForEvents:withEvent:] + 822
16 UIKit 0x000000010502c4b2 -[UIControl touchesEnded:withEvent:] + 618
17 UIKit 0x0000000104f1649a -[UIWindow _sendTouchesForEvent:] + 2707
18 UIKit 0x0000000104f17bb0 -[UIWindow sendEvent:] + 4114
19 UIKit 0x0000000104ec47b0 -[UIApplication sendEvent:] + 352
20 UIKit 0x00000001056a7adc __dispatchPreprocessedEventFromEventQueue + 2926
21 UIKit 0x000000010569fa3a __handleEventQueue + 1122
22 CoreFoundation 0x00000001076ebc01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
23 CoreFoundation 0x00000001076d10cf __CFRunLoopDoSources0 + 527
24 CoreFoundation 0x00000001076d05ff __CFRunLoopRun + 911
25 CoreFoundation 0x00000001076d0016 CFRunLoopRunSpecific + 406
26 GraphicsServices 0x00000001096fca24 GSEventRunModal + 62
27 UIKit 0x0000000104ea70d4 UIApplicationMain + 159
28 ArduinoHomeKit_bis 0x0000000103fc3ce7 main + 55
29 libdyld.dylib 0x00000001086e565d start + 1
30 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
After click OK this is the code that I try to execute:
#IBAction func tornaAllaLista(_ segue: UIStoryboardSegue){
do {
var vistaDettaglio: AggiungiLuceViewController = segue.source as! AggiungiLuceViewController
if(vistaDettaglio.nuovaLuce != nil && vistaDettaglio.nuovaLuce?.id == 0){
self.listaLuci.append(vistaDettaglio.nuovaLuce!)
self.tabella.reloadData()
}else{
}
} catch let errore {
print("[CDC] problema tornaAllaLista")
print(" Stampo l'errore: \n \(errore) \n")
}
}
EDIT
This is the code that I execute when I click on OK button:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
//se il pulsante cliccato รจ diverso da OK torno indietro
if sender as? NSObject != self.buttonOK{
return
}
let nomeLuce = self.textNomeLuce.text!
let pinArduino = Int16(self.textPinArduino.text!)
let tipoLuce = self.textTipoLuce.text!
if(nomeLuce.characters.count>0){
//ho inserito almeno un carattere
LuciKitCoreDataController.shared.addLuce(descrizione: nomeLuce, pin_arduino: Int(pinArduino!))
self.nuovaLuce = LuciKit()
self.nuovaLuce?.descrizione = nomeLuce
self.nuovaLuce?.pin_arduino = pinArduino!
self.nuovaLuce?.id = 3
}else{
let alert = UIAlertController(title:"Attenzione", message: "Inserire un nome per la Luce", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated:true, completion: nil)
}
}
If I try to execute this line code:
self.nuovaLuce?.descrizione = nomeLuce
I have an error
Pretty sure that this is the offending line:
vistaDettaglio.nuovaLuce?.id == 0
Object stored under novaLuce doesn't contain a method called -id, as it seems to be.
When I clicked my "Sign Up" button after typing my username and password in, my app crashes. I am new to this type of programming and I have no idea why. This is my error:
2015-12-08 08:37:51.477 Scoop[835:19495] -[Scoop.CustomSignUpViewController SignUp:]: unrecognized selector sent to instance 0x7fa383cc8220
2015-12-08 08:37:51.484 Scoop[835:19495] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Scoop.CustomSignUpViewController SignUp:]: unrecognized selector sent to instance 0x7fa383cc8220'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108960f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010a684deb objc_exception_throw + 48
2 CoreFoundation 0x000000010896956d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001088b6eea ___forwarding___ + 970
4 CoreFoundation 0x00000001088b6a98 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010917ee91 -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x00000001092ea4d8 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x00000001092ea7a4 -[UIControl _sendActionsForEvents:withEvent:] + 311
8 UIKit 0x00000001092e98d4 -[UIControl touchesEnded:withEvent:] + 601
9 UIKit 0x00000001091eced1 -[UIWindow _sendTouchesForEvent:] + 835
10 UIKit 0x00000001091edc06 -[UIWindow sendEvent:] + 865
11 UIKit 0x000000010919d2fa -[UIApplication sendEvent:] + 263
12 UIKit 0x0000000109177abf _UIApplicationHandleEventQueue + 6844
13 CoreFoundation 0x000000010888d011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14 CoreFoundation 0x0000000108882f3c __CFRunLoopDoSources0 + 556
15 CoreFoundation 0x00000001088823f3 __CFRunLoopRun + 867
16 CoreFoundation 0x0000000108881e08 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x000000010bdd0ad2 GSEventRunModal + 161
18 UIKit 0x000000010917d30d UIApplicationMain + 171
19 Scoop 0x00000001075e463d main + 109
20 libdyld.dylib 0x000000010b19692d start + 1
21 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
This is my code for my sign up action:
#IBAction func SignUpAction(sender: AnyObject) {
var username = self.usernameField.text
var password = self.passwordField.text
var confirmPassword = self.confirmPasswordField.text
if (username?.characters.count > 4 || password?.characters.count > 5){
var alert = UIAlertView(title: "Oops!", message: "Username must be
greater than 4 & password must be greater than 5.", delegate: self,
cancelButtonTitle: "Okay")
alert.show()
}else if (password?.characters.count !=
confirmPassword?.characters.count){
var alert = UIAlertView(title: "Oops!", message: "Your passwords do
not match. Try again.", delegate: self, cancelButtonTitle: "Okay")
alert.show()
}else {
self.actInd.startAnimating()
var newUser = PFUser()
newUser.username = username
newUser.password = password
newUser.signUpInBackgroundWithBlock({ (succeed, error) -> Void in
self.actInd.stopAnimating()
if ((error) != nil) {
var alert = UIAlertView(title: "Error", message: "\(error)",
delegate: self, cancelButtonTitle: "Okay")
alert.show()
}else {
var alert = UIAlertView(title: "Success!", message: "You
have been signed up for Scoop!", delegate: self, cancelButtonTitle:
"Okay")
alert.show()
}
})
}
}
Rename your method
#IBAction func SignUpAction(sender: AnyObject){
to
#IBAction func SignUp(sender: AnyObject){
To prevent crashes like this you should read the error message carefully, it says:
-[Scoop.CustomSignUpViewController SignUp:]: unrecognized selector sent to instance...
That means that you try to call a method on your view controller which doesn't exist. Often it happens if you misspell a name of method ( you sent SignUp name, but in your view controller SignUpAction)
By the way, it would be better practice, according to guidelines, to name methods starting with lowercase character.