Dragging and dropping not working in Xcode - ios

I'm working on my first Swift project in Xcode and am running into trouble with dragging and dropping elements from the storyboard into the code.
Nothing happens when I try dragging and dropping. I'm running the newest version of Xcode and using Swift.
The class is ViewController and the file is ViewController.swift
I'm trying to drag and drop a textfield into the class.

I have a question and possible solution for you, Sam.
What system are you using to do this? When I first started I wanted to use a mac over a remote connection and I found that holding control and dragging yielded me no blue line to associate the Interface Builder items with the assistant editor's code. I tried Chrome remote desktop, splash top, and VNC viewer. Nothing yielded the results I was looking for. Only when I got my own mac and was working with the machine itself was I able to control-click-and-drag to associate Interface Builder items with code.
Also, are you using the assistant editor or dragging into the file in the navigator on the left? I haven't tried the latter... only ever used the assistant editor.
Hope that helps!

You need to first change the class of the ViewController in the Storyboard to match the class of file that you are dropping into. Click the dropdown menu and choose your own viewcontroller class.
I'd suggest to rename your own viewcontroller class to differentiate it from iOS build-in class. Otherwise you might get confused while selecting the class.

May be you already solve. but it may help some one else. for Xcode-10 you will go
editor -> Localization Locking -> Reset Locking Controls
it help me to enable dragging and dropping the element.

You drag and drop into the Storyboard (Main.storyboard is the default name).
You cannot drag and drop inside a .swift file.
When your UI is complete, you need to "bind" the storyboard scene with the UIViewController (or any subclass) in the Identity Inspector (check this)

Related

Xcode 11.3.1 Beta does not show corresponding custom class in assistant editor

I am trying to create a project using Xcode 11.3.1 beta. I have added the UICollectionView and made an Custom Class for that and associated it with the cell in the storyboard.
But when I try to open that class in assistant editor it does not show up.
Like previously also it was not sometimes picking up the right corresponding class but then we could select the file manually but that option is missing here as it seems.
I cleared Derived data, restarted code but nothing is working. It's still showing the wrong class for the the UICollectionViewCell.
How do I resolve this?
Now that we have editor panes, there is really no need to use an Assistant pane. So just don’t use one. Use two normal editor panes and populate them however you like.

GLKView in IB will cause crash when app is run without Xcode

I have an app that displays a ViewController at some point, which includes a GLKView. All defined within a storyboard.
It works just fine, that is, unless you run the app from the phone itself, not launched from within Xcode. Upon presentation of the ViewController and therefore the GLKView, the app instantly crashes.
It doesn't matter if the Installed checkbox is ticked or unticked for the GLKView. Only when I delete it from the storyboard altogether, it won't crash.
Any ideas?
I don't know why these things happen but I would consider them a bug. A similar situation happens when adding a WKWebView directly from storyboard. For both the solution is pretty simple: All you need to do is import the module for it. So in your case in your view controller add:
import GLKit
It seems otherwise the framework is not loaded or something.
With ObjectiveC the problem seems to go a level deeper. It seems that the module must manually be imported. Go to your project settings. Select your target. Select "General". Scroll down to bottom and find "Linked Frameworks and Libraries". Below it find a "+" button and search for "GLKit.framework" and add it. This should fix the issue.

XCode Version 8.3.1 (8E1000a) IBOutlet Connect Issue

