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 butt...

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,6597 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 badges15 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,2684 gold badges26 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,45717 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

4,9741 gold badge34 silver badges49 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,3711 gold badge17 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

4815 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


Aasif Khan

By  | Last Updated on January 11th, 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

  • Make your own app with this Amazing DIY service Appy Pie
  • Virtual Currency [Definition, Pros, Cons, and Popular Cryptocurrencies]
  • 10 Best Todoist Integrations That Will Boost Your Productivity in 2022
  • Workflow Automations & Integrations to help Small Businesses work from home
  • 14 Trending eCommerce Website Templates to Use in 2021
  • How to manage your B2B sales during coronavirus outbreak?
  • An Introduction to Event Management and Marketing
  • How a small business can save up to $100k?
  • How to Make an App Like Tinder in 2022?
  • 9 Best Workout Apps for Runners in 2021

App Builder

Updated on June 1, 2019 by David Ruvinskiy and Chris Ching

Are you getting strange error messages like “Thread 1: signal sigabrt” or “Use of unresolved identifier”?

This handy reference guide will show you what the common causes for these errors are and give you steps to fix them!


TABLE OF CONTENTS

1. Xcode Simulator Errors
– My iPhone simulator looks different?
– My simulator screen is black when the app runs

2. App Runs And Then Crashes
– Finding the error message after a crash
– Unrecognized selector sent to instance
– This class is not key value coding-compliant for the key…
– Unexpectedly found nil while unwrapping an optional value
– Thread 1: signal sigabrt
– Use of unresolved identifier
– Class has no initializers

3. Xcode Errors/App Won’t Run
– Xcode complains that a method of some class doesn’t exist
– Xcode warnings

4. My Xcode Interface Is Different
– Missing panels or views
– Can’t find UIElements in my Storyboard
– Can’t drag UIElements onto my Storyboard

1. Xcode Simulator Errors

My iPhone simulator looks different?

If your iPhone simulator doesn’t look like the one you see me using in my videos, it’s because your iOS simulator is at a different zoom level.

The frame or bezel on the simulator also differs from level to level so if you don’t see an iPhone bezel on your simulator, try changing your zoom level to either “Physical Size,” “Point Accurate,” or “Pixel Accurate” as shown in the screenshot below. By default, the zoom level is “Physical Size.”

You can also hit command + 1-3 on your keyboard as shortcut keys to control the zoom level of your simulator.

My simulator screen is black or white when the app runs

If you run your app and the iOS simulator is showing a black or white screen, I would first wait a little while. Sometimes it can take up to 15 seconds to launch your app initially.

Secondly, I would reset the simulator like I mentioned above and try to run my app again.

If that still doesn’t work, then maybe you have accidentally set some breakpoints which is stopping the app execution.

Run your app, then bring Xcode to the foreground and see if you see something like the below with a green line (representing where execution has halted) stopped at a blue marker (which is a breakpoint):

If you see something like the above screenshot, that means that you’re seeing a black screen because the app execution has stopped. All you need to do is to either remove the breakpoint by clicking the blue marker and dragging it off the gutter (and then re-run your app).

Or you can disable all breakpoints by this menu command in Xcode:

I see this happening a lot for beginners who aren’t aware of what breakpoints are.

Breakpoints are used to halt execution at a certain point so that you can inspect variables and peek into your objects to debug.

You can set breakpoints by clicking the gutter beside a line of code and it’ll add a little blue marker there. So you can see why beginners may accidentally have set breakpoints and not realize it when they run their app!

2. App Runs And Then Crashes

Finding the error message after a crash

When your app runs and then crashes (as soon as it runs or after you click something), you need to know where to find the error message to understand exactly what went wrong.

After the crash, go to Xcode in the lower right hand pane, scroll all the way to the top.

Unrecognized selector sent to instance error

So now that you know how to find the actual error message when your app crashes, the next step is to learn to recognize some of the more common types of messages because they will hint at what’s wrong.

The unrecognized selector error means that somewhere, a method was called on an object and that object didn’t have that method so it crashes. “Selector” is another term for a method.

As you can see in the error message above, it tells you the method that was called was “dealTapped” and the object that it was called on was a ViewController object.

So now you can go back to your code and see where you’re calling the “dealTapped” method and why the object doesn’t have that method.

Check if that method exists in the .swift file of the class and pay attention to the parameters and letter casing to make sure it matches.

If you’re calling a method on a IBOutlet property that is referring to an element in your storyboard, then make sure that the UIElement has its custom class set to the class that has the “dealTapped” method.

This class is not key value coding-compliant for the key

If you’re using Storyboards to build your user interface and you encounter a detailed error similar to this:

