Thread 1 signal sigabrt swift как исправить

I’m just a beginner in Swift coding. My idea is quite simple which is an app with two buttons. When clicked, a textfield will change its text.
In the Main.StoryBoard, I add a textfield and two buttons.
In ViewController.swift file. I write as this:

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var textfield: UITextField!
    @IBOutlet weak var button: UIButton!
    @IBOutlet weak var button2: UIButton!

    @IBAction func action1(_ sender: UIButton) {
        textfield.text="you just clicked on button1"
    }
    @IBAction func action2(_ sender: UIButton) {
        textfield.text="you just clicked on button2"
    }
}

It is supposed to be all right. However, an error appears which shows:

thread1:signal SIGABRT

in file AppDelegate.swift line:

class AppDelegate: UIResponder, UIApplicationDelegate

What is wrong with my code?

saurabh's user avatar

saurabh

6,6877 gold badges42 silver badges62 bronze badges

asked Apr 21, 2017 at 15:23

chucklai's user avatar

4

You get a SIGABRT error whenever you have a disconnected outlet. Click on your view controller in the storyboard and go to connections in the side panel (the arrow symbol). See if you have an extra outlet there, a duplicate, or an extra one that’s not connected. If it’s not that then maybe you haven’t connected your outlets to your code correctly.

Just remember that SIGABRT happens when you are trying to call an outlet (button, view, textfield, etc) that isn’t there.

answered Apr 21, 2017 at 23:06

Andy Lebowitz's user avatar

Andy LebowitzAndy Lebowitz

1,4412 gold badges16 silver badges23 bronze badges

7

For me it wasn’t an outlet. I solved the problem by going to the error And reading what it said. (Also Noob..)

This was the error:

enter image description here

And The solution was here:
enter image description here

Just scroll up in the output and the error will be revealed.

answered Jan 10, 2018 at 18:33

dangalg's user avatar

dangalgdangalg

6,3384 gold badges27 silver badges37 bronze badges

1

To solve the problem, first clean the project and then rebuild.

To clean the project, go to MenuBar: Product -> Clean

Then to rebuild the project, just click the Run button as usual.

donjuedo's user avatar

donjuedo

2,47517 silver badges28 bronze badges

answered Jan 3, 2018 at 6:47

Marwan Salim's user avatar

0

A common reason for this type of error is that you might have changed the name of your IBOutlet or IBAction you can simply check this by going to source code.

Click on the main.storyboard and then select open as
and then select source code
enter image description here

source code will open

and then check whether there is the name of the iboutlet or ibaction that you have changed , if there is then select the part and delete it and then again create iboutlet or ibaction.
This should resolve your problem

Mohammed Julfikar Ali Mahbub's user avatar

answered Jan 31, 2018 at 14:21

Anshu Shahi's user avatar

Anshu ShahiAnshu Shahi

1512 silver badges4 bronze badges

In my case I wasn’t getting error just the crash in the AppDelegate and I had to uncheck the next option: OS_ACTIVITY_MODE then I could get the real crash reason in my .xib file

enter image description here

Hope this can help you too :)

answered Sep 6, 2018 at 14:15

GOrozco58's user avatar

GOrozco58GOrozco58

1,16212 silver badges10 bronze badges

I had the same problem. I made a button in the storyboard and connected it to the ViewController, and then later on deleted the button. So the connection was still there, but the button was not, and so I got the same error as you.

To Fix:

Go to the connection inspector (the arrow in the top right corner, in your storyboard), and delete any unused connections.

answered Jan 29, 2018 at 15:56

Bijan Negari's user avatar

1

If you run into this in Xcode 10 you will have to clean before build. Or, switch to the legacy build system. File -> Workspace Settings… -> Build System: Legacy Build System.

answered Oct 18, 2018 at 22:06

Jon Vogel's user avatar

Jon VogelJon Vogel

5,0341 gold badge37 silver badges52 bronze badges

This is a very common error and can happen for multiple reasons. The most common is when an IBOUTLET/IBACTION connected to a view controller in the storyboard is deleted from the swift file but not from the storyboard. If this is not the case, use the log in the bottom toolbar to find out what the error is and diagnose it. You can use breakpoints and debugging to aid you in finding the error.

To find out how to fix the error please use this article that I found on Google: https://rayaans.com/fixing-the-notorious-sigabrt-error-in-xcode

answered Jan 12, 2020 at 18:48

Rayaan Siddiqui's user avatar

