I'm getting a lock alert when trying to connect/add elements to the viewcontroller in Xcode 7.3 - ios

I have a ViewController that all of the sudden will not allow me to add a new element or connect an existing element to an IBAction. I've looked through sample code as well and googled the s*%& out of it without finding a solution.
My ViewController.swift file contains this code:
#IBAction func helpButtonTapped(sender: AnyObject) {
}
And I'm trying to connect a very basic button.
Also, note that I've double-checked to be sure that all elements and views are set to Lock: Nothing.
Any help would be amazing!

Go to menu Editor then Localization Locking then choose Nothing.
You probably have enabled one of the other locking options accidentally.

Related

What is the reset(_:) method

I am learning iOS app development, and I came across a line which confused me:
Also add a call from reset(_:) so it works when you reset the app
But I can't find a reset(_:) function anywhere, both in ViewController and AppDelegate. Do I have to create the function, or is it something different?
So let's add the additional infos:
Your quote is from Intro to App Development with Swift, Apple's iBook., chapter 17.6 Polishing the Interface, in Disabling sliders subpart.
You missed the previous part:
#IBAction func reset(_ sender: AnyObject) {​} Open the Connections inspector. You’ll see that the button has been
connected to the Touch Up Inside event. This is the standard event
used ​for most buttons. Your reset button will set the value of each
slider to 1 and the isOn property of each switch to false. Add that
code to the new action method.
So your quote was talking about that method that you should have added previously on ViewController.swift in the chapter 17.5 Reset Button.

can multiple buttons be attached to a single IBAction is Xcode 8?

I have tried to connect several buttons to a single IBAction in Xcode 8 however it does not work. I tried the practices outlined here Xcode8 cannot connect multiple/single uibuttons to single #IBAction in swift file still to no avail. can anyone shed some light as to why or if it is simply still just a bug?
Works fine for me in Xcode 8.1 on a new Swift 3 project. You have to control-drag from the button to the center side of the method to select it if it already exists rather than drag to the left side.
change your parameter from (_ sender: Any) to (_ sender: UIButton), and you're good to go.
There is no reason why several buttons should not connect to a single action function in your code. I had no trouble doing this when I tried it, as you can see:
However, if the nib editor interface won't let you form the connection, configure the action-target of the buttons in code.
Double check if you want to add action to a real button
Check if when you wrote the action, you used some customized class instead of UIButton, and the class of your button does not match.
I was able to resolve the issue by upgrading to Xcode 8.1 and including an _ before the sender argument. I believe this is just a bug from Xcode 8 because I tried the latter before upgrading and I was still unable to connect.

iOS 9 Segue Causes App To Freeze (no crash or error thrown)