In the image see the highlighted portion .swift(Interface), When I get this it makes me unable to drag and connect from storyboard to viewcontroller class.
I have searched but not getting any clue that what is the issue behind this.
Can anyone help regarding this?
I have tried, clearing cache, cleaning the build, restarting the MBP etc but nothing helped.
I am unable to solve it out.
Rather than choosing "manual" and selecting the interface, you might use "automatic" and when you select the control in IB, you should see the actual .swift file (not the interface) in the assistant editor, and you should be able to control-drag at that point.
And you didn't mention it, but if you ever have troubles hooking up outlets, double check that the base class has been properly set in IB before you try hooking up outlets.
This is a Xcode bug, update to 8.3.2 to see if it fixes your problem (it doesn't show up on the app store update sometimes, so manually download it)

Xcode keeps building storyboard after each keystroke

My Xcode project using a storyboard entered in a very weird state recently: Xcode keeps building the whole project and notably the storyboard after each keypress. I found no reason for this behavior neither in my project diffing all interesting files (storyboard and project) neither a setting in Xcode (maybe I just could not find it?) Needless to say that this "feature" makes working on my project nearly impossible since the CPU is constantly occupying with rebuilding the storyboard when I type new code. Anybody seen this?
It is caused by the IB_DESIGNABLE definitions in the source header files. Probably it makes problem only if the header file containing IB_DESIGNABLE is included (even implicitly) to the source file you are currently editing.
I did not find a definitive solution how to disable IB_DESIGNABLE and thus compiling the storyboard and the source files continuously. I would appreciate an Xcode flag to disable this temporarily. I tried also surrounding the IB_DESIGNABLE with #ifdef macros but they are considered even if the #ifdef evaluates to false. Commenting out one by one the IB_DESIGNABLE helps but it is not a feasible solution with many IB_DESIGNABLEs.
Update
I finally found a quick way to avoid this annoying behavior. Having the storyboard opened in the active window, disable "Automatically Refresh Views" from the Editor menu. This will stop updating the views in the storyboard editor that use your custom code and thus speed up your development significantly. When you need again the just-in-time compiling to have a visual preview of your custom code, enable this option again (it seems you also have to re-open your storyboard to make it working again).
You may wish to add a key binding to the command, such as command-option-control-A, to easily toggle the behavior on/off. To add a key binding in Xcode, touch command-comma for preferences, choose the Key Bindings tab, use the search bar to find the command, then double-click on the right area to add your desired keystroke.
"Leave it off" approach
Alternately turn "Automatically Refresh Views" off, and never turn it on.
Make a convenient keystroke for "Refresh all views", say command-option-shift-R
As you work, just touch command-option-shift-R from time to time, or as needed. It's generally only necessary to touch command-option-shift-R as you work on the storyboard.
I had this problem and the accepted answer did not work for me.
The problem I had was that I always keep the storyboard open in it's own tab within XCode so that I can access it quickly.
The only way I could fix it was to either close that tab or select a different file (like a normal code file) and then close and reopen XCode. Thereafter it was no longer rebuilding on each keystroke.
Be warned however if you need to open the storyboard to make changes then this problem can sometimes reappear and I will have to repeat the above process.
Can't wait till Apple fixes this as it is very frustrating indeed!
(ノಠ益ಠ)ノ彡┻━┻

Missing ViewController.xib in Xcode 5

I'm new to iOS programming and is currently following the tutorial at http://codewithchris.com/demo-app-with-xcode-and-interface-builder/
We first create a new project using the Single View Application library.
Question: About half way into the tutorial, it says Once you have ViewController.xib opened on the left pane and ViewController.m opened on the right pane... However there is no .xib file anywhere in the Project Navigator, and this is the first mention of an .xib file in the tutorial.
Am I supposed to get a .xib file somewhere along the way? If so, which step will create the .xib?
XIB is an older format of Interface Builder. In newer versions of Xcode, by default, the project is created with a storyboard (Main.storyboard in your project). The difference is that in storyboards, you can see all the views of your app at once (and transitions between them), and with XIBs you have to keep them separately.
I'm not sure about this (can't check it right now), but if you insist on using XIBs, there should be a checkbox somewhere during creating a project. Anyway, I recommend you getting familiar with the storyboards, they are supposed to be a successor to XIBs.
As I can see in the tutorial, the author says 'XIB' even if he has a storyboard in his project, probably because he got used to XIBs. All in all, they are very similar in usage.
Actually storyboards contain .xibs (in your project one .xib as you created single view app.) The xib is just the user interface file shown in your second screenshot.
You just have to click the "Show assintant editor" on top right (the button with the suit) to split the xcode window and see the xib alongside the viewcontroller header/or implementation files.

Resources