IBOutlets in Swift are nil

xib iboutlet nil swift
iboutlet nil awakefromnib
iboutlet unexpectedly found nil
tableview is nil swift
iboutlet uiview is nil
uitableviewcell outlets nil
uicollectionviewcell ( @iboutlet nil)
instantiateviewcontroller iboutlet nil

(Developing on OSX 10.9, Xcode 6.1b)

If I declare IBOutlets in my AppController, everything is fine. I instantiate an object in InterfaceBuilder, drag it across to form an outlet, and by the time I have reached applicationDidFinishLaunching, my IBOutlets are populated and everything is great.

If I go a step further in abstraction and instantiate a custom controller object in InterfaceBuilder (a subclass of NSObject), and declare one of my objects as an IBOutlet in that class, they're nil, each and every one.

I can set the connection just fine, IB seems convinced it exists, the 'referenced outlets' list is correct, but it doesn't take, and I haven't been able to find anything in the documentation beyond

It is implicitly unwrapped because after your class is initialized from a storyboard or xib file, you can assume that the outlet has been connected.

Well, I was assuming that.

All of my code is boilerplate Xcode offerings:

@IBOutlet weak var sceneController: NSArrayController!

and I've checked and double-checked and triple-checked the connections. I've looked at dozens of iOS tutorials (although I cannot find the equivalent for OSX) all of which seems to be variations on the theme of 'yes, you can totally declare an outlet in a file other than the AppController, just make sure that every involved instance exists'.

(At the time of writing, the 'mac' documentation uses examples featuring UIButton etc.)

I'm out of ideas. It's obvious that the connection is not formed, presumably because the objects are instantiated in an order other than 'controller class first, IBOutlets later', but how can I force this connection?

@IBOutlet weak var sceneController: NSArrayController!

The weak keyword is your problem. If, after the system finishes decoding your nib, nothing else references the NSArrayController, then the system will immediately set the outlet to nil and deallocate the NSArrayController.

Try removing the weak keyword from your outlets.

UPDATE

Add this code:

@IBOutlet var sceneController: NSArrayController! {
    didSet {
        NSLog("sceneController set to %@", sceneController);
    }
}

What's the output? Put a breakpoint on the NSLog. What's the stack trace when it's hit? Is it hit repeatedly?

IBOutlet is nil, but it is connect…, IBOutlet is nil, but it is connected in storyboard - fatal error: unexpectedly found nil while unwrapping an Optional value. hi,. I just made uiview in one� Using Swift 1.1 and Xcode 6.2. I have a UIStoryboard containing a singular, custom UIViewController subclass. On it, I have an @IBOutlet connection of type UIView from that controller to a UIView subclass on the storyboard. I also have similar outlets for subviews of that view. See figure A. But at run time, these properties are nil (Figure B).

I had a similar problem

I have a button that takes me from one view controller to another. Inside the event handler for this button I was trying to set values for some of the GUI components in the second view. Unfortunately, I was getting a nil value for those components.

The solution was to wait until the button handler exited then make changes to the GUI components in the second view (try the viewDidLoad() function on the second view controller). Presumably those GUI components were not allocated until I left the handler and switched views.

yuen helbig

Why an IBOutlet in your UITableViewCell is suddenly a nil, Why an IBOutlet in your UITableViewCell is suddenly a nil Some time ago I've noticed a strange behaviour of one of IBOutlets in my UITableViewCell Swift — Creating a Custom View From a XIB (Updated for Swift 5). This question already has an answer here: IBOutlet is nil, but it is connected in storyboard, Swift 29 answers I'm pulling out what little hair I have left!

I had the issue when I was configuring the corner radius of the buttons in viewWillAppear. Moving this part to viewDidLoad solved the issue.

Is it normal for IBOutlet variables to be nil in Swift while the , By the time viewDidLoad is called, all of the IBOutlets—assuming they're actually connected to something in the corresponding IB file—should be non-nil. Extra table cells when UITableViewController is embedded into a Container in a UIViewController. ios,swift,uitableview,uiviewcontroller. You just need to add this to your code in viewDidLoad. self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero]; EDIT: sorry i was written in objective -c here is in swift. self.tableView.tableFooterView = UIView(frame:CGRectZero) The

Crash due to IBOutlets as nil, viewController resolved in tableView , Crash due to IBOutlets as nil, viewController resolved in EmployeesViewController.swift override func tableView(_ tableView: UITableView,� Optionals In Swift: The Ultimate Guide – LearnAppMaking, In Swift, Optional is a generic type that can contain a value (of any kind), or no value at all. In many Fatal error: Unexpectedly found nil while unwrapping an Optional value IBOutlets, in particular, are usually implicitly unwrapped optionals.

Fatal Error found nil IBOutlets – Mom In Tech, Fatal error: Unexpectedly found nil while unwrapping an Optional value First, make sure all the IBOutlets are connected in the xib or storyboard� The line self.present(vc, animated: true, completion: nil) — this reference is internally managed by Apple and gets removed on dismissing ViewController. 4. When dealing with IBOutlets

To Optional or Not to Optional: IBOutlet — Curtis Herbert, Optionals are a new concept to the Cococa world. Where-as Objective-C allowed for willy-nilly nil messaging, Swift wants you to be explicit and� In similar fashion to other languages, Swift uses nil to represent the situation where there is no value at all. By incorporating optional types directly into the language, Swift forces us to be clear about whether a particular variable, constant, parameter or return value can be nil and does so right there in the code rather than forcing us to rely on the documentation for that sort of information.

Comments
  • I have the same problem. Have you found any solution ?
  • See my comment below, adding @objc to the receiving class and running 'clean' did help. (I haven't seen this since). I am currently (6.1) getting a lot of 'cannot find details for class x' (including the AppController class) which I circumvent by writing the IBAction/IBOutlet code, running 'clean', and making the connection from class to nib file.)
  • Thanks for the suggestion, this is one thing I hadn't tried since my understanding was that instantiating an item in the nib file means that the nib file has a strong reference to the item. Sadly, this isn't the solution: I know the controller exists because it populates a table, and removing 'weak' makes no difference, so this is about the outlet not being set.
  • Put a breakpoint on the setter method and see if it's called.
  • There isn't a setter method. As far as I understand, InterfaceBuilder is supposed to resolve the IBOutlet directive once the nib has finished loading, and it doesn't. I have never seen a method to set an IBOutlet in code, so the only workaround seems to be to force instantiation in applicationDidFinishLaunching and setting up connections manually? That would make for a lot of very messy code :-(
  • using 'didSet' on the IBOutlet did help me to check that no, they really weren't set. Every time I tested this Apple brought out a new version of Xcode, and GM1 gave me a lot of problems. In GM2, error messages have changed. Two seemingly necessary steps: use @objc(className) for the class you want have the IBOutlet property and use 'clean' to make that change stick, otherwise IB will not recognise that class. I would suspect this was the problem all along, only now the error messages were clearer.
  • weak is ok. I had @objc but didn't have @objc(className). Apparently (className) is needed which is ridiculous.
  • I'll make a note of that - I haven't had this problem in years (and several Xcode versions), so I had assumed it had been fixed. (There have been changes and Apple now recommends that outlets should be strong.)