*** Terminating app due to uncaught exception ‘NSUnknownKeyException’, reason: ‘[setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key handleButtonClick.’

The actual name of the key (in this case “handleButtonClick”) may be different for you, but this error may indicate that there’s a UIElement in your Storyboard that’s connected to a property which doesn’t exist anymore. This can occur if you connected the UIElement to a property and then removed the property from the .swift file.

In order to fix it, go into your storyboard and right click each element to check the connections to the properties and “break” any connections to properties that don’t exist in your .swift file anymore by clicking the little “x” beside each bad connection.

Unexpectedly found nil while unwrapping an optional value

Another one of the most common errors is the “unexpectedly found nil while unwrapping an optional value” error.

This error usually occurs after attempting to use a nil value as a regular value. For example, if you force unwrap an optional value with the “!” operator since you expect it to contain a non-nil value, receiving this error indicates that the optional value actually contained nil.

In the screenshot below, I attempt to compare the value of str with “CodeWithChris” to see if they are equal. However, I receive this error because str contains nil.

This error can also be caused by attempting to use disconnectedIBOutlet properties. IBOutlet properties are actually implicitly unwrapped optionals, which means that they start off as nil but are expected to contain a value when your app runs. This can cause problems if you disconnect an IBOutlet in your storyboard but still refer to it in your code.

Thread 1: signal sigabrt

This unhelpful error usually appears next to the red highlighted line when Xcode crashes. Because this error does not give you specific information about what’s wrong with your app, I would recommend looking for the detailed error as discussed above.

The signal sigabrt message could be caused for several reasons, including attempting to dequeue a TableView cell with an identifier that does not exist (as seen in the screenshot below) or attempting to perform a segue with an identifier that does not exist.

In these cases, double check to make sure that you have not made any typos when typing out your identifiers. Otherwise, you may have to Google the detailed error message for a better idea of the cause of the problem.

Use of unresolved identifier

You will often see this error if Xcode cannot find the variable or property you are referring to. “Unresolved” means that Xcode couldn’t find something, and “identifier” is another word for a variable, property, function name, etc.

Here are several reasons why you could receive this error:

  1. You made a typo when trying to access a variable or property.

    As you can see in the screenshot above, I declare a variable called name and set it equal to David. On the next line, I attempt to print out name. However, I receive an “unresolved identifier” error because I typed nome instead of name.

  2. You are trying to access a property out of scope.

    Variable scope is something that often confuses beginners. In the screenshot above, I have a function called doWork(). Inside the function, I declare a String constant called doingWork, and I am able to print it inside the function.

    However, if I try to print doingWork outside the doWork function, I receive the “unresolved identifier” error. This is because I can only access doingWork inside the scope of the function.

  3. You have not imported a method or framework where a property is declared.

    You will often receive this error if you forgot to import a library or framework. In order for the code in the screenshot above to work, I need to make sure to import UIKit to get access to arc4random_uniform and UIImage.

Class has no initializers

This is another error that often confuses beginners.

To explain this error, let’s take a look at the screenshot above, specifically at the leftScore and rightScore variables. In order for a class in Swift to be initialized, Xcode needs to guarantee that all of its non-optional properties will also be initialized.

This is the reason why we are seeing the “no initializers” error. Because rightScore does not have an initial value as leftScore does and because the ViewController class does not have an init() method, Xcode cannot guarantee that leftScore will be initialized when the ViewController is.

If you are a beginner, I would recommend two solutions to fixing this error. You can either give rightScore an initial value similar to leftScore, or you can make rightScore optional.

You can also give your view controller class an initializer. However, this is more of an advanced topic since it involves making an instance of your ViewController programmatically.

3. Xcode Errors/App Won’t Run

Xcode complains that a method of some class doesn’t exist

If you run your app and you get some build errors, that means Xcode has detected that the syntax of your code is wrong.

If Xcode is complaining that a specific identifier doesn’t exist, then check that all of your opening curly braces have corresponding closing curly braces.

If you look at the screenshot below, both build errors are caused because of missing curly braces. Can you spot the missing curly brace?

Xcode warnings

Xcode warnings are highlighted in yellow and they won’t stop you from running your app but it’s a good practice to reduce the number of them.

I’ll be illustrating some of the more common ones in the future in this section.

4. My Xcode Interface Is Different

Missing panels or views

If you’re missing some panes in your Xcode interface, you can check the buttons in the upper right corner. They’re used to toggle the main panels.

In the debug/console area, there are also a couple of buttons to toggle the panes in the debug area:

If you’re in Storyboard designer view, there’s a button that many people miss. This button controls the document outline which lists the UI Elements in your storyboard in a tree hierarchy view.

Can’t find UIElements in my Storyboard

If you don’t see the UI elements list in your storyboard view then your library pane may not be visible. See the screenshot below:

Can’t drag UIElements onto my Storyboard

If you drag UI elements onto your storyboard and you can’t add any to your view, then you may be in zoomed out view. When you’re zoomed out in your storyboard, you can’t add any elements into the view. The zoomed out view gives you and overview of your views and allows you to position your controllers on the storyboard.

To get back into zoomed in view, just double click on an empty area on your storyboard and you’ll zoom back in and be able to drag elements onto your views.

Понравилась статья? Поделить с друзьями:
  • Thread 1 fatal error init coder has not been implemented
  • This servers accepts only legit clients go and buy it right now at как исправить
  • Thread 1 fatal error index out of range
  • This server is blocked by mojang lunar client как исправить
  • Thor2 error connection not found