All IB outlets seems to have disconnected and app crashes (Xcode) - swift

So I'm having a problem with one of my Xcode projects: It seems like all my IB outlets have disconnected (all I see is the empty circle without the dot in the middle next to the line of code, please see the picture).
empty / hollow circles indicating IB outlets aren't connected
All the IB actions seems to be working regardless, with the exception of one. When I try to tap it, my app crashes and I receive the following error message:
"libc++abi.dylib: terminating with uncaught exception of type NSException"
Also the error seems to be located in the AppDelegate file:
Error message in AppDelegate.swift
Does anyone have any idea what's going on here? It has been a while (a few weeks) since I last worked on this project, if that's at all relevant.

Ignore the unfilled circles; they are not causing a problem.
The crash when you tap is not because of an IBOutlet. It is because that object's IBAction (not shown in your screen shot). That is what you need to work on.

First check all Objects IBAction and IBOutlet or reconnect them. Sometime unfilled circles misguide you.
For better compilation you should have an exception handler in the app. Try below link:
https://www.raywenderlich.com/152276/intermediate-debugging-xcode-8
This will help you to find exact place where you are getting issue.
hope this helps.

Related

Message sent to deallocated instance on device only

I'm at a complete loss with a memory bug. This issue only happens on the device and not the simulator. It also only happens when the app is loaded for the first time on the device. If I close the app and relaunch it the issue does not preset itself. This is the error I'm getting
-[CFString retain]: message sent to deallocated instance 0xfd5a2f0
I've tried everything to attempt to figure out what the released string is. Please help me figure out what the released object is when running on the device and not the simulator! Thanks in advance!
UPDATE:
I still do not have a solution but I have confirmed the app will crash consistently on the line of code where I set a frame and the above error shows. If I comment this code out the app will pass this point but may crash at other strange spots. I can't even begin to determine where the crash is originating.
CGRect frame = CGRectMake(27, 96, 265.0, 50.0);
someAcct.frame = frame;
I'm so confused by this since this is not a string. Any ideas?
UPDATE 2: This issue is directly related to the NSUser Defaults being synchronized. This seems pretty random but this is causing the issue. Any Help?
UPDATE 3: The problem has been solved as of a week ago. This was in fact due to a string being inaccessible. A string was passed to a method, that method then did work and passed data to another method and so on. Until finally the data was to be written to user defaults and a local plist contained within the documents folder. All of a sudden the app would crash at very strange places like the above consistently even though those places had nothing to do with a string. I was baffled and after playing with it for a very long time I decided to head over to the .h file and go through each string one at a time by making sure each were synthesized in the .m file and that self.stringName was applied throughout the .m file. After spending an hour on this I finally found the string that was to blame and the issue is now resolved. Using self.stringName allows the memory to be found and avoids these obscure and highly confusing application crashes. Thanks to everyone for all of the suggestions and tips!
To help you with tracing it down, could you try putting NSLog at the start of your didFinishLaunching() method, somewhere in the middle and at the of the didFinishLaunching().
Then also could you push a NSLog in the viewDidLoad() of the first view controller your app shows. For example, if you're using a tab bar interface, then a NSLog in the first tab's root view controller.
You can use NSLog(#"step 1"), NSLog(#"step 2"), NSLog(#"step 3") ... to organise the output so you know where the code managed to reach up to before it crash, rather than NSLog(#"I am here").
The problem is of retain count. Refer mememory management and check u r not missing something.
Don't forget to turn on NSZombieEnabled.
One reason can be due to the iOS compatibility.Check if your device and the simulator are using the same iOS.Try working the simulator on the same version of OS as your device and change the release of the string accordingly.

xcode4 with SDK 4.3 App working in sim but crashes on device, how is that possible?

I'm testing my app in the sim with SDK 4.3, My device is iPhone 4 with OS 4.3.3, when running the app on the sim every things is working, no errors and nothing, but on the device every thing crashes with the runtime error: "Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key addButton"
I can not find the problem in any xib file. I used to have this outlet, but not any more, not in the class and not in the xib (or maybe i am missing it, but i looked of many many hours for it) and the sim is getting it that i have changed the files but the device does not...
UPDATE: *maybe this would help. I decided to test my theory and removed (deleted) the MainWindox.xib file. compiled and got the same results...On the sim every things worked (WIERD AS IS) and in the device crashes.... The first part tells me that when the Xcode does the link and build, It builds from a deferent directory then the one that the project in... It is as weird as it can get in my eyes.... Any one has a thought about that? I think that when i will fix this every thing else will work just fine....*
What can i do?
Thank you very much,
Erez
There would most probably be a viewcontroller name just above the above error. Open the xib of that viewcontroller and check all buttons in that xib, and check the outlets of each of them. I assume you have forget to remove the outlet connection from one of the buttons.
If you cannot spot out the viewcontroller that has the problem, you need to check all xib files. Also, as alexJones mentioned, please check the capitalization of outlets as the device is case sensitive where the simulator is not.
You might had an outlet "addButton" connected to a button in XIB.
Later you might have removed "addButton" from code, but forgot to remove the connection in XIB.
If you open XIB, right click the "File's owner", you can see "addButton" in red color. Click "x" button to remove it. Then build the code and run on your iphone. It must work now.
Also clean your code, remove the app from your device before running on the device.
I've found the solution, the problem was exactly what i said, The XCode went to a wrong build somewhere, I don't know where and what happen, but it didn't go to the new build.... created a new project, copied all the files and then just changed the delegate and what needed and every thing is working, I am guessing it is a BUG, a very annoying one, but still a bug with XCode 4.
Thank you all,
Erez
Before going to such extremes as copying your project ... try cleaning your target sim and device first, then building from scratch. In effect i believe that is what you achieved by creating a new project.
I had the same problem too, would build and execute in the simulator but crash on my iPhone. The solution turned out to be improper case of a nib name in interface builder. detailView instead of the actual nib name DetailView. Great advice, thanks!

App Crashes on Opening

I have an app that keeps crashing as soon as it starts. Not sure why. I have image views and buttons in the main xib file. The main xib file is not mainwindow, it is firstview, so i changed it in the plist to the firstview. There may be something wrong with the xib file for firstview but it only has buttons and images and a view in the back. There are no warnings or errors when I run it, just Debugging Terminated when it crashes.
To Debug a crash problem, especially on a small application, do a binary search on removing functionality and adding it back in until you find the smallest thing that when removed makes the crash go away, and when added back in causes the crash. Sometimes this bottom-up search approach is easier than the top-down analytical approach to finding what is the problem. Then when you know what is causing the problem, it's generally much easier to focus on why it is causing a problem.
What's the very last change you made before your app started crashing? That's the one that caused your problem. If you made a lot of changes at once before running your app to test them, now you know what that's a Very Bad Idea (tm)... :-(
You probably want to switch it back to mainWindow, and then add the view as a subview in the app delegate did finish launching. also, you may want to set a break point on obj_c_exception_throw.

UITextView delegates problem

I am trying to access the UITextView delegates and have a problem
I have a UIViewController with the UITextViewDelegate protocol and a Nib containing the textView.
If I set the delegate inside viewDidLoad like "textView.delegate = self" and I touch the textView, the app crashes without logging errors.
If I start editing the textView with code like "[textView becomeFirstResponder]" all delegates get called.
When I set the delegate in the Nib creating a connection between the textView and the File's owner and deleting "textView.delegate = self" also no delegates get called.
What am I doing wrong here?
Regards,
Elias
It's not easy to help you without more description, posted code or a xib file.
You say application crashes without any logging errors - well, do you mean that there's no output in console's window ? That is normal, for an app that has crashed.
Anyway, you should be able to get the stack-trace to figure out where approximately the application has crashed. Open the debugger (⇧⌘Y), and see the position. That should give you an idea of what went wrong.
Here you can see an example of such debugger session (after EXC_BAD_CRASH):
First two lines doesn't give us much information, but later on we can see that application has crashed while loading user interface from a NIB file. Well, usually the only code that executes during such load are awakeFromNib methods - it's up to you to find a problem along those lines.
Often top of code's execution doesn't make any sense - for example you might see your ViewController method somewhere, but the top few function calls (those where the code crashed) are located in methods/classes which you never call in your code. In most cases that is a sign of wrong memory de-/allocation. What might happened is that you forgot to retain some of your objects, it has already been released, but you are still keeping reference (a pointer) to its memory. Because that memory has been in fact freed, another object took its place later on, usually some Apple's internal object you've never heard about. Later on your code tries to message your poor object but it sends a message to something completely different. BUMMER! That's how you get those crashes and strange stack traces.
To fix the kind of problem I've just described you can use Instruments and its Zombies instrument. Unfortunately you can't start Zombies from within Xcode, you need to start Instruments standalone, then choose the Zombies under iPhone Simulator/Memory, then Choose Target from the toolbar, you should see your application in there, or be able to navigate to it on filesystem.
What Zombies instrument does is that it never really frees memory after objects are deallocated. Instead, it will mutate those objects into NSZombie class. That class intercepts all calls to itself, and informs you when some code is trying to send a message to it.
This is how such Instruments session looks like (this is the same crash as seen in debugger above):
In the table you can see that we're trying to message UIScrollView that has already been deallocated. You can as well see the whole history of retain/release calls to this particular object. That way you can find a missing retain or wrong release/autorelease.
Remember - Zombies Instruments can only be used with Simulator, because there's not enough memory on the real device to keep all those memory blocks.
Hopefully I could help you with further analysis of your problem.

strange error iPhone/iPad

So I have a table view that contains a bunch of data. The user can navigate down, browse edit, etc. However when they edit and delete a row, and then navigate back via the nav controller, sometimes (not all the time) the app crashes throwing this error:
-[CALayer resourceType]: unrecognized selector sent to instance: **********
does anyone know what could be causing this error? I can't seem to isolate the cases where this happens, it seems random. The data for this is coming from an array. Not sure if that makes a difference. Thanks in advance!
Must likely, you are over-releasing an object or releasing an object too soon (or not retaining an object).
Turn on zombie detection and try to reproduce the crash. (Instruments has a zombie detection mode or search Google for NSZombieEnabled).