I have been working on this app for months now and from as far back as I can remember I have never had an issue with segues. The code is unchanged in terms of calling performSegueWithIdentifier but since my recent update to Xcode 7 and iOS 9 I have not been able to tack this issue.
I have tried:
Deleting button and creating new button w/ segue link
Using a direct segue from button to view, without the use of performSegueWithIdentifier
Connecting button to new blank viewController
When I press the button, no initial load functions are called on the destination VC (Ex: ViewDidLoad, ViewWillAppear, etc). When I connect it to a blank view, the segue works fine with the same code in place.
Since the code never stops, or breaks, and just seems to "freeze" in place while still running on Xcode I can't seem to even narrow this down to whats causing the issue. I have a similar segue that is also called from another button on the same ViewController that has no issues whatsoever.
Any thoughts on the matter are greatly appreciated!
EDIT: I have narrowed the issue down to the UITextView's causing the problem. Once the Text Views were removed the page loads fine via segue. I wonder what changed between iOS 8 and iOS 9 in terms of UITextView as I will have to remove the text views and completely re add new text views.
So basically the segue was freezing because of the UITextView's I was using in the destinationViewController. The following fixed the issue:
Delete all UITextView's
Add new UITextView's
you must leave the default lorem imposed text and change this programmatically in the viewDidLoad()
This was the fix for me, and from the research I have done on the issue it seems this is a bug in iOS 9 and Xcode 7.
Cheers!
NOTE: Removing the text in the UITextView (or making it longer then ~12 characters) is sufficient to work around it, no need to delete and recreate them. This is fixed in Xcode 7.1.1 and later.
I ran into the same issue and the fixes in this post (Xcode 7 crash: [NSLocalizableString length] 30000) solved the issue for me.
The first is to enable a localisation other than the base for the storyboard (see https://stackoverflow.com/a/32688815/3718974)
The second is to turn off the base localisation (see https://stackoverflow.com/a/32719247/3718974)
I think I have the same problem: I have a UITabelView with cells created from a nib file, when a user tap a cell this method is called:
and when I have the following method prepareForSegue:: the application crashes:
if I delete the line 129 Everything is ok , the method prepareForSegue:: open the right view and the label contactName is shown with its default text.
If I modify the method as follows prepareForSegue:: get exactly what you expect, without having any type of error:
let me know if you also get the same result
Any one who is facing this issue, i solved it by turning off the "Optimize rendering for windows scale" option in Debug of simulator window. I already had tried all of the above answers but could not solve the issue.
In the method in the first viewController where you activate the segue, do you have beginIgnoringInteractionEvents anywhere? If so the screen you segue to will be frozen and will ignore interaction events like you describe. If this is the case you can fix this by adding an endIgnoringInteractionEvents method before your segue method:
UIApplication.sharedApplication().endIgnoringInteractionEvents()
self.performSegueWithIdentifier("editItemToMyGearSegue", sender: self)
I realize this is an old topic, but appears to be still relevant. I was facing the same problem in Xcode 9, iOS11. My UITextViews are embedded inside UITableViewCells. Same symptoms as described here. The tricks with default text and placeholders did nothing for me, but I solved it by turning off the scrolling indicators for the text view in the xib. They were on by default, I guess, though unused.
Edit: this is probably an important detail... the views that were hanging all had an image NSTextAttachment in the attributed string of the text view. I think the image was wider than the available table cell content. With scrolling turned off, they appear to downscale.

Xcode UI Test example

I have just recently learned about Unit Testing in Xcode. Now I am trying out Xcode 7 and I see there is a new group for UI Tests when I create a new project.
I watched the WWDC 2015 video and it was pretty good, but do you have a super simple example that I could go through myself? The video examples were a little too complex for me.
Notes
The answer below is my attempt to figure this out, but I welcome any better answers.
I have read these SO questions about UI Testing in Xcode but they are different: docs, reloading, App vs UI, ViewController, multiple, values and properties, pre XCode 7 projects.
Use Unit Tests to test the validity of methods in your classes. You use them to test the code you have written. (See my other example for setting up a simple Unit Test in Xcode.)
Use UI Tests to check the validity of the User Interface. Think of it like having your own robot to go through and do all the normal interactions with your app that a normal user would. This saves you the time of doing it yourself.
At the time of this writing, it is difficult to access many of the properties of the UI components, but just having a test go through tapping them and swiping them confirms that they are there.
Example
This is about the simplest setup and UI test that I could think of: a button that when pressed changes the text of a label.
Set up
Create a new project in Xcode 7+ for iOS 9.0+.
Make sure that Include UI Tests is checked
If you are adding UI tests to a project created before Xcode 7, see this answer. (File > New > Target > Test > Cocoa Touch UI Testing Bundle)
Add a UILabel and a UIButton to the storyboard
Create an #IBOutlet and #IBAction in the ViewController and make the label text change when the button is pressed.
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var label: UILabel!
#IBAction func button(sender: AnyObject) {
label.text = "Hello"
}
}
Do the test
Open the YourProjectUITests file.
Put your curser in the testExample() method. (You can delete the comments)
Press the red Record button
In the app, (1) tap the label, (2) tap the button, and then (3) tap the label again. (4) Press the Record button again to stop recording. The following code should have been automatically generated for you:
func testExample() {
let app = XCUIApplication()
app.staticTexts["Label"].tap()
app.buttons["Button"].tap()
app.staticTexts["Hello"].tap()
}
Use the staticText lines as a starting point for making an XCTAssert. Now you should have:
func testExample() {
let app = XCUIApplication()
XCTAssert(app.staticTexts["Label"].exists)
app.buttons["Button"].tap()
XCTAssert(app.staticTexts["Hello"].exists)
}
Press the diamond on the left to run the UI Test. It should turn green when it passes.
That's it! This showed that the UIButton and UILabel exist and that the text of the label changed. If you want to see it fail (a good idea), you can change "Hello" to something else.
Further study
UI Testing in Xcode
Exploring the New UI Testing Features of Xcode 7
Xcode 7 UI testing, a first look
UI Testing in Xcode 7
#Suragch +1 for the answer. One thing I observed and want to share that every function inside the UI Test case must start with "test". You can append extra name after that. Only this way the button(for clicking to start the test) appears.

