I can't find my Xcode "Source" file

Discussion in 'Mac Programming' started by AlbuquerqueApac, Jan 29, 2012.

  1. macrumors member

    Joined:
    Jan 13, 2012
    #1
    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!)
     
  2. macrumors 68040

    Joined:
    Feb 2, 2008
    #2
    Isn't it in File > Add new file or similar? (don't have Xcode here atm).
     
  3. macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #3
    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.
     
  4. macrumors 68000

    Sydde

    Joined:
    Aug 17, 2009
    #4
    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.)
     
  5. thread starter macrumors member

    Joined:
    Jan 13, 2012
    #5
    There isn't a source file for the Objective C foundation? you just add it to your project? Thanks!
     
  6. macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #6
    You mean the foundation headers ? They should be automatically imported in the templates when you create a new project/class.
     
  7. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #7
    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.
     
  8. macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #8
    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.
     
  9. thread starter macrumors member

    Joined:
    Jan 13, 2012
    #9
    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.

    ----------

    n.p.
     
  10. macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #10
    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.
     
  11. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #11
    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?
     
  12. thread starter macrumors member

    Joined:
    Jan 13, 2012
    #12
    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.
     
  13. macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #13
    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.
     
  14. macrumors 68040

    Joined:
    Feb 2, 2008
    #14
    And.. we have come full circle.

    File > New > New File
     
  15. macrumors 603

    Joined:
    Aug 9, 2009
    #15
    As KnightWRX said, I think you still have to import your full circle into your geometry. ;)
     
  16. macrumors 68040

    Joined:
    Feb 2, 2008
    #16
    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.
     
  17. macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #17
    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.
     
  18. thread starter macrumors member

    Joined:
    Jan 13, 2012
    #18
    I did that initially, then corrected it, but Xcode is still saying it cannot find the header file.

    ermmmm...
     
  19. macrumors member

    Joined:
    Feb 2, 2009
    #19
    I think, in this case, a picture really is worth a thousand words. How about some screenshots?
     
  20. thread starter macrumors member

    Joined:
    Jan 13, 2012
    #20
    No, because then I would really be embarassed, lol. Figured it out. :eek:
     
  21. macrumors 68000

    Sydde

    Joined:
    Aug 17, 2009
    #21
    Then maybe you should go up to your OP, click Edit, Click Go Advanced, and set the title prefix to "Resolved"?
     
  22. macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #22
    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.
     
  23. thread starter macrumors member

    Joined:
    Jan 13, 2012
    #23
    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.
     
  24. macrumors Pentium

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #24
    Please post code and exact error messages.
     
  25. thread starter macrumors member

    Joined:
    Jan 13, 2012
    #25
    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"
     

Share This Page