OK, so here's the deal...
I'm trying to connect even the simplest actions (the typical ctrl+drag from the UI builder to the corresponding file), the actions are created fine, but they're not working.
What the UI (with a test action) looks like:
And the corresponding part in AppDelegate.swift (which doesn't get called no matter what)
In case it makes any difference:
macOS : High Sierra 10.13.2
Xcode : 9.1 (9B55)
Project platform : macOS
Project language : Swift
Storyboards : NO
Auto Layout : NO
Which files should I have a look into, in case something has been corrupted?
I have had a look into MainMenu.xib but the <connection> and <action>s there seem to be linking the correct things. Maybe it's the project.pbxproj file?
Note: The project in question is a result of (automatically) duplicating a previous Xcode (+Swift) project, so chances are something might have gone wrong during the process. (although it normally works for me). Let's see...
The first and possibly only place to sanity check Outlets,Segues,Actions is this right panel menu in Xcode:
I am thinking that the #IBAction line for buttonClicked should be in the viewController file instead of the AppDelegate file
Related
I'm running 10.10 with Xcode 6.1.
And I'm having trouble getting an app I wrote to work. After hours and hours I finally got it to build correctly after accidentally messing with something, but now I'm getting an error I don't have permission to view the file (if I open directly in Xcode) or if I try to open it from the Finder it says the App is damaged or corrupt and can't be open. If it matters it's written in Swift.
I've literally spent 6 hours on this (Just trying to get it to build) so any help would be greatly appreciated! Austen
Here's the Xcode workspace, project, files, and a build if anyone needs to take a look: http://pattersoncode.ca/ServerChecker.zip
There are a several issues here. I can't help you with all of them, but I can put you on the right path, at least.
The app won't launch because it wasn't built correctly. Specifically, there's not any actual binary executable in the built .app. You can see this by right-clicking on the built Server Checker.app and choosing Show Package Contents. In there is a Contents folder; open that. Inside that should be a folder called MacOS, in which your actual binary executable would be. But it's not there. This isn't really an app at all.
Reason is, you have a custom build rule for swift files that's making them not compile at all. Just remove that, you don't need it.
In Xcode, click on the top-level item of the project (it says something like ServerChecker, 1 target, OS X SDK 10.10). Then, under TARGETS, select ServerChecker. Click Build Rules. The thing that says "Swift source files using Script", that we don't need. Click the little X in the top-right corner, and click Delete when prompted. Now try to build again.
You'll get an error:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
Since you don't have a main.swift file, your app doesn't have a main entry point. In Swift, you must either provide an NSApplicationMain function (usually in main.swift), or you can declare your app delegate as NSApplicationMain, which has the effect of calling NSApplicationMain with your delegate class. I recommend the latter.
Open up AppDelegate.swift, and add #NSApplicationMain to your AppDelegate class. It should look like:
#NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
...
}
Now your app should build again. Right-click it and Show Package Contents to verify that there's actually an executable binary in there.
The app still won't run. It looks like on launch there's an error that a library couldn't be loaded.
Hopefully that helps you get moving, anyway. I really need to get back to work now. :)
I just bought the book: Sams Teach Yourself iPhone Application Development in 24 Hours.
In the book it uses xCode 3.2.4, so I went ahead and tried xCode 4.3 (the current version), but I didn't understand what to do...
I then found this page...
https://developer.apple.com/downloads/index.action
I downloaded the version of xCode used in the book (just so I could see the same thing the book shows).
But, I'm getting two errors each having something to do with the Interface Builder...
"This version of Interface Builder does not support documents of type "Interface Builder Cocoa Touch Document (XIB 3.x)" targeting "iPhone/iPod touch"."
And it comes up twice for two different documents in my xCode project.
How can i get it to work? In the book the code I put in works just fine.
Also my Mac Version is: 10.7.3
Do not waste time learning anything about Xcode 3.x. That would be like learning how to build catapults and siege engines in preparation for a career in the military.
Apple completely rewrote Xcode with version 4.0, and every single thing about the user interface is totally and completely different. If you invest time learning 3.x, you will be totally lost and confused when you move up to 4.x (version 4.3. was just released, and there is yet a new version on the horizon.)
I was totally lost and confused for about 2 weeks when I made the move from Xcode 3.x to 4.x, and I do this for a living and have been using Xcode for over 6 years now.
Unfortunately, the iOS development books are behind the curve when it comes to versions of Xcode.
Do yourself a favor and set the Xcode 3 book aside and find an Xcode 4 book (an ebook might be a better choice, since they can be updated.)
From what I just read, the xib files you have are not compatible with the newest version of Xcode.
You may learn loads by fixing this.
Don't delete the two files yet...
Will the xib documents still display in IB?
Try this:
Rename the two xib files to some other name.
*) With the old file open in IB, click View, Utilities, Show File Inspector.
Click File's Owner, Rename
1) In toolbar click File, New, File
2) Choose User Interface, Empty, Next, Next
3) Type the name of the corresponding .h file, be case sensitive. Click Create.
4) Click File's Owner
5) With the new file open in IB, click View, Utilities, Show Identity Inspector.
6) For the class name, Use the class name in which you are attempting to fix.
7) Drag a New View object to to the canvas, right click the new view, and set a Reference to the file owner's view variable by dragging to File Owner.
At this point, you could attempt to copy all the objects out of the old xib and paste to the new one. Make sure you check all referencing outlets and target action stuff.
8) Delete the old files in Xcode by right clicking and choose Delete, References Only.
Let me know if this works or not.
Guys, i wonder if any one can help - My project was fully working in both the simulator and on a device, however, i renamed the project in xcode 4 (double clicking at the root of the project navigation pane, it was happy to rename any references - but now when i launch the app it only opens to the main window (yes it has outlets, all have outlets etc etc),
no code in the app delegate stops at a break point (even in didFinishLaunchingWithOptions)
so unsure what i could have missed, i have looked at other answers and everyone writes and says "missing outlet" etc.
I have dragged some backed up version of the app delegate that used to work and no difference, what could i be missing.
I do have source control, however currently in the process of merging from VSS to GIT.
thanks
lee
Check your Info.plist for what it uses as it's Main Nib File. Perhaps something changed there? Also, within the nib file itself you might have problematic connections to classes that are still named with the old name.
For some reason Xcode's Refactor is always disabled. I used to be able to activate it via selecting a class name and right clicking in the editor to select it. But now no matter what I do, it remains disabled. Any idea what's going on?
Working with Xcode 5, I kept getting "Can't refactor during indexing" when trying to refactor. Rebuilding the index seemed to hang at "Indexing - Waiting for make" forever.
I then noticed that make was already used by another process on my machine (not by Xcode). Shutting this process down enabled Xcode to finally finish indexing
Your project's index might be out of date/corrupt. In the General tab of the Project Settings window, click Rebuild Code Index and wait until it's done.
You can check the progress of the rebuild in the Activity window (Window > Activity).
I just ran into a similar problem in Xcode. I could not refactor anything in the class's .m (implementation file). The only explanation I could come up with is that it was not indexing the file for some reason, and I could not force it to reindex. The only hack that I found that worked was to copy the file to temporary location, remove it from my Xcode project, copy the file from the temp location back to my project's location, and then re-add the file via Xcode.
None of these suggestions work for Xcode 3.2 - the ONLY way is to select the file you want to rename in the left Groups & Files column. THEN highlight the name of the .m or .h in the right code view, then you can right click and select Refactor!
For instance if you're changing the DetailViewController name, highlight the actual DetailViewController.h word in code.
Note, you should also always make sure you've selected the .h file, not the .m
I faced the same thing in Xcode 11. and this worked for me:
I changed iPhone 8 simulator to generic iOS Device and it worked when it is on Generic
I'm new in iOS development,I have met this similar problem.
Xcode:Version 7.1 (7B91b),it looks like Refactor not working:
But when I put my mouse on the red circle point in the following picture,and then the Refactor working.
I think this is a low level mistake,but may be a reference for someone.
Why is Refactor... grayed out (disabled) in Xcode?
I'd like to rename a class.
Select the class's symbol in its header file - i.e. the bit just after #interface. Then the refactoring stuff should be enabled.
If you are using Objective-C++ (i.e. mix Objective-C with C++ code) then refactoring is disabled in xcode since it does not support refactoring of C++ code.
Refactor might also be disabled if affected files (most likely the file with your class in it) are not saved.
I've been using Xcode for 5 years now, and refactoring has never worked correctly (even xcode 4.6 has major bugs where it WILL corrupt your source code!).
The workaround has always been (still works 100%, even in cases where Apple's code fails)
use shift-command-f to find all uses of the file
select "replace" in the search settings
"replace-all"
do the following for the .h file, and REPEAT IT FOR THE .m FILE (if you have one):
right click the original file, and select "show in finder"
delete the file from xcode (select "delete references only" when asked)
rename the .h (and .m if you have one) in Finder
in Xcode, select "Product -> (hold down Alt) -> Clean Build Folder"
quit xcode (you can usually get away with not doing this - but NOTE: there are some other MAJOR bugs in Xcode where it crashes itself if you don't do this)
re-open xcode
drag/drop the .h and .m back into Xcode
wait a few seconds (some of Xcode's core methods are asynchronous - allowing it to corrupt your project)
finally, when it seems to be doing nothing (and your hard disk isn't making any noise any more): cmd-b to re-build
I have a 100% success rate with this method. I just tried refactoring with Apple's "Refactor -> Rename" in latest xcode and it failed - again!
(this time with the incorrect error: "Unable to determine the language of", one of those error messages where Apple put the wrong text in place)
I'm going to my project at finder, then change files name by get info.
After that, at xcode -> Project Navigator I delete the files.
At end, I click right on the class and Add files to ..., and add these files again.
It worked for me.
For me I realized Refactor was disabled because the Xcode project I had opened was referencing a Base SDK that was missing. Edit Project Settings and in the Build tab set the Base SDK to one that you have (like for me this was iOS 4.2). This enabled Refactor for me.
Also, it could happen that you renamed the filename for the class, either outside xcode or by ctrl-clicking the filename and then renaming it.
xcode refuses to refactor if filename does not match with the class name.
Go to your class' header file and find the line that looks similar to this:
#interface YourClassName
Right click on the class symbol (e.g. YourClassName) and you should be able to select Refactor -> Rename...
I just tried this and it works in Xcode 5.
This may be a bit late, but I stumbled across this post because I was unable to refactor my "ViewController.swift" file to "WhateverViewController.swift". I tried selecting the file in the Project Navigator and then selecting "Editor -> Refactor" from the top menu, but 'rename' is always greyed out.
Instead, what worked was selecting the ViewController name from the editor. So if you have:
class ViewController: UIViewController {
// Code here...
}
Highlight the "ViewController" word and then select Refactor from the menu or right-click and select Refactor -> rename.
Hopefully that helps...
Had this problem as well. I ran through trying to find missing SDKs, saving files, and looking for Objective-C++ code as mentioned above, and all it took to fix my machine was rebooting XCode.
Seems a little buggy still.
BTW, this was for XCode 4.0.1
Refactoring works If you first change the file name in the project navigator.