Showing posts with label Objective-C Tutorial. Show all posts
Showing posts with label Objective-C Tutorial. Show all posts

Sunday, July 3, 2011

Mixing C or C++ function with Objective-C

As you can see in the screenshot that C++ methods (e.g. GLuint BuildShader(const char* source, GLenum shaderType) ) are written above @implementation in objective-C .m file.
I am not saying this is the only way but this is one of the ways I use to mix the C++ methods with my objective-C code.



Wednesday, June 29, 2011

Integrating C++ files with Objective-C (tips)

This trick will be helpful for people who are trying to embed Opengl ES code in their iPhone project.
One way to let your compiler know that you will be using mix of C++ and objective-C will be to convert the extension of all .m files to .mm as discussed in one the previous post(LINK) but there is another way if you don't want to change all the extensions  !


In your project Settings, Under Build Settings > GCC 4.2- Language
Change the "Compile Source As" value to "Objective-C++"
































It will let you compile the code without changing the extensions of all the files.

I found this wonderful tip from Pete Cole blog. LINK

Thursday, June 16, 2011

Copy items of NSMutableArray into another ?

Lets say you have arrayA and arrayB, arrayB could be NSArray or NSMutableArray.
But arrayA should be mutable.


  [arrayA addObjectsFromArray:arrayB];





Here you are copying items from  arrayB to arrayA. Make sure you have already alloc memory for arrayA as:

arrayA = [[NSMutableArray alloc]init];




Case 2: If you want to create a copy an array to NSArray, you can do so as following:

NSArray *db=[[NSArray alloc]initWithArray:availListArray];



Tuesday, June 14, 2011

Private and Public Variables in Objective-C




    @interface MIMClass : NSObject
    {
        @private
        int _privateVar; //BY convention I usually put _ in front of private variables.
        


        @protected      
        int _myVar; //By default, every variable you define is in protected mode so if you don't          write protected above your variables, they are by default in protected mode.

        @public
        int publicVar;  // Can be accessed by any object,view
    }
    @end







I guess the code above pretty much explains how you can declare the private and public members in Objective-C