I am adding a new protocol to my project but XCode does not recognize the code. I already have other protocols in the same project without any problems but this time the funny thing is the color of the code is not the right one and the automatic text helper is not recognizing the language.
For example in a protocol the code appear like that:
#import <Foundation/Foundation.h>
#protocol URLGetDelegate <NSObject>
#required
#optional
- (void)setWeather:(NSArray*) data;
- (void)setChemists:(NSData*) data;
#end
Then NSObject appear in purple, however in the new protocol the NSObject appear in black and when I type code, NSO... XCode does not offer me the words NSObject automatically.
#import <Foundation/Foundation.h>
#protocol CompanyDelegate <NSObject>
#end
Any help?
Thanks
What the Laure_f_o is referring to is the lack of standard auto completion and text colorization that happens in XCode; essentially XCode refusing to recognize a newly added protocol as such. So when you try and add it to a class and declare that class as subscribing to that protocol, you get a build error.
I just had the exact same sort of problem: other protocols in my project that work fine, but when trying to add a new one XCode just would not recognize it at all. This is all for XCode 4.6.2
What finally solved it for me was the following (based on Javy's advice here: Xcode Not Immediately Recognizing New Classes (iOS)):
1.) Clean Project
2.) Close project (but not XCode)
3.) Open Organizer in Xcode (under the Window menu)
4.) Select "Projects" tab
5.) Delete "Derived Data" (if you have saved snapshots, you'll have to delete those first)
6.) Quit XCode and restart computer
7.) Reopen project and clean it again
8.) Import the problem protocol into a class and declare that class as subscribing to it
Then, and only then, did I finally get the protocol in question to start behaving as such and didn't get build errors trying to use it in classes.
Related
I am studying by self for application development.
OS: MacOS
Software: Visual Studio(8.10.11 - build 8) for coding
Xcode(13.1)
I am referring a help article below published by Microsoft since I am using Visual Studio.
Ref; https://learn.microsoft.com/en-us/xamarin/mac/get-started/hello-mac
However, I am sticking at Outlets/Actions section.
I open storyboard on Xcode, and tried to sync between UI change to ViewController.h file.
I recognized that I do not have .h nor even .m file.
Did I have to create ViewController.h file manually??
There was also a sentence like this below.
This stub .h file mirrors the ViewController.designer.cs that is automatically added to a Xamarin.Mac project when a new NSWindow is created. This file will be used to synchronize the changes made by Interface Builder and is where the Outlets and Actions are created so that UI elements are exposed to C# code.
I researched NSWindow but I am super newbie on App Dev. So I am about to lose my mind and wasting my time for a long (T_T)
Could someone help me here?
This Visual Studio ver will not create .h/.m file anymore?
Kind regards
I am sorry for this dumb question.
I still do not have any header file nor m file.
However, when I double clicked storyboard, I saw header and m file.
I used to open storyboard file on Xcode because I did not have an option to open from Visual Studio even though I right-clicked storyboard file like "open -> Xcode interface builder" stuff.
Anyway, the issue was resolved.
Case closed.
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.
I have 2 classes, an NSObject and an NSView. No AppDelegate.
I was getting a hard error "method definition not in #implementation context" even though the methods were between #implementation and #end. Moving a #import ahead of #implementation eliminated that but then variables from the other file were not known. To get rid of it, I wound up // commenting out all the code lines in both .h and .m files. There's no code left except #interfaces, #implementations, and #ends.
I still get a warning "#end must appear in implementation context." One of them appears immediately after the #end!
I have not attempted to use IB in this program.
Other programs compile correctly, and I think the code is correct in his one and it should work.
Is there some way the compiler gets stuck? OSX 10.6.8, Xcode 3.2.6.
I gave up on that project, created a new project, and copied and pasted the text from the bad one. The new project works fine with the same old text.
Then I ran memtest repeatedly and Applejack to clean up. The hardware is ok.
Probably the compiler is flaky; I've had to do this a couple times this year. Last time an error message said that the compiler had a partition problem; Google links said to upgrade and maybe the new version would fix the problem. So I installed Xcode 3.2.6, which produced the same error, unfortunately. Copy and paste to a new project was necessary, again.
I'm making a simple dialog in XCode 4 using the Interface Builder. I have three NSButtons, all of which are hooked up to their relevant IBOutlets. However I have an NSTextView, which I'd also like to hook up. I have the declaration for it in MyDialog.h:
#interface MyDialog : NibLoaderOC {
#public
IBOutlet NSTextView* tv;
IBOutlet NSButton* acceptButton;
IBOutlet NSButton* editButton;
IBOutlet NSButton* rejectButton;
}
#end
But when I drag the 'New Referencing Outlet' line over tv, it won't highlight. If I try and make a new outlet, it says:
Could not insert new outlet connection: Could not find any information for the class named MyDialog
I have tried restarting XCode, this does nothing. What am I doing wrong?
I noticed that .m file was moved inside en.lproj folder.
Just delete (reference only) the .m file from the Xcode and moved .m out of the en.lproj.
Add it again.It will fix the issue.
Don't worry, you will get all your connections back.
Although I'd still be interested in a proper solution, I fixed this by just manually editing the xib code to create the link.
This has the unfortunate side-effect of Interface Editor refusing to play nicely with the file (although all my manual edits were correct, and the code compiles and runs perfectly).
i got this bug in xcode 4.6.0. restarting xcode didn't fix it for me. deleting the derived data for the project, then restarting xcode did fix it.
delete /Users/myusername/Library/Developer/Xcode/DerivedData/MyProject
Another thing to check for is to make sure that if you have a custom class that you specify it under "Custom class" in the Identity inspector of Interface Builder.
So for instance if you have the following declaration
#interface MyViewController : UIViewController {
#public
IBOutlet MyCustomView* aCustomView;
}
#end
Make sure you add that into the inspector as pictured. Otherwise I've found that you won't be able to hook it up.
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 :-)