PDA

View Full Version : I can't find my Xcode "Source" file




AlbuquerqueApac
Jan 29, 2012, 08:13 AM
I'm trying to add a new class but I Can't seem to find my "Source" file through Xcode to add my new class definition.

Can anyone help!

(and PLEASE! PLEASE! if you're going to go on a rant about "Teaching", please just skip on by. Thanks!)



subsonix
Jan 29, 2012, 08:48 AM
Isn't it in File > Add new file or similar? (don't have Xcode here atm).

KnightWRX
Jan 29, 2012, 08:49 AM
Maybe you could post a screenshot of what you mean. What source file ? Adding a class to your project is basically just going File->New->New File for a brand new class you're going to write, or File->Add Files to "Project" to get a open file dialog to select your existing files.

Sydde
Jan 29, 2012, 03:31 PM
If you know where the .h and .m files are, you can grab them in Finder and drag them into the Xcode sidebar, whereupon you will get a dialog asking whether you want to copy them. At least, that is how Xcode 3 works. (This is not the same as importing a framework.)

AlbuquerqueApac
Jan 29, 2012, 08:24 PM
Maybe you could post a screenshot of what you mean. What source file ? Adding a class to your project is basically just going File->New->New File for a brand new class you're going to write, or File->Add Files to "Project" to get a open file dialog to select your existing files.

There isn't a source file for the Objective C foundation? you just add it to your project? Thanks!

KnightWRX
Jan 29, 2012, 08:31 PM
There isn't a source file for the Objective C foundation? you just add it to your project? Thanks!

You mean the foundation headers ? They should be automatically imported in the templates when you create a new project/class.

gnasher729
Jan 30, 2012, 06:45 AM
I'm trying to add a new class but I Can't seem to find my "Source" file through Xcode to add my new class definition.

Can anyone help!

(and PLEASE! PLEASE! if you're going to go on a rant about "Teaching", please just skip on by. Thanks!)

Let's come to the teaching bit: If you don't know what you are talking about (like asking for "my source file" when you are really looking for a "Apple's header file"), you should give as much information as possible about what you are doing, so that people have a chance of figuring out what you actually want.

And that's not directed at _you_, so just skip it. It is directed at anyone else who needs help _and_ is willing to learn.

KnightWRX
Jan 30, 2012, 07:02 AM
And that's not directed at _you_, so just skip it. It is directed at anyone else who needs help _and_ is willing to learn.

And I thought I was rough. :D

A good point really. OP, I made nothing of your quip, but really, you need to realise that teaching is better than giving out answers if you want to learn, not just have other people do your work for you.

AlbuquerqueApac
Jan 30, 2012, 08:35 AM
Let's come to the teaching bit: If you don't know what you are talking about (like asking for "my source file" when you are really looking for a "Apple's header file"), you should give as much information as possible about what you are doing, so that people have a chance of figuring out what you actually want.

And that's not directed at _you_, so just skip it. It is directed at anyone else who needs help _and_ is willing to learn.

Ok, so I don't have to add my classes to the framework files? I.e. Mac Framework or iOS framework.

in other words, do I add my new header and implementation file to my project file, or does it need to be in a library?

Also, I was referring to a library, not a header file or implementation file.

----------

And I thought I was rough. :D

A good point really. OP, I made nothing of your quip, but really, you need to realise that teaching is better than giving out answers if you want to learn, not just have other people do your work for you.

n.p.

KnightWRX
Jan 30, 2012, 09:10 AM
Ok, so I don't have to add my classes to the framework files? I.e. Mac Framework or iOS framework.

in other words, do I add my new header and implementation file to my project file, or does it need to be in a library?

Also, I was referring to a library, not a header file or implementation file.

I don't quite get what you're trying to do here. You're creating a library ? You're writing an Application ? What is your project exactly ?

You don't add your project to existing frameworks, you link against them. Your project is your project, you're going to distribute it seperately from the base frameworks or even other frameworks.

As for your new header files, you have to manually "#import" or "#include" them depending on what parts of your code requires them (other classes/source files).

Maybe again, you could properly define for us what you mean/what you're trying to do so we can actually offer proper guidance here. It's all left to guess work right now as to what you actually mean.

gnasher729
Jan 30, 2012, 09:54 AM
Ok, so I don't have to add my classes to the framework files? I.e. Mac Framework or iOS framework.

in other words, do I add my new header and implementation file to my project file, or does it need to be in a library?

Also, I was referring to a library, not a header file or implementation file.


How is anyone supposed to know what you are referring to? What you _wrote_ was that you couldn't find your source file. It now looks like you don't have any source files yet (but that is mostly guessing). This is the first time that you used the word "library", so please think about this: How is anyone supposed to know that you are referring to a library if you don't say so?

What about telling us what it is that you want to achieve? What you are doing so far is like asking "should a put my foot on the gas pedal or on the brake pedal"? How am I supposed to know if you don't tell us whether you want the car to accelerate or to slow down?

AlbuquerqueApac
Jan 30, 2012, 10:25 AM
I'm sorry guys, I'm not explaining myself very well and I apologize.

I'm trying to write my own class (*.h and *.m files) and be able to import those into my project. Xcode keeps saying it cannot find the files I'm asking for. I assumed I needed to have them in a library so it could find them.

Anyway, gnasher, if I haven't totally ticked you off, I'm just trying to do what I stated above.

KnightWRX
Jan 30, 2012, 10:56 AM
I'm sorry guys, I'm not explaining myself very well and I apologize.

I'm trying to write my own class (*.h and *.m files) and be able to import those into my project. Xcode keeps saying it cannot find the files I'm asking for. I assumed I needed to have them in a library so it could find them.

What have you done and tried and what is the exact error message you're getting ?

Adding your own class has been covered, if it's a new class, it's File->New->New File, or File->Add Files to "Project" to get a open file dialog to select your existing files if this class is already written.

This adds it to your project. Nothing else to do, the build settings will automatically reflect your new code. Then you simply #import the proper header file into the code that needs to reference this class.

Let's say your new class is Circle, and you need to reference it from Geometry, you simply #import "Circle.h" in Geometry.h.

There's nothing more to it.

subsonix
Jan 30, 2012, 11:00 AM
I'm sorry guys, I'm not explaining myself very well and I apologize.

I'm trying to write my own class (*.h and *.m files) and be able to import those into my project.

And.. we have come full circle.

File > New > New File

chown33
Jan 30, 2012, 11:08 AM
And.. we have come full circle.

As KnightWRX said, I think you still have to import your full circle into your geometry. ;)

