Swift error : signal SIGABRT how to solve it - ios

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?

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.

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:
And The solution was here:
Just scroll up in the output and the error will be revealed.

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.

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

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
Hope this can help you too :)

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.

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.

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

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.

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
}

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.

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.

I had the same problem. In my case I just overwrote the file
GoogleService-Info.plist
on that path:
Platform\ios\YOUR_APP_NAME\Resources\Resources
In my case the files were present without data.

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

Related

Events from storyboard don't reach view controller

(Newbie question) after mucking around with renaming folders/modules, etc. I find that events are no longer triggered. Looking in the story board inspector, all events look to be wired properly.
But no events are triggered in the view controller.
How can this be debugged? Could it be something wrong with the module names, relative paths or anything like that.
Code snippets:
class ViewController: UIViewController, STBackgroundTaskDelegate, MeshViewDelegate, UIGestureRecognizerDelegate, AVCaptureVideoDataOutputSampleBufferDelegate {
viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
// ... more here...
}
Receiving method:
#IBAction func overlayTypeChangedWithSender(_ sender: AnyObject) {
NSLog("Overlay type changed")
showOverlay()
}
You may have forgotten to change the Custom Class in Storyboard or Xcode caches outdated data. Do the following:
Copy the NameOfViewController to the Custom Class field for your viewController in Storyboard.
Clean the project (Product -> Clean)
Clear Derived Data. Here is how.
Restart Xcode
Build & Run
Have you tried connecting another control in one of your problem classes? If you can do that, have a look at the connections inspector for the new control, and earlier ones in the same view - they SHOULD be connected to the same class (of course), but if they are not, you just need to remove the old connection and reconnect

Method name gets changed in storyboard connections inspector

I created a method for a button using Swift 2.3 in Xcode 8. let's say
#IBAction func testAction(sender: UIButton) {
print("\(sender.tag)");
}
but in Connections inspector of storyboard editor it shows as testActionWithSender:, which I know is not the correct method name but I have no problem with that until it crashes with
[TestProject.ViewController testActionWithSender:]: unrecognized selector sent to instance 0x7ff3f3e050e0
on button tap.
So why does the method name changes in Connections inspector and how do I fix it?
By Using this workaround you can add existing action and also can connect multiple buttons to a single action.
I think there is a bug in Xcode8. You can add multiple/Single button to a single action /function by changing sender to _ sender
eg :- Normal Button
#IBAction func huu(sender: UIButton) {
}
You can't add multiple buttons or single button to this action you need to simply change like this and then you can add multiple buttons by using drag and connect from storyboard.
#IBAction func huu(_ sender: UIButton) {
}
After connecting IBOutlets Xcode will show a warning like this :-
To remove this warning simple delete _ sign from the action/function. Make sure that to delete _ after connecting your IBOutlets
Hope that this will gonna help you! :)
I faced the same issue. The only workaround I found is to delete the connection, and drag the button action to a new Action method.
If you link your button to an existing one, it crashes

Connecting IBOutlet in Newly Created .Swift File

I wrote some code in Swift for an iOS app in XCode (7.1.1) and I can't use the drag and drop in the interface builder for the outlet I want to connect. I tried to do it manually too but the outlet didn't show up in the reference collection when I tried to do it.
I did see this answer:
Can't connect IBOutlet in Interface Builder
But this appears to be for Objective-C/older versions of XCode. The way I have it right now is I have my main DataViewController.swift file and then I created a PhotoViewer.swift file (it's just an example so the code doesn't really matter it's pretty simple). I used the following code:
import Foundation
import UIKit
class PhotoViewer: UIViewController {
#IBOutlet weak var viewerButton: UIButton!
func loadPhotoUI() {
viewerButton.setTitle("View Photos", forState: .Normal)
}
}
The viewerButton does not show up as an option and when I open up the story board and try to Ctrl-Click and drag to the file on the right side, it doesn't let me drop it in.
If I try it on the DataViewController.swift file (the one that was there when I started the initial template), it still works.
I'm guessing I just need to change a setting on the new file but I can't seem to figure that out. I basically will be using the classes functions in the DataViewController like:
let photoClass = PhotoViewer()
self.photoClass.loadPhotoUI()
etc etc. I'm just wanting to keep everything super organized.
I'm obviously a bit of a noob at Swift so thanks for the help!
Your ViewController in your Storyboard needs to be linked to your Swift file.
You have to change the Class to "PhotoViewer" in your Identify Inspector in your Storyboard Viewcontroller:

How do I get rid of this Sigabrt error? I've tried Multiple Ways

So I am new to programming on xcode. I just started a week ago but constantly watched coding videos and looked at coding examples. I have very small background with this but am in search for learning so much more about coding.
The Situation
I am working on my app and try to simulate it through an Iphone 5s simulator. I have my main view controller linked to the second view controller by a UIButton. When I press the button, Nothing happens and I recieve a red little warning saying:
class AppDelegate: UIResponder, UIApplicationDelegate {
Next to where it says "UIResponder, it will say "Thread 1: signal SIGABRT" This is how my viewcontroller.swift editor looks like:
//
// ViewController.swift
// QuoteDaily
//
// Created by Jordan Norris on 2/5/16.
// Copyright © 2016 Jordan Norris. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var Button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
What I have done so far
I looked at other post like this and the answers say to get rid of any lingering outlets and unattached things that may be causing this problem, so I get rid of every outlet and connection and start "fresh". The only problem is, When I add a button to go to the second ViewController,"FirstQuestion.swift", it will show the same error.
I also restarted xcode many times and restarted the simulator a lot of times and the same error pops up.
The Question
What I'm asking for is how do I get rid of this error so that I can push this button to bring me to the second view controller?
I have 2 pictures for reference
Assistant text editor for first view controller
View Controller number 1(with the button) and view controller 2(When is your birthday) Also the triggered segues and referencing outlets on the left side
I would greatly appreciate it if someone could help me because I don't feel like giving up on something I just started. Also this community seems like a very friendly one so I'd love to come back to this source for any further help. Thank You.
Select Your second viewController to which the button is pointing and check all the outlets connections you have made by going to Show the connections inspector. Sometimes there are some previously connected outlet or actions names that you may have changed, that may cause crash.
Remove all connections and connect them again by selecting show the assistant editor. Clean the code and run the project again if it helped.

Swift PNChart PNCircleChart with Storyboard

I'm trying to set up a basic PNChart PNCircleChart on my app. I created a UIView in the storyboard and set the class to PNCircleChart. The restoration ID is piechart. I created an outlet in to my view controller that looks like:
#IBOutlet weak var pie: PNCircleChart!
Now I'm trying to build a basic piechart in my viewdidload and I can't figure out how.
pie.backgroundColor = UIColor.greenColor()
pie.setValue(50, forKey: "A")
pie.setValue(50, forKey: "B")
pie.strokeChart()
It is failing with a NSUnkownKeyException error. Any idea how to do this in swift
The NSUnknownKeyException is almost always caused when one of your interface elements was hooked up to a property in your view controller that you then deleted. The property was deleted from the view controller, but the interface builder was never unhooked from that property.
The actual exception message should tell you what "key" it's having trouble finding, which should give you a hint as to which UI element is hooked up wrong.
Once you figure out which key is hooked up wrong, go through your UI elements and right click on each of them. One of them will be hooked up to a property of this name (and it won't exist in your class source code file). You need to either click the X for this connection to delete the connection, or you need to add the property back to your source code file.

Resources