I've created a class using XCode3.2.1 and I want to make it inherit from NSViewController (or any other AppKit entity) .
#import < Cocoa/Cocoa.h>
#interface myCustomView : NSViewController {}
#end
I've linked in the Cocoa libraries, but I get the error that it can't find the class header file
Undefined symbols: "_OBJC_CLASS_$_NSViewController", referenced from:
_OBJC_CLASS_$_myCustomView in myCustomView.o
I have other classes in my project that are inherit Cocoa classes without a problem. I don't have any errors if I make it inherit from classes that are part of Framework or CoreData (eg NSObject, NSArray, NSEntityDescription).
Any suggestions?
Check if your subclassed NSViewController implementation file is in the "Compile sources" build phase of your active target.
Somehow the some of the Frameworks become disconnected in XCode.
Under if you control-click Frameworks and select GetInfo, it the
box had a dash through it (meaning it was partially selected).
Clicking it again activated it for all classes.
Related
I have imported an Objective-C library with its entire source code in my Xcode project. The recommended way of using this library is to subclass its main object and customise its behaviour. The problem is that this superclass has many properties declared in the .m through the well known mechanism:
#interface BGRichTextEditorViewController ()
#property (strong) NSString *theString;
#end
This way, they are invisible by my subclass, and all I can do is either change the code of the library and move the properties to the .h or use valueForKey to access the superclass properties from the subclass. Is there a more elegant way to solve this ? Many thanks
That is a class Extension. The public interface is in the header file, and the private properties are hidden from you. It is by design by whoever wrote the library.
If you work around this with valueForKey you might very well find your code breaking on a new release of the library (They are usually private for a reason).
If you have the source code and don't need to be on the bleeding edge release, I would simply fork the library and make your own changes.
Xcode has a new "fix-it" feature for automatically implementing protocol methods. Here is an example:
MFMessageComposeViewControllerDelegate has only a single method. However, when I click "fix" button, Xcode creates MANY irrelevant method stubs:
I haven't added any new other protocols, it's just as follows:
#interface TUDiscoverInviteViewController ()<CNContactPickerDelegate, MFMessageComposeViewControllerDelegate>
#end
My view controller only derives from UITableViewController. Where are those method stubs coming from and how can I prevent this behavior?
I'm on Xcode 9.2.
UITableViewController conforms to UITableViewDataSource and UITableViewDelegate, so you get those method stubs too.
I don't see a way to get Xcode to only generate stubs for one protocol, except by temporarily removing the other protocols and changing your base class.
If you use AppCode, then you can use AppCode's Code > Generate > Implement Methods interface to select which members you want stubs for:
I created a new embedded framework. Within the framework I created a class called "WBButton", which is a subclass of UIButton. I have set the IB_DESIGNABLE and added IBInspectable attributes to allow configuration through Interface builder, as explained here.
It works fine when I test it from within my framework (by adding a sample .xib and placing the button on the screen), but when adding the custom button to a nib located on the project which contains the framework, I get a "Build Failed" message next to the "Designables" (see below).
Also, what does "Module" mean in Interface builder?
Xcode 6 has a bug that breaks IB_DESIGNABLE classes defined in static library or framework. The same is with CocoaPods which use static library for all Pods.
It seems this is an Xcode bug
Temporary workaround:
Create an empty category/extension in the target that contains the storyboard or nib you want to use the designable view in.
Swift:
extension CustomView {
}
Objective-C:
//.h
#interface CustomView (Category)
#end
//.m
#implementation CustomView (Category)
#end
#Andy's comment above is correct answer if you use CocoaPods and your custom library is not working, you need to uncomment use_frameworks! in your Podfile and "pod install" again.
Apparently the "IB_DESIGNABLE" is not recognized by XCode if you don't do this.
I created a custom NSTextView subclass called JWTextView. It's part of a separate Xcode project. That project has a target that creates a static library containing this class. I now added this subproject to my main project under MainProject/Libraries/JWKit (in Finder) and added it in Xcode as well. I made my main project's target depend on the subproject's library target and I'm linking the library in my main target. I also added MainProject/Libraries/** to the Library and Header search paths.
Now I'm trying to use this view in my main project. I added an NSTextView to one of my xib's and changed its class to JWTextView. I also have an IBOutlet JWTextView in my code and call some methods on it upon user interaction. JWTextView.h is imported. Everything compiles file.
But once I call a method on this text view that I implemented in my JWTextView subclass, the app crashes with an unrecognized selector error:
-[NSTextView myCustomMetod:]: unrecognized selector sent to instance 0x101901a80
I checked, and it's actually an NSTextView instance, even tough the ivar is a JWTextView and I set the class in IB.
If I just add the classes to my main project it works fine, but not as a subproject and a static library.
The compiler optimized it out, because I wasn't referencing the class anywhere by name (except the ivar, which doesn't seem to help).
Adding [JWTextView class]; to applicationDidFinishLaunching: fixed the problem.
I'm trying to learn some of the basics of developing OS X apps with XCode and Objective-C, but I am already running into problems.
I have a project I made from a while back which worked very well for me, however, when I try to replicate the results I had last time, I run into numerous errors.
I have two files, a .c and a .h named "AppDelegate"
in AppDelegate.h:
#import <Cocoa/Cocoa.h>
#import <WebKit/WebView.h>
#interface AppDelegate : NSObject {
IBOutlet WebView *gameFrame;
}
#end
then, in AppDelegate.c:
#import "AppDelegate.h"
#implementation AppDelegate
-(void)awakeFromNib
{
}
#end
In IB, there is an NSObject named 'AppDelegate' and its class is 'AppDelegate'.
However, when I try to run this, I get 11734 errors...
When I click on the error icon at the bottom of the XCode window, it lists a bunch of code that seems to be involving NSStrings, but I cant make any sense of it...
Also, within my code, the
#end
line in both the .c and the .h are highlighted with an error saying:
'Expected identifier or '(' before '#' token.'
I don't understand what XCode is tripping up on when it tries to compile, I don't see any logical place for a '(' to go and I don't think I left anything unidentified.
Any help would be appreciated.
That's because that isn't valid C code.
You named your module file AppDelegate.c, which indicates that it contains source code written in (more or less) pure C. But it does not: You wrote a class interface and implementation in Objective-C, which is a superset of C (all C is valid Objective-C, but not all Objective-C is valid C—in particular, classes aren't).
For this, you must name the module file AppDelegate.m (or anything else, as long as it ends with .m; naming it after the class is a convention worth following). The .m suffix indicates a module (usually containing a class implementation) written in Objective-C.
So, just rename your module file from AppDelegate.c to AppDelegate.m. Make sure you do this in Xcode, not the Finder: If you do it in the Finder, Xcode will only care that there is no longer a file named AppDelegate.c; it won't notice the rename.
For your convenience in creating future classes, Xcode provides a template in the “New File” panel for creating subclasses of certain Cocoa classes; your AppDelegate should be a subclass of NSObject, and templates are also provided for NSView, NSDocument, UIView, UIViewController, and a few others. The files created by the template will already have the correct extensions.