I'm facing a few problems with Xcode. I have searched around and nothing helps... to make things worst i'm learning everything from scratch. swift, xcode, build mac apps... coming from ruby/rails this is extremely painful!
A while ago all projects started throwing errors like the use of undeclared type 'NSObject' and so on.
I am using Xcode Version 6.1 (6A1052d).
The project still runs if I clean/build it and run. But as soon as I select another file and come back the AppDelegate the errors appear again. Also cmd+clicking just displays "Symbol not found" and autocompletion doesn't work.
I created a new blank project (multiple times) and this still happens. I didn't even touch the code! I have attached two images to show my problems.
The first line error I managed to fix it following Subclass UIApplication with Swift:
Basically I removed #NSApplicationMain from AppDelegate and created a main.swift file with these lines.
import Foundation
import AppKit
NSApplicationMain(C_ARGC, C_ARGV)
this seems to fix the 'NSApplicationMain' class must conform to the 'NSApplicationDelegate' protocol error.
But I can't see how to fix the other errors. Any help please? :) Thanks in advance.
So this is just bizarre. If I create a custom Table View Controller as a subclass of UITableViewController, I can't reliably edit the .m file. When I click on it, I can see everything in the file, but I can't actually drop the cursor in to edit the code; it stays fixed in the top-left of the screen. Anything I type will appear, and any code already in .m that happens to be on that line will randomly appear. It's like a static image of the .m contents are on the screen, but the actual text is hidden.
Eventually the entire editor just goes blank. Everything else works fine. I wiped Xcode with app cleaner to pick up all the loose com files, restarted, re-installed Xcode from the dmg and re-created the project and still have the same problem (this is under Mavericks, by the way).
Granted, Xcode 5 doesn't seem to have this issue, but I'm quite new to programming and am following a course that's based on Xcode 4. And at this point the issue is just so stupidly weird that I want to figure out what's going wrong. Any insights?
I've given up. If for some strange reason someone happens on this question and has the same problem, it's not worth the energy; just head to Xcode 5 and live your life bizarre-error free (for now, heh).
I was having the same problem. I just cleaned the Build Folder and everything seems to be working perfectly now. You clean the build folder by selecting Product, hold Alt, and then "Clean Build Folder.
I too had this problem after upgrading to XCode 5, then downloading and installing XCode 4.5 (without removing Xcode 5). What I wound up doing was to create all my new UITableViewController files (File->New File->Objective C Class) as UIViewController files, then modifying the parent class to UITableViewController in the .h file.
I'm working through "Cocoa Programming: A Quick-Start Guide for Developers." One of the examples is to create a basic browser by inserting a WebView object into a window. Whenever I do that, it causes the program to crash (compiles alright, though) with the message:
Thread 1: SIGABRT
tagged to the line:
return NSApplicationMain(argc, (const char **)argv);
I know that it is the WebView object because when I remove it, the problem goes away. I saw a similar question here that suggested adding the following lines to the preprocessor:
#import <webKit/webview.h>
#import <webKit/webkit.h>
but the result is the same. I've written no actual code, only manipulated the MainMenu.xib in the Interface Builder GUI.
WebKit.framework needs to be included in the build.
Go to MacHD>System>Library>Frameworks and drag the WebKit.framework folder into the project icon in XCode. A window will pop up and ask if you want to add the files to the project. Click finish and it will work.
This feels weird to not be including library files by typing in that they should be included.
When I was using Xcode 3 I had configured it with a perl script I found on the web that allowed me to automatically generate the #property, #synthesize and dealloc code for new instance variables. Xcode 4 doesn't have that User Scripts menu though.
Is there a way to plug in these kinds of User Scripts for Xcode 4 or does Xcode 4 have a new feature that generates that stuff automatically? (I've looked and can't find one though).
I'm not talking about linking to IBOutlets. I know that I can drag from a xib and it will create all of the right stuff for IBOutlets, but I'm looking for something that will create #property, #synthesize and dealloc code for any instance variable.
Thanks,
Kenny
I would strongly (and I can't emphasize this enough) suggest the application:
Accessorizer
This is by far the most useful application for writing objective-C and objective-C 2.0 code that I have found. Originally written in the pre ObjC2.0 days, it created ivar getters and setters for you. Over the years it just keeps evolving. Now it does properties, container classes, key value encoding, KVO.
It tailors to your style: What line do you put brackets on, how do you indent, how do you comment? It also installs as a service so you can call it up from XCode, copy to the clipboard and paste right back into XCode.
I am not the author, I get nothing for plugging this. However, I have introduced its usage to every Mac team I've worked on and have converted every Obj-C programmer to it on first use.
It's got a demo period. Definitely at least try it out and see if it solves your issue.
I managed to get the Xcode 3 perl script mentioned above working under Xcode 4 as a behaviour.
I put it up on github. https://bitly.com/HXHiij
Hope that helps.
I haven't tested either of these yet, but both claim to support Xcode 4:
https://github.com/CraigWilliams/property_synthesize_dealloc
https://public.me.com/dhoerl (Navigate to Xcode/PropertyMaster)
I also miss the property related scripts, but I have found a workaround. As noted elsewhere, XCode 4 will automatically generate the property/synthesize/dealloc code for IBoutlets that are hooked up through IB.
So I have a dummy XIB in my project called Property_Hack.XIB with some UILabels, and whenever I need a new property for a class I go to Property_Hack, change the owner, and "connect" a label to the file. All you have to do is enter the name of the ivar you want, and XCode will add the #property statement to the .h, and in the .m it will add the #synthesize and dealloc code. Then I modify the .h (delete IBoutlet keyword, and change UILabel to the datatype you want).
Rather hackish and far from perfect, but it is still a time saver compared to the manual effort of modifying both files. Since NSIntegers and BOOLs do not need dealloc code, and are assign instead of retain, I usually set them up manually instead of using this approach. Whether or not NSStrings should be copy or retain is an argument I will not rehash here :-)
I find that in various situations Objective-C code in Xcode 3.1 (Leopard) can fail to get appropriate syntax coloring after typing or lose coloring that it had.
This isn't just a "refresh" issue with new custom symbols -- but affects Cocoa framework symbols as well.
Sometimes CMD-a to select all text on the code page will make the coloring (re)appear, sometimes double-clicking on a line to select it will work, sometimes I have to add/delete a space in a symbol to get that symbol to (re)color. Rebuilding, or closing/reopening the project may or may not work.
Is this a known issue with Xcode? For something so annoying to me, I'm not finding the plentiful discussions of it on SO and elsewhere I'd expect.
And is there any command to force global syntax recoloring?
1.) Go to Project --> Build Settings --> Header Search Paths
2.) Add "$(SRCROOT)/**"
3.) Close and reload the project
4.) Go to Xcode --> Window --> Organizer --> Projects --> $YourProject --> Delete Derived Data
5.) Wait a moment until XCode rebuild all indicies
To get more information activate verbose logging:
1.) Increase Xcode log level in Terminal app:
defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3
2.) Open Console app. Search for "xcode"
3.) I saw "file not found" errors for header files mentioned in the pch file (therefore the fix above)
I had the same issue with a project that was fine in Xcode 3 and for which the syntax highlighting and code completion has broken in Xcode 4. It took me the better half of the day to figure it out but I found that the following steps will reproduce / fix the issue 100% for me.
After trying all the aforementioned solutions to no avail, I tried creating the project from scratch and reimporting every file and folder painstakingly. Every time I imported a couple of files I checked and syntax highlighting still worked. Even after the last few of them it still did. Then I hit build which failed because I forgot to include a couple of common header files in the project .pch file that were there in the old project. And that was when CodeSense broke again.
After further investigation we found that if you import a header file that in turn imports the same framework header file than the .pch already does, then CodeSense will break. The same setup did not cause any issues in Xcode 3.
Example:
project.pch
#import <Foundation/Foundation.h>
#import "projectConfig.h"
projectConfig.h
#import <Foundation/Foundation.h>
#import "one.h"
#import "two.h"
So by removing the wholly unnecessary
#import <Foundation/Foundation.h>
directive from the 'projectConfig.h' you can fix the highlighting and code completion will come back for you as well. If your issue is the same as mine that is.
Just select the file who lost the syntax coloring , press Editor > Syntax Coloring > ( choose your language (Objective c++ for ex) instead of 'Default'
I have found the best way to regain syntax coloring is just to quit Xcode and re-launch it. I couldn't tell you why, but that works every time.
I find that the following will often do the trick…
"Reselect" both "Base SDK" - and "Architecture" - in "Build Settings".
(CLick on blue project icon in top left, while in "Browser mode", aka ⌘1, then click project settings and mess with the stuff there.
Make sure they all line up / it doesn't hurt to do a little toggly-wogglying up in there, while you're in there… ya know just mix it up a bit. You'll notice xCode has a teensy-tiny mini-stroke - every time you switch between 64 and 32 bit… This is usually when I know if code highlighting is dead for the night, or if I'm good to go.
Often, I will have a project that gets highlighted instantly in 32 bit mode, and just sits there in 64… Who knows.. Ahh, Xcode, you wacky botch.
Select your Project -> Build Settings tab -> Apple LLVM Language 5.0 -> Precompile Prefix Header to YES. NSLog was not highlighting. Currently running Xcode 5.0.1 Hope it helps =) Thanks #rebelzach
I can confirm a 100% fix for this problem, based on a question I had asked (and actually answered), as pictured below. One thing i will add is that sometimes it is "errant whitespace" that can also contribute to the loss of highlighting. Either clean it up yourself, or use the Goggle Toolbox for Mac Xcode 4 plugin, which adds an entry in the XCode Edit menu called Clean Up Whitespace.
This appears to be a similar error from this question
I was able to correct this issue by setting Precompile Prefix Header to No in the build settings.
I recently had a similar issue, all coloring and autocomplete stopped working for built-in frameworks, my own classes still worked. Someone recommended to me that I turn off "Run Static Analyzer" in the build settings. It's weird, but it worked.
For me it was that I renamed my project, and Tests target was still pointing to the old pch location, but my App target was pointing to the new one.
If your app delegate still has code sense, this might be the case for you too. Go into project, select the 'Tests' target search 'prefix' and set it to the equivalent value in the 'app' target.
Open the project settings (Project > Edit Project Settings menu) and then click the Rebuild Code Sense Index button in the General tab. This will recreate the index that Xcode uses for syntax coloring.
This process can take a while for larger projects, so you can check the progress in the Activity window (Window > Activity menu).
Moreover, in XCode4 there is no button to rebuild the code sense index.
I had the same problem and solved this by updating my build settings to use the system default compiler, LLVM GCC 4.2.
It seems there are multiple factors.
I experience this issue as well, and have tried the solutions either "rebuilding the index", "relaunch XCode", "change the compiler setting to LLVM GCC 4.2". Those didn't help me out.
So I tried to add the following code right away along with the fresh creation of header file.
#include "header.h"
using namespace cocos2d
Then, the code added earlier in header file is colorized, and it can recognize classes and stuff.
I've used cocos2d-x, so my syntax is based on c++. I don't test it with Objective-c yet though.
For someone still have don't know why. Let open with XCode 8.2, it should work