Weird build error,issue with class name? - ios

I'm doing a short project just to experiment writing without the use of nib files (personal interest only, don't plan on never using nibs!).
I have my app controller set up as NSApp's delegate. Under -(void)applicationDidFinishLaunching:(NSNotification *)aNotification, I attempt to initialize the interface.
AppController.h:
#import <Cocoa/Cocoa.h>
#import <QTKit/QTKit.h>
#interface AppController : NSObject {
NSWindow* mainWindow;
QTMovieView* movieView;
QTCaptureSession* mainSession;
QTCaptureMovieFileOutput* output;
QTCaptureDeviceInput* video;
QTCaptureDeviceInput* audio;
}
+ (void)initialize;
- (id)init;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
#end
Method in AppController.m
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
//Proceed to initialize the entire interface:
mainWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(500, 300, 700, 500)
styleMask:(NSTitledWindowMask|NSClosableWindowMask|
NSMiniaturizableWindowMask|NSResizableWindowMask)
backing:NSBackingStoreBuffered
defer:NO];
[mainWindow setTitle:#"Record a movie!"];
/*movieView = [[QTMovieView alloc] initWithFrame:NSMakeRect([[mainWindow contentView] bounds].origin.x + 5,
[[mainWindow contentView] bounds].origin.y + 30,
[[mainWindow contentView] bounds].size.width - 10,
[[mainWindow contentView] bounds].size.height - 35)];*/
[[mainWindow contentView] addSubview:movieView];
[mainWindow makeKeyAndOrderFront:NSApp];
}
The part commented out is the origin of the 1 error that doesn't appear in the text editor, only in the "build" panel:
<pre> ".objc_class_name_QTMovieView", referenced from:
literal-pointer#_OBJC#_cls_refs#QTMovieView in AppController.o
symbol(s) not found
collect2: Id returned 1 exit status
There seems to be a problem with alloc/init'ing an instance here. I can declare a new one just fine, i.e. QTMovieView *test; and nothing complains. I've also found that it does the same thing with all the other QT classes when I try to alloc/init them. However, I was able to alloc/init NSWindow just fine. The framework is in my project and as you can see in my .h file, I included QTKit.
Anyone know what's going on?

The error you're getting is a linker error -- the linker (ld) can't find the framework object code for the QTMovieView class. Therefore, you haven't included the QTKit framework in your project. If you think you have, then something about it isn't set up properly.

Related

Objective-C UIViewController Category is causing Error NSException

I am using a Category to add functionality to my ViewControllers. When the function from the category is run I get an error unrecognized selector sent to instance 0x7970ebf0. To test out the function I'm calling, I originally had the code within my viewDidLoad where I am calling the added function and it worked fine, so I don't think it is a problem with the function itself. So here is my code for the category and where I call it. Am implementing the Category incorrectly?
Here is "UIViewController+StatusBar.h"
#import <Foundation/Foundation.h>
#interface UIViewController (StatusBar)
-(void) addStatusBarBackground;
#end
Here is "UIViewController+StatusBar.m"
#import "UIViewController+StatusBar.h"
#implementation UIViewController (StatusBar)
-(void) addStatusBarBackground(){
//for making the background of the UIStatus bar black
UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, [[self view] bounds].size.width, 22)];
statusBarView.backgroundColor = [UIColor blackColor];
[self.navigationController.navigationBar addSubview:statusBarView];
}
#end
And then I call the function in viewDidLoad of my controller after including UIViewController+StatusBar.h like so
[self addStatusBarBackground]; This is where the error happens, when this is called.
Thanks for the help in advance!
I figured out what I was doing wrong. It ended out to be nothing to do with the category. The category was implemented correctly except for the declaration -(void) addStatusBarBackground(). The parenthesis needed to be deleted. The problem was that I did not select the target memberships that my app has on the right panel in my UIViewController+StatusBar.m file. So the file was not being compiled for my project. I guess its kind of like it wasn't included. I haven't dealt with target memberships before so that was why I was unaware of the problem. Thanks for the comments helping me figure out the answer!

Xcode CodeSense error - Property not found on object of type, but project compiles

