Xcode does not recognise methods added through categories - objective-c

I've created a category to add methods to NSManagedObjectModel. Everything works fine except Xcode keeps throwing warnings about NSManagedObjectModel not implementing the methods. How can I force it to recognise the method?

Did you #import the .h of the category?

Related

IB_DESIGNABLE build failed when using class from within a framework

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.

Compile Warnings About Missing #required Protocol Methods NOT Appearing

I was tinkering with XCode 4.5.2 this morning and wanting to make a table view I naturally added the UITableViewDataSource and UITableViewDelegate protocols to one on my view controller definitions.
#import <UIKit/UIKit.h>
#interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
#end
#import "MyViewController.h"
#implementation MyViewController
#end
Now I know at this stage I need to implement the #required methods of the UITableViewDataSource protocol but out of (presumably TDD) habit I decided to perform a build first with the expectation that the compiler would throw up warnings about the unimplemented #required methods (indicating to me which ones to implement).
But NO the build completed without a single error or warning from the compiler which has confused and concerned me slightly.
So I realize this question is normally the other way round i.e. 'why I am getting this warning', instead of 'why am I NOT getting this warning' but this really simple issue has really baffled me. Clearly I'm doing something wrong but I've no idea what. Any ideas how this might be possible?
FYI this a new project with no build/project setting customisation on a brand new clean install of XCode 4.5.2 on a new Mac Book.
In XCode 4.5.x there is a option for setting different warnings to display (YES/NO). You can check it under build setting Compiler Warnings for LLVM 4.1 compiler.
I hope it'll resolve your issue.

how to access a newly created class in objective c

I get the feeling that this is a very stupid question, but I cannot find an answer anywhere. I've created a new class in an XCode project called "Word", with its own .h and .m files, which inherits from NSString, and has its own declared instance variable, method, etc. How do I access it within the viewcontroller.h and .m files? I though it would just show up in the little suggestion box in XCode, like the pre-made classe, but it doesn't. How do I use my new class?
#import "Word.h"
I will note that subclassing NSString is extremely uncommon and almost never what you mean to do. You probably meant to have Word have an NSString property.
in your .h, at the top type #import " then start typing Word.h. It should autocomplete if the .h and .m files are in your project correctly.
You just need to add the following to your ViewController.h
#import "Word.h"

XCode Throwing Errors #implementation

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.

Objective C, Core Data issue

I'm following a tutorial in "More iPhone 3 Development. In the code, they have a line:
NSManagedObjectContext *managedObjectContext = appDelegate.managedObjectContext;
I get an error: "accessing unknown 'managedObjectContext' getter method" on that line.
I've downloaded his sample code and his program runs fine with that line of code. I've tried rewriting the code and I've even copied and pasted his code into my program, but I still get the error.
I am using the newest SDK, and I'm wondering if something might have changed so this getter method doesn't work anymore, but I do not get any warning about deprecation.
Does anyone know what is going on, or better yet, a better way to write this line and not get the error.
Thanks
LadyDev
When you create a core data project there's a method that is automatically created for you...
- (NSManagedObjectContext *) managedObjectContext
That's your AppDelegate's getter method for the managed object context. Also in the header file you will see that getter method defined:
#property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
So make sure you AppDelegate has these then you should not have that problem.
I had the same problem, i found that when I created the project it put 3 #property declarations in the SuperDBAppDelegate.m file which may be a new way of doing it i'm not quite sure. Anyway I took it from there and put it in the .h file and that fixed the error, however now I have other issues which I am still debugging but hopefully that works for you.