Why can't I set a referencing outlet for my NSTextView in XCode 4? - interface-builder

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.

Related

File's Owner 'view' outlet not showing

I created a project in Xcode 6 beta 2, which initial had a storyboard. I wanted to work with separated xibs so I removed storyboard and line related to storyboard from Info.plist and added several xibs. Now the problem is that I can't connect file's owner 'view' outlet (because it's not visible) to view from xib. First thought was that I misspelled name of the file's owner custom class name (from Identity Inspector), but I didn't. Also file's owner class is a UIViewController child. I don't know that the problem can be. Did some faced this issue ?
It's probable that you need to close Xcode, clean the project and try again. I created a new project without storyboards and I did the following:
1) I created the nib file.
2) I created the UIViewController class.
3) I opened the nib and selected the File's owner tab. Then I wrote the name of the custom UIViewController class.
4) Without selecting the file's owner tab on the Placeholders left bar (make sure of this) go to Connections inspector tab and you should see the view outlet.
Simply cleaning, quitting Xcode and re-opening fixed it for me.

After localization: Unable to find nib named ... in bundle path: (null)

I'm starting to get into Mac OS X development and I have a problem the solution to which I haven't been able to figure out for the last three hours (I've googled a long time).
Test application:
I have an application that has a MainMenu.xib, which displays a window - so far so good. I've created another XIB and NSViewController subclass that contains a view which I want to display within the main window. I use the following code to load the view and insert it into the main window:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
self.compartmentViewController = [[SelectCompartmentViewController alloc] initWithNibName:#"SelectCompartmentViewController" bundle:nil];
[self.compartmentViewController.view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[self.compartmentViewController.view setFrame:[self.contentArea bounds]];
}
compartmentViewController is a property and self.contentArea is a custom view on the main window - like a placeholder.
This works fine so far.
Problem
Then I decided to check out the localization feature. I've localized a couple of strings and both XIBs. At first I was a bit confused by not seeing any localized values. That was until I found out I had to clean the project - since then I've been getting the following error when running:
2013-03-19 22:48:59.763 Vocab Box[10160:303] unable to find nib named: SelectCompartmentViewController in bundle path: (null)
2013-03-19 22:48:59.764 Vocab Box[10160:303] -[NSViewController loadView] could not load the "SelectCompartmentViewController" nib.
Suggested solutions I've tried to no avail
Cleaning the project doesn't help
Checking the build configuration - yes, the bundle resources seem to be ok
Yes, if I remove the localization for my subview and re-add the original XIB, things are fine again (though of course the view is not localized)
Help
I don't have an answer as to why this happens. But I had the same problem, and I fixed it by closing xCode and opening it up again, believe me.
Try the following :
select your project
select "build phases"
add the new xib in the "copy bundle resources"
I just had this same issue and was able to solve it by doing the following:
1) Select the XIB in the project navigator
2) In the File Inspector, uncheck any items under Localization (it will prompt you - make sure 'delete files from disk' is unchecked, and press Remove)
3) Manually add the XIB back into the project

XCode Protocols

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.

Automatic #property synthesize not working on NSManagedObject subclass

After updating to the newest Version of Xcode 4.5 for iOS6 last night, i get Warnings and Errors like this
Property 'mapAnnotation' requires method 'mapAnnotation' to be defined
- use #synthesize, #dynamic or provide a method implementation in this class implementation
because of missing #synthesize Statements, and even Errors about unknown iVars if i use them.
The thing is, i thought it was not necessary to write these #synthesize statements since the last Xcode Update to 4.5 that came out with Mountain Lion, AND all my projects worked without them before i've updated Xcode last night (i've deleted a whole bunch of #synthesize statements from my files back then)
It's even still in the Release-Notes:
• Objective-C #synthesize command is generated by default when using properties.
So i'm confused, am i missing a new Project-Setting that turns automatic #synthesize generation on?
But it's not even working when i create a new Project and try it
I faced the same problem and found the reason and the solution.
If you look at the header file of NSManagedObject in iOS 6 SDK, you'll see "NS_REQUIRES_PROPERTY_DEFINITIONS" which forces classes to specify #dynamic or #synthesize for properties.
(You can see the NS_REQUIRES_PROPERTY_DEFINITIONS in the API diff between iOS 5.1 and iOS 6.0.)
This is because the compiler has to know if you want a property to be dynamic or synthesized especially in the implementation of a subclass of NSManagedObject class.
I could solve this problem simply by adding the #synthesize lines explicitly for the properties other than #dynamic in NSManagedObject subclasses.

Xcode4 Automatic Generation of #property declarations and all that goes with it

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 :-)

Resources