I have this in my .pch file:
#import "UIViewController+Loader.h"
The implementation for the category looks like this:
static char kUIViewControllerBaseViewKey;
#implementation UIViewController (Loader)
- (void)setLoader:(LoaderView *)loaderView {
objc_setAssociatedObject(self, &kUIViewControllerBaseViewKey, loaderView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (LoaderView *)loader {
LoaderView *loaderView = (LoaderView *)objc_getAssociatedObject(self, &kUIViewControllerBaseViewKey);
if (!loaderView) {
loaderView = [[LoaderView alloc] initWithView:self.view];
[self.view addSubview:loaderView];
[self setLoader:loaderView];
}
return loaderView;
}
#end
The problem is that in any view controller when I do this:
[self.loaderView doSomething];
Xcode shows this error: Property 'loaderView' not found on object of type MyViewController
HOWEVER, the project compiles fine and the doSomething: method on loaderView works fine. How can I get Xcode to stop showing these errors?
After much head scratching, I found a build setting called "Increase Sharing of Precompiled Headers". Changing this to YES made the problem go away. After reading the description of what this does, I still don't understand why this fixes the problem. But it's fixed.

iOS7 compiler won't recognize method call with message

So this one has me stumped - probably something simple, but I'm clueless.
I'm defining a custom class, containing one method that receives one message (an integer). When calling that method, the compiler refuses to recognize the message I'm trying to send along with the call. ("No known class method for selector 'sendMessage:'. Removing the message from both the call and the definition - i.e. removing the :(int)mode from the definition, and the :1 from the call - allows it to compile fine (but then of course I lose the functionality).
I've tried defining it as an instance method, and as a class method - neither one works.
Many thanks in advance for your collective wisdom!
custom class "Communications.h":
#interface Communications : NSString
+(NSString*)sendMessage:(int)mode;
#end
Communications.m:
#import "Communications.h"
#interface Communications ()
#end
#implementation Communications
+(NSString*)sendMessage:(int)mode {
// Do something important
}
ViewController.h:
#import "Communications.h"
- (void) tapPanic:(UITapGestureRecognizer*)sender;
ViewController.m:
- (void) tapPanic:(UITapGestureRecognizer *)sender {
[Animations animatePanic:self.view type:0];
panicactive = 1;
NSString* tmpResponse = [Communications sendMessage:1];
UILabel* tmpServerResponsePanic = [self.view viewWithTag:10002];
tmpServerResponsePanic.text = tmpResponse;
[[self serverResponsePanic] setNeedsDisplay];
}
So, chalk it up to weirdness with Xcode... copy / pasting the contents of Communications .h and .m into new files, with a new class definition (Comms), did the trick. I think the compiler got confused and was remembering an old definition of the method.

getting a warning setting up delegate for a custom protocol

i added a custom protocol to one of my classes and i am getting a compiler warning when i attempt to set the delegate during a prepareForSegue: method. the warning i get is...
Sending 'MyCustomViewControllerClass *const __strong' to parameter of incompatible type 'id<NSFileManagerDelegate>'
the project builds and runs and everything works fine minus the warning. if i add <NSFileManagerDelegate> to my custom class the warning goes away. am i missing something or is this a bug in Xcode (6 beta)? the code is standard code for setting up a protocol / delegate but i will post it anyways...
SomeSecondClass.h
#import <UIKit/UIKit>
#class SomeSecondCustomViewController;
#protocol SomeSecondCustomViewControllerDelegate <NSObject>
- (void)doThisForMe
#end
#interface SomeSecondCustomViewController : UIViewController
#property (weak, nonatomic) id <SomeSecondCustomViewControllerDelegate> delegate;
#end
SomeSecondClass.m
#interface SomeSecondViewController ()
…stuff
-(void)someMethod {
[self.delegate doThisForMe];
}
#end
CustomClass.h
#import <UIKit/UIKit.h>
#import “ SomeSecondViewController.h”
#interface MyCustomViewController : UIViewController <SomeSecondCustomViewControllerDelegate>
//adding on <NSFileManagerDelegate> removes the warning...
#end
CustomClass.h
...standard stuff...
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"MySegue"]) {
//this is where the warning happens on "self"
[segue.destinationViewController setDelegate:self];
}
}
- (void)doThisForMe {
//doing some stuff...
}
#end
i have opened previous projects where the warning did not exist and now the same warning appears. i am wondering if this is an Xcode problem?
You are running into an issue caused by an ambiguity in how Objective-C finds a matching selector and dealing with an id reference.
UIStoryboardSegue destinationViewController returns an id. Your code then tries to call the setDelegate method on this id reference. Since there is no information about what this id actually references, it doesn't know which setDelegate: method you might mean (there are many). So the compiler scans through the list it knows of and picks one. In this case it chose the setDelegate: method from the NSFileManager class. Since self doesn't conform to the NSFileManagerDelegate protocol, you get the warning.
You could ignore the warning and your code will work fine in this case.
The better solution is to help the compiler by adding a cast:
[(SomeSecondCustomViewController *)segue.destinationViewController setDelegate:self];
This will let the compiler know which setDelegate: method you really mean.
BTW - Adding NSFileManagerDelegate to your class is not a valid solution even if it works at the moment. A simple reordering of some import statements could lead the compiler to make a different choice and your warning would return but complain about not conforming to some other protocol.
as it turns out, this is a bug / change in Xcode 6 beta. running this exact same code on Xcode 5.1.1 produces no warnings or errors. the problem is cause because in Xcode 6 the compiler is asking for type
(id<NSFileManager>)
for the delegate. in Xcode 5.1 the compiler is simply expecting
(id)
for the delegate type.
as rmaddy stated, by casting the type in
[(SomeSecondCustomViewController *)segue.destinationViewController setDelegate:self];
it did remove the warning, but this should be an unnecessary step and will chalk it up to a problem with Xcode.
Try explicitly typing (giving type to) the destinationVC, like this:
SomeSecondCustomViewController *vc = (SomeSecondCustomViewController *)segue.destinationViewController;
vc.delegate = self;
#rmaddy provides the correct answer. This is a more detailed example for those of us who are lightly schooled in the ways of Objective-C.
I changed my code from:
[[segue destinationViewController] setDelegate:self];
UIPopoverController *popoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
self.flipsidePopoverController = popoverController;
popoverController.delegate = self;
to:
[(UIPopoverController *)segue.destinationViewController setDelegate:self];
UIPopoverController *popoverController = [(UIStoryboardPopoverSegue *)segue popoverController];
self.flipsidePopoverController = popoverController;
popoverController.delegate = self;
and the warnings disappeared.

Why can't I convert this PDFMaker from xib to storyboard?

I need this small PDFMaker code in my larger code project, which is almost done expect for the PDFMaker. My larger project is all done in storyboard, and the PDFMaker in xib. I didn't see how you could do them both in the same project. I used the Apple "Converting to Storyboards Release Notes" to convert the PDFMaker from xib to storyboard. Pretty easy and straightforward. However, I can't get either the didClickMakePDF or didClickOpenPDF selectors to work. I keep getting the message
unrecognized selector sent to instance
and a thread pointer to the Main.m file
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MTAppDelegate class]));"
line. I'm new to coding and have been working on this for over 20 hours with no success. All the actions and outlets seem to be set up fine in both the .h, .m, and storyboard files. Could somebody please help me to fix this, or suggestion a different approach to be able to use this PDFMaker code in a storyboard-based project?
Here is my .h file:
#import <UIKit/UIKit.h>
#import "ReaderViewController.h"
#interface MTViewController : UIViewController <ReaderViewControllerDelegate>
- (IBAction)didClickMakePDF:(id)sender;
- (IBAction)didClickOpenPDF:(id)sender;
#end
Here is the relevant part of the .m file for the didClickMakePDF:
- (IBAction)didClickMakePDF:(id)sender {
[self setupPDFDocumentNamed:#"NewPDF" Width:850 Height:1100];
[self beginPDFPage];
CGRect textRect = [self addText:#"This is some nice text here, don't you agree?"
withFrame:CGRectMake(kPadding, kPadding, 400, 200) fontSize:48.0f];
CGRect blueLineRect = [self addLineWithFrame:CGRectMake(kPadding, textRect.origin.y + textRect.size.height + kPadding, _pageSize.width - kPadding*2, 4)
withColor:[UIColor blueColor]];
UIImage *anImage = [UIImage imageNamed:#"tree.jpg"];
CGRect imageRect = [self addImage:anImage
atPoint:CGPointMake((_pageSize.width/2)-(anImage.size.width/2), blueLineRect.origin.y + blueLineRect.size.height + kPadding)];
[self addLineWithFrame:CGRectMake(kPadding, imageRect.origin.y + imageRect.size.height + kPadding, _pageSize.width - kPadding*2, 4)
withColor:[UIColor redColor]];
[self finishPDF];
}
Here is the Main.m file:
#import <UIKit/UIKit.h>
#import "MTAppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([MTAppDelegate class]));
}
}
Your error messages contain the selector didClickMakePDF (with no colon, so no argument) but your code uses the selector didClickMakePDF: (with a colon, so expecting one argument). These are different selectors.
In your storyboard, you need to delete the connections from your buttons to those (incorrect) actions and create connections from the buttons to the correct actions.
UPDATE
Sometimes the storyboard editor (“Interface Builder” or IB) gets out of sync with the source code, remembering methods that you've deleted or ignoring methods that you've created. Here are some things to try, in increasing order of brutality:
Make sure all files are saved. (Command-Option-S saves all files.)
Close all files in the project window by pressing Control-Command-W repeatedly, until the editor window is blank.
Quit and restart Xcode.
Clean your build folder by pressing Option-Shift-Command-K.
Delete your Derived Data folder for the project. Close your project, then open the Organizer window and click on the Projects tab. Click on your project in the left-side list. Then click the Delete… button to the right of the Derived Data line in the right-side pane.
UPDATE 2
When you delete a resource file (like a xib file) from your app and then run the app, Xcode doesn't delete the resource file from the app installation on the simulator or device. You need to delete the app entirely from the simulator or device (in the usual way, by making the icons wiggle and then tapping the X button) to remove the obsolete xib file.

Resources