Error in Xcode 6 - view controller does not have an outlet named (subview)

I just got this error in one of my apps, and after checking some other apps the same error is happening. None of my IBOutlets and IBActions are connected anymore. When I recreate the outlet by control-dragging into the .h file, the outlet still displays the error in Connections Inspector > Outlets, saying (view controller) does not have an outlet named (subview). Before today I didn't have this problem, so is to do with Xcode 6? The view controller is referencing the correct class under Identity Inspector > Custom Class. I have deleted the derived data folder, removed the reference to the .h file, cleaned the project, and cleaned the build folder. None of that has worked and I can't progress with development until this issue is fixed.
Update: I just reopened the project after a couple of days and my outlets no longer have the exclamation mark next to them, and the 'easyLabel' outlet that I disconnected has reappeared. I didn't change anything, so I guess it's a bug in Xcode 6-6.1.
Update 2: This error came back. Exclamation marks next to every outlet. If I delete them I can't re-add them. Can't create new outlets. Also can't give a view controller a custom class. I really just want to make some progress on an app, but this issue keeps recurring. Really just can't stand it anymore. Any help would be appreciated.
Duplicate of: Xcode 6: can't connect any IBOutlet to ViewController but here's the trick:
You can also see that the link between the parent view and the custom class is broken (not visible anymore) which is a huge problem.
I had the exact same issue with the app i'm working on actually, updating Xcode from 5.xxx to 6.1. The workaround that worked for me was to remove the reference of every view controller and re-add them to the project... Unfortunately, in some cases, mine actually, all the connections get lost again when XCode is closed.
To everyone facing that issue, here's the (annoying) trick :
Step 1 : select both .h and .m view controller files
Step 2 : remove the reference of those files
Step 3 : re-add the files to your project tree
Step 4 : open the storyboard, eventually re-build the project and smile
I can understand those things could be reaaally annoying, but it worked for me... Hope it will help someone else !
I had the exact same problem and what was breaking my storyboards was the fact that my project was inside the folder /Dropbox (MyName)/projects/
Apparently something about the name of the dropbox folder with spaces and ( ) was BREAKING my storyboard completely, try what I did and move your project completely to another folder and see if that helps :)
I had the same problem, changed the class under identity Inspector > Custom Class to something else, saved it and then set it again to the correct one, after doing that the connections appeared normally.
I had this issue with a Swift UIViewController subclass. I had removed the original view that IB created for me, and added a new view—which I was unable to connect.
I went to the Identity inspector for the File's owner, and tried to re-enter it, thinking that maybe it had been modified somehow. Oddly, the class name did not autocomplete. It seemed like XCode was unable to actually see my class.
I tried removing and re-adding both the .swift and .xib files, to no avail. XCode would allow me to manually type in my owning class name, but it would not autocomplete. It seemed to think it didn't exist, or wasn't valid for this context.
Looking back at my code, I had something like the following:
extension SomeViewController {
func foo() -> Bool {
return false
}
}
class SomeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
It compiles just fine, but on a hunch, I removed the extension. I saved the file, went back to the .xib, and was able to set the File's Owner identity with autocompletion again. I was also able to wire up the view.
It would suck if extensions always broke things of course, so I tried again, this time with the extension after the class:
class SomeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
extension SomeViewController {
func foo() -> Bool {
return false
}
}
Everything still worked in IB. To sanity check, I moved the extension back ahead of the class definition, and things were again horked.
I took a look a the *-Swift.h generated by XCode, and at least relative to the affected class, there seemed to be no differences—regardless of where I put the extensions in the Swift file, they were always declared after the #interface definition for the actual class in the header.
So, long story short, in my case this was due to Swift extensions (I say extensions because my actual code has many) coming before the class definition. I moved them after the class definition, and the problem went away.
For me I had to remove the reference and add back to my project the -XIB- file for my view controller. Simply removing the view controller .h/.m did not reset the outlets, but removing the .xib and adding it back did!
I have this problem only with #protocol defined IBOutlets if I don't redefine them in the implementing class.
Probably the only thing we can do is file a bug.
Why dont you update your xcode 6.0.1 to xcode 6.1, Apple have fixed many bugs.
Download Xcode 6
Do you get the same issue if you connect the actions/outlets in Interface Builder instead of the assistant editor? For actions try control dragging from your object in IB to your first responder object (or whatever you have your class set to).
#robb actually discovered the fix for this, but the issue he found was that the group in the project that mirrored a folder on disk used a different case.
So if the project group was Broken/classone.m
and on disk it was broken/classone.m
Interface builder could not find the files. Renaming either the group or the folder to match case resolved the issue.
I was having the same issue but it was because i changed the name of the view controller in the Project Navigator to MapViewController but its name stayed the same (ViewController) in the code. once i changed it, it worked
I've had this same problem since using XCode 6.1, answers above didn't work for me. (removing/re-adding my class files, changing the class to something else and then changing it back. The only thing I didn't try was creating a new project from scratch).
I noticed by accident that my 'Application' placeholder within the MainMenu.xib had somehow got its class set to NSObject. Changing that to NSApplication seemed to clear the 'does not have an outlet named' problem from all of my other objects.
I updated my project from Xcode 6.x to Xcode 7.x about two months ago without any issues. But then this morning I ran into this bug. I tried pretty much everything on this page but nothing worked. But then Justin Middleton's solution gave me an idea.
When I switched my project from the 10.9 SDK to the 10.11 SDK, I decided I wanted my code to remain backwards compatible just in case I had to revert back to Xcode 6.2. So I put Preprocessor code around several of my object declarations, e.g.:
// This caused the (!) problem in Interface Builder
#if( MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_10 )
#interface CLChatWindowController : NSObject <WebPolicyDelegate, WebUIDelegate, WebFrameLoadDelegate>
#else
#interface CLChatWindowController : NSObject
#endif
...
// Removing all the Preprocessor code fixed the problem
#interface CLChatWindowController : NSObject <WebPolicyDelegate, WebUIDelegate, WebFrameLoadDelegate>
....
Once I removed all the Preprocessor code, the (!) characters in Interface Builder disappeared and everything went back to normal. Hope that helps someone.
Xcode 6.3.2. Similar issue. A project(s) that i've been working on suddenly 'disconnects' IBOutlets and shows the error
view controller does not have an outlet named (subview)
The project still builds and works and if you hover over the IBOutlets in code it thinks there are still connected.
I've nailed this down (at least in my case) to an issue with storing projects on dropbox (similar to an above post). The fix for me was super easy:
Drag the project folder off of dropbox to your desktop. Then drag the project back into dropbox.
This solution has fixed numerous projects with the issue.
Try to add the header file to the project, if it's missing.
I had this in Xcode 7.0.1 on a swift project. Specifically, tableview cell connections were broken (permanently) while other things still worked. Deleting derived data, rebooting etc - nothing worked.
My solution ended up being:
Close xcode project
Delete derived data for project (Window->Projects)
Rename the entire project/source folder, ie. project -> project-1
(Update source-management bookmarks like sourcetree as required)
Open project in xcode (from finder): notice that the storyboard and a few other files are in red. Delete the references, re-add them. Boom, it works.
Note that deleting the reference to the storyboard and readding it, even with deleted derived data, was not enough. The rename of the entire source folder was necessary for me.

Resources