Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AlbuquerqueApac

macrumors member
Original poster
Jan 13, 2012
47
0
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!)
 
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.
 
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.)
 
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!
 
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.
 
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.
 
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.
 
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.
 
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?
 
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.
 
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.
 
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.
 
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 :

Code:
#import <mycustomheader.h>

instead of :

Code:
#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.
 
I did that initially, then corrected it, but Xcode is still saying it cannot find the header file.

ermmmm...
 
I think, in this case, a picture really is worth a thousand words. How about some screenshots?
 
No, because then I would really be embarassed, lol. Figured it out. :eek:

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.
 
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.
 
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.
 
Code:
//
//  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

Code:
//
//  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


Code:
//
//  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"
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.