subsonix
Jan 30, 2012, 11:12 AM
As KnightWRX said, I think you still have to import your full circle into your geometry. ;)

Strictly speaking doing the above makes them part of the project, which means you can make references to them in other source files. But the latter part is not really specific to Xcode.

KnightWRX
Jan 30, 2012, 11:23 AM
Strictly speaking doing the above makes them part of the project, which means you can make references to them in other source files. But the latter part is not really specific to Xcode.

And I'm betting the OP is having problems with the latter part. He's probably trying to import his header with :

#import <mycustomheader.h>

instead of :

#import "mycustomheader.h"

Which we would know if the OP had posted screenshots or exact error messages, or even a detailed post about what he's trying to achieve and what he's done up to now.

AlbuquerqueApac
Jan 30, 2012, 03:44 PM
I did that initially, then corrected it, but Xcode is still saying it cannot find the header file.

ermmmm...

phantax
Jan 30, 2012, 03:56 PM
I think, in this case, a picture really is worth a thousand words. How about some screenshots?

AlbuquerqueApac
Jan 30, 2012, 04:23 PM
No, because then I would really be embarassed, lol. Figured it out. :o

Sydde
Jan 30, 2012, 06:24 PM
No, because then I would really be embarassed, lol. Figured it out. :o

Then maybe you should go up to your OP, click Edit, Click Go Advanced, and set the title prefix to "Resolved"?

KnightWRX
Jan 30, 2012, 07:11 PM
No, because then I would really be embarassed, lol. Figured it out. :o

It is good etiquette to post the solution to a problem for any other posters searching for similar problems and coming up on your thread.

You got helped, now it's your turn to pass along the help to others. There's nothing to be embarassed about here, we've all made mistakes that seemed so obvious to fix after we've put our finger on the problem but at the time seemed impossible to get working right.

AlbuquerqueApac
Jan 31, 2012, 10:47 AM
Well, it was that I didn't add my header file to the correct project.


BUT.....My compiler is not recognizing the @synthesize directive for my accessor methods.

in my main.m file, I'm getting an error that it doesn't recognize my accessor methods on my object.

I have the #import "Fraction.h" at the top of my method and the implementation file defined as well.

KnightWRX
Jan 31, 2012, 11:20 AM
My compiler is not recognizing the @synthesize directive for my accessor methods.

in my main.m file, I'm getting an error that it doesn't recognize my accessor methods on my object.

I have the #import "Fraction.h" at the top of my method and the implementation file defined as well.

Please post code and exact error messages.

AlbuquerqueApac
Jan 31, 2012, 06:46 PM
//
// main.m
//
//
//
//

#import <Foundation/Foundation.h>
#import "Fraction.h"






int main (int argc, const char * argv[])
{

@autoreleasepool {


//testing out my new fraction class

Fraction *mf;
mf=[[Fraction alloc]init];

[mf setnumerator: 5];
[mf setdenominator: 6];








}
return 0;
}



my header




//
// Fraction.h
//
//
//
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface Fraction : NSObject

@property int numerator, denominator;

-(void) print;
-(double) convertToNum;



@end







//
// Fraction.m
//

#import "Fraction.h"

@implementation Fraction

@synthesize numerator, denominator;

-(void) print
{
NSLog(@"%i/%i", numerator, denominator);

}

-(double) convertToNum
{
if (denominator != 0)
{
return (double) numerator/denominator;

}
else
{
return NAN;

}


}



@end








The error message I'm getting is: "Receiver type "Fraction" for instance message does not declare a method with selector "set numerator" and "set denominator"

AlbuquerqueApac
Jan 31, 2012, 06:57 PM
Ok, I figured it out. It seems if you exit Xcode and re-enter it Xcode recognizes my class.

Sydde
Feb 1, 2012, 03:50 AM
// main.m

#import <Foundation/Foundation.h>
#import "Fraction.h"

int main (int argc, const char * argv[])
{

@autoreleasepool {


//testing out my new fraction class

Fraction *mf;
mf=[[Fraction alloc]init];

[mf setnumerator: 5];
[mf setdenominator: 6];
}
return 0;
}


The error message I'm getting is: "Receiver type "Fraction" for instance message does not declare a method with selector "set numerator" and "set denominator"

Curious: what happens if you change the spelling of the blue method selectors to "setNumerator" and "setDenominator"?