In my case there was no log whatsoever.

My mistake was to push a view controller in a navigation stack that was already part of the navigation stack.

answered Jun 27, 2018 at 8:35

Xavier Lowmiller's user avatar

Xavier LowmillerXavier Lowmiller

1,3811 gold badge15 silver badges23 bronze badges

Sometimes it also happens when the function need to be executed in main thread only, so you can fix it by assigning it to the main thread as follows :-

DispatchQueue.main.async{
  your code here
}

answered Oct 26, 2018 at 6:07

Bishnu Das's user avatar

Bishnu DasBishnu Das

1612 silver badges14 bronze badges

For me, This error was because i had a prepare segue step that wasn’t applicable to the segue that was being done.

long story:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        let gosetup = segue.destination as! Update
        gosetup.wherefrom = updatestring

    }

This was being done to all segue when it was only for one. So i create a boolean and placed the gosetup inside it.

answered Mar 8, 2019 at 23:00

JonesJr876's user avatar

In my case, I was using RxSwift for performing search.

I had extensively kept using a shared instance of a particular class inside the onNext method, which probably made it inaccessible (Mutex).

Make sure that such instances are handled carefully only when absolutely necessary.

In my case, I made use of a couple of variables beforehand to safely (and sequentially) store the return values of the shared instance’s methods, and reused them inside onNext block.

answered Nov 11, 2019 at 16:36

Revanth Kausikan's user avatar

I had the same problem. In my case I just overwrote the file

GoogleService-Info.plist

on that path:

PlatformiosYOUR_APP_NAMEResourcesResources

In my case the files were present without data.

Abhinav Kinagi's user avatar

answered Nov 16, 2019 at 6:56

Supriya's user avatar

SupriyaSupriya

4715 silver badges5 bronze badges

If this crash occurs when accessing a view controller within a package you may have to remove the Class and Storyboard ID from the view controller within the package and then add them again, run the project and the view controller should be found

answered May 27, 2022 at 11:15

Adam Smith's user avatar

Adam SmithAdam Smith

1791 silver badge3 bronze badges

Back to blog


Aasif Khan

By  | Last Updated on January 14th, 2023 8:30 am | 4-min read

One minute your iOS app runs fine in Xcode, and the next it has hopelessly crashed with a cryptic SIGABRT error. What’s going on!?

In this app development tutorial you’ll learn:

  • How to solve the “Signal SIGABRT” error in Xcode
  • How to use some of the debugging tools in Xcode
  • What SIGABRT stands for, and what its causes are
  • 3 approaches to find the root cause of SIGABRT

The error SIGABRT stands for “signal abort”. It’s a signal that’s sent by iOS – the operating system – to a running app, which will immediately quit the app because of a runtime error. It essentially means your app has crashed…

In the screenshot you see a few things:

  • On the left you see a list of threads that ran when the app crashed. You see that the thread that caused the crash is the main thread, or “Thread 1”.
  • In the editor we see that dreaded Thread 1: signal SIGABRT error. It has highlighted line 12 in the editor, the class definition of AppDelegate.
  • At the bottom you see helpful debug output. In this case, you get a stacktrace and a cryptic error message about not being “key value coding-compliant.”

The problem with the SIGABRT error is that it’s too generic. Xcode is basically saying: “Look, your app has crashed, that’s all we know.” In most cases of the SIGABRT error, you get little information about what’s caused the error.

Before we go on, let’s discuss a few misconceptions and common pitfalls of SIGABRT:

  • The SIGABRT error usually has nothing to do with the AppDelegate class declaration, even though it highlights that line in Xcode. The line is highlighted because it’s the first line of code of your app. Don’t waste your time looking in the AppDelegate class, unless you’re absolutely certain the bug is in there.
  • The stacktrace is a list of function calls that lead up to the app crashing. That doesn’t mean the line of code that caused the error is anywhere in the stacktrace. It sometimes is, but in other cases, the stacktrace merely leads to the code that choked on a value you set elsewhere in your own code.
  • Don’t stare yourself blind on a SIGABRT error. There’s a rational, logical cause for the error. It’s probably a bug in your own code, and there’s nothing wrong with that. Apps aren’t magic, no one is out to get you, and bugs never appear out of the blue. Don’t frustrate yourself with thoughts like “It ran fine yesterday!” – it always does, and now it doesn’t!

Now that we’ve established a baseline, let’s get to the first cause of SIGABRT.

A common cause of “Signal SIGABRT” is a typo or bug in your outlets. Here’s what happened:

  • You created a new view controller in Interface Builder, and set it up with a few UI elements like buttons and labels
  • You connected these UI elements to your code by using outlet properties, which creates a connection between a property of your view controller and the UI element in Interface Builder
  • At one point you changed the name of the initial outlet property and your app started crashing with a SIGABRT error

When you’re using Interface Builder to create a view controller, your app will use the XIB file to generate the view controller’s UI when your app runs (roughly speaking). At this point it will also connect outlets from the XIB to properties of the view controller class.

If you’ve changed the name of an outlet property, your app can’t find it anymore. And because of that it will throw an exception. What’s causing the SIGABRT error, is not handling that exception.

Here’s what that looks like in Xcode:

See what’s happening? The property is called otherButton, but the outlet is still called button. At one point we changed the outlet – because the new name is better – and confused the app, which made it crash.

At the top of the stacktrace we also spot another clue:

Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[<…> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key button.
What does that mean? The app is telling us at this point that the view controller is not key value coding compliant for the key button. This means that it cannot find the button property on the view controller. And that’s true, because we’ve renamed it.

iOS uses a mechanism called key value coding to inspect the properties a view controller has, so it can use those properties to reference UI elements it has created based on the XIB.

How do you solve the bug at this point? You can use 2 approaches:

  1. You rename the property back to its original name
  2. You remove the outlet connection in Interface Builder, and reconnect it using the new outlet property name

Quick Tip: Just as a changed @IBOutlet can cause “Thread 1: signal SIGABRT”, so can erroneously changing the name of an action, i.e. with @IBAction, cause the SIGABRT error.

In many cases Xcode won’t show you any helpful error messages for a SIGABRT crash. When that happens, it’s useful to know a few debugging commands, such as bt.

Xcode has an integrated debugging environment called LLDB. It’s what you see at the bottom of Xcode when your app runs, the Console or debug output area. You often see debug messages here, but did you know you can also use it to input commands?

Next time your app crashes, try typing help in LLDB. Like this:

You’ll see that many of the LLDB commands directly correspond to actions you can take with the debugger, such as setting breakpoints, stepping over lines of code, and inspecting runtime values.

One command is particularly useful. You can type in bt to see the current call stack (also called “backtrace” or “stacktrace”). This is a list of all functions that ran up to the current crash. This trace typically includes the function that caused a bug.

Here, check out the stacktrace of a typical Index out of range error. In the screenshot below, we’ve deliberately caused that error by getting index 99 from an array that only has 4 items. When the app crashes, bt can tell us which line of code caused the error.

Can you spot the following information in the stacktrace?

  • The offending code is at line 21 of ViewController.swift, inside the viewDidLoad() function
  • You can even see that we used the subscript “getter” of Array
  • Before the crash a whole bunch of view controller-related function calls were made

Based on the information we got with bt, we can find the offending line in our code and fix it. Xcode already helped us in this case, by highlighting the error in the editor. In some scenarios you won’t have such luck, and then it can be helpful to use the bt command.

One last thing: you can inspect values at runtime with the print command. In the above scenario, typing print names would have produced this output:

([String]) $R0 = 4 values {
[0] = “Ford”
[1] = “Arthur”
[2] = “Zaphod”
[3] = “Trillian”
}

For printing complex objects, use po. Awesome!

Keep in mind that a stacktrace runs outside-in. The bottom of the stack trace shows top-level function calls, and the higher up the stack you go, the deeper the calls go in. The latest, most recent, deepest-level call is at the top of the stack.

An exception breakpoint is triggered whenever an exception occurs in your code. Instead of specifying on which line the breakpoint is triggered, you instruct the debugger to halt code execution for exceptions.

Exception breakpoints are useful for inspecting the code when an exception occurs. You can see which line of code threw the exception, and you can inspect values in your code at that point. Some exceptions are caused by bugs or invalid states of your app, so exception breakpoints are useful for finding and fixing those bugs.

Here’s how you can set an exception breakpoint:

  1. Go to the Breakpoint navigator in Xcode, by using the tabs on the left
  2. Click on the bottom-left +-button and choose Exception Breakpoint
  3. Leave the default settings as-is (although they’re helpful to customize)
  4. Run your code

When an exception is thrown, execution of your app halts. You can now use the debugger to inspect values, step through the code, and use LLDB commands. When possible, Xcode will take you to the line of code that caused the exception.

Keep in mind that an exception doesn’t necessarily crash your app! So, whenever the exception breakpoint is enabled, and an exception occurs, your app is halted. Halting code with a breakpoint isn’t the same as an app crash, so don’t let that confuse you.

For example, an exception breakpoint will get triggered by an Unsatisfied constraints exception, but that won’t crash your app. Use the exception breakpoint to gather extra information for the SIGABRT crash, and then disable it once you’ve solved the bug (until it’s needed again).

The SIGABRT error is quite cryptic, and can prove difficult to solve. Why can’t Xcode just give helpful error messages? Well, that’s a good question…

The short answer is that there are so many moving parts in iOS development that Xcode can’t always determine the cause of a crash. Xcode doesn’t know that you erroneously changed the name of an outlet. It only knows that in connecting the outlet, some code was invoked, and that caused an exception.

This means you’ll always see an error that’s as close to the root cause as possible. The best you can do is make lots of mistakes, decrypt lots of error messages, and get to know them better. And what you’ve learned in this tutorial, is how to find and solve the SIGABRT error!

Create Your App Now

Related Articles

  • How to recall an email in Outlook? [Unsend emails in Outlook]
  • How An App Can Help Healthcare Industry Grow Its Customer Base and Revenue
  • Make your own Radio App with Appy Pie’s Radio app builder
  • Key Web Design Principles to Follow in 2022-23
  • How To Use Apple’s Developer Documentation for Fun and Profit
  • Mobile Banking, Apps, & Artificial Intelligence (AI): Evolution of the Banking Services
  • Best Auto Loan Calculator – Calculate Your Car Loan EMI Payments
  • 11 Effective Ways to Use Instagram Carousel Posts
  • Things To Know While Calculating The Budget Of Hiring A Mobile App Developer
  • Mobile Website Or Mobile App – Which Must You Build First?

App Builder

Начал делать впервые приложение по гайду, компилирую его, тестирую — вылезает ошибка

class AppDelegate: UIResponder, UIApplicationDelegate {

«Thread 1: signal SIGABRT» и приложение даже не открывается (что в общем то не странно).
Приложение для расчета индекса массы тела. Окна задал, связь с ними задал.

//
//  FirstViewController.swift
//  Mass App
//
//  Created by *** on 30.08.16.
//  Copyright © 2016 ***. All rights reserved.
//

import UIKit

class FirstViewController: UIViewController {
    
    
    
    @IBOutlet weak var ageTextField: UITextField!
    @IBOutlet weak var heightTextField: UITextField!
    @IBOutlet weak var weightTextField: UITextField!
    @IBOutlet weak var sexSegmentedControl: UISegmentedControl!
    @IBOutlet weak var activitySegmentedControl: UISegmentedControl!
    @IBOutlet weak var resultsLabel: UILabel!
    @IBAction func calculateTapped(sender: AnyObject)
    {
        weak var activitySegmentedControl: UISegmentedControl!
        func calculateTapped(sender: AnyObject) {
            var bmr: Double = 0
            var bmi: Double = 0
            
            if let age = Int(ageTextField.text!) {
                if let height = Int(heightTextField.text!) {
                    if let weight = Int(weightTextField.text!) {
                        switch sexSegmentedControl.selectedSegmentIndex {
                        case 0:
                            bmr = 88.362 + 13.397 * Double(weight) + 4.799 * Double(height) - 5.677 * Double(age)
                        case 1:
                            bmr = 447.593 + 9.247 * Double(weight) + 3.098 * Double(height) - 4.330 * Double(age)
                        default:
                            bmr = 0
                        }
                        bmi = Double(weight) / pow(Double(height) / 100, 2)
                    }
                }
            }
            
            let factor = [1.375, 1.55, 1.725, 1.9]
            let selectedFactor = factor[activitySegmentedControl.selectedSegmentIndex]
            bmr *= selectedFactor
            resultsLabel.text? = "Вы должны потреблять (Int(bmr)) килокалорий для поддержания веса.nИндекс массы тела (Int(bmi))."
            
            UIApplication.sharedApplication().keyWindow!.endEditing(true)
            
        }
        
    }
    
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
}

Ошибка:

2016-08-30 19:05:45.409 Mass App[4618:118258] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Mass_App.FirstViewController 0x7c88dbc0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key activityTextField.'

Предполагаю что ошибка в том что я до этого вместо activitySegmentedControl писал activityTextField.
Где то это осталось и не дает запуску? Или что?..

Need a bit of help as well. Got the same thread1 sigabrt error. Hope you can help! Here is my code —

import UIKit

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

/

return true

}

func applicationWillResignActive(application: UIApplication) {

/

/

}

func applicationDidEnterBackground(application: UIApplication) {

/

/

}

func applicationWillEnterForeground(application: UIApplication) {

/

}

func applicationDidBecomeActive(application: UIApplication) {

/

}

func applicationWillTerminate(application: UIApplication) {

/

}

}

and Here is my error message —

2016-05-07 20:17:48.053 User-Pwd 2[58970:364513] -[User_Pwd_2.LoginVC textUsername:]: unrecognized selector sent to instance 0x7fd661e19f00

2016-05-07 20:17:48.060 User-Pwd 2[58970:364513] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[User_Pwd_2.LoginVC textUsername:]: unrecognized selector sent to instance 0x7fd661e19f00’

*** First throw call stack:

(

0 CoreFoundation 0x00000001051d2d85 __exceptionPreprocess + 165

1 libobjc.A.dylib 0x0000000106f76deb objc_exception_throw + 48

2 CoreFoundation 0x00000001051dbd3d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205

3 CoreFoundation 0x0000000105121cfa ___forwarding___ + 970

4 CoreFoundation 0x00000001051218a8 _CF_forwarding_prep_0 + 120

5 UIKit 0x00000001059fca8d -[UIApplication sendAction:to:from:forEvent:] + 92

6 UIKit 0x0000000105b6fe67 -[UIControl sendAction:to:forEvent:] + 67

7 UIKit 0x0000000105b70143 -[UIControl _sendActionsForEvents:withEvent:] + 327

8 UIKit 0x00000001063f96c5 -[UITextField _resignFirstResponder] + 298

9 UIKit 0x0000000105c0ea1a -[UIResponder _finishResignFirstResponder] + 292

10 UIKit 0x00000001063f94ef -[UITextField _finishResignFirstResponder] + 49

11 UIKit 0x0000000105c0eac9 -[UIResponder resignFirstResponder] + 140

12 UIKit 0x00000001063f93bc -[UITextField resignFirstResponder] + 136

13 UIKit 0x0000000105c0e777 -[UIResponder becomeFirstResponder] + 362

14 UIKit 0x0000000105aa4151 -[UIView(Hierarchy) becomeFirstResponder] + 138

15 UIKit 0x00000001063f8186 -[UITextField becomeFirstResponder] + 51

16 UIKit 0x0000000105efc6db -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 287

17 UIKit 0x0000000105f0019a -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 3817

18 UIKit 0x0000000105ef2b28 _UIGestureRecognizerSendTargetActions + 153

19 UIKit 0x0000000105eef19a _UIGestureRecognizerSendActions + 162

20 UIKit 0x0000000105eed197 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 843

21 UIKit 0x0000000105ef5655 ___UIGestureRecognizerUpdate_block_invoke898 + 79

22 UIKit 0x0000000105ef54f3 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 342

23 UIKit 0x0000000105ee2e75 _UIGestureRecognizerUpdate + 2634

24 UIKit 0x0000000105a6f48e -[UIWindow _sendGesturesForEvent:] + 1137

25 UIKit 0x0000000105a706c4 -[UIWindow sendEvent:] + 849

26 UIKit 0x0000000105a1bdc6 -[UIApplication sendEvent:] + 263

27 UIKit 0x00000001059f5553 _UIApplicationHandleEventQueue + 6660

28 CoreFoundation 0x00000001050f8301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17

29 CoreFoundation 0x00000001050ee22c __CFRunLoopDoSources0 + 556

30 CoreFoundation 0x00000001050ed6e3 __CFRunLoopRun + 867

31 CoreFoundation 0x00000001050ed0f8 CFRunLoopRunSpecific + 488

32 GraphicsServices 0x0000000109868ad2 GSEventRunModal + 161

33 UIKit 0x00000001059faf09 UIApplicationMain + 171

34 User-Pwd 2 0x0000000104fe76d2 main + 114

35 libdyld.dylib 0x0000000107a3a92d start + 1

)

libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb)

Понравилась статья? Поделить с друзьями:
  • Как составить дополнительное соглашение об изменении фамилии
  • Как найти матрицу смежности для данного графа
  • Как найти собственника теплотрассы
  • Как найти месяц по номеру недели
  • Как найти фильмы на немецком языке