Thursday, September 24, 2009

Instantiation

Plus signs denote class methods, minus signs denote instance methods.
Class methods have no access to instance variables.
@implementation classname
+classMethod {
// implementation
}
-instanceMethod {
// implementation
}
@end


/////

Instantiation

Once an Objective-C class is written, it can be instantiated. This is done by first allocating the memory for a new object and then by initializing it. An object isn't fully functional until both steps have been completed. These steps are typically accomplished with a single line of code:

MyObject * o = [[MyObject alloc] init];

The alloc call allocates enough memory to hold all the instance variables for an object, and the init call can be overridden to set instance variables to specific values on creation. The init method is often written as follows:

-(id) init {
self = [super init];
if (self) {
ivar1 = value1;
ivar2 = value2;
.
.
.
}
return self;
}

////

Properties are implemented by way of the @synthesize keyword, which generates getter and setter methods according to the property declaration. Alternately, the @dynamic keyword can be used to indicate that accessor methods will be provided by other means.

Tuesday, September 22, 2009

Cocos2d

In Cocos2d iPhone you'll be dealing with the Scene and Layer classes frequently. A Scene is what the players can see at a given time, and is composed of one or more Layers. To display a specific Scene, you tell the Director (which is a singleton) to play it.

Friday, September 18, 2009

kaminey Night

CGAffineTransform

Any change to a view's position, scale, or rotation can now be stored in a property of the view called transform. It's a CGAffineTransform struct, and it's a bit cryptic if you've never worked with transformation matrices before.

A transformation matrix nothing more than a two-dimensional array of numbers. Okay, perhaps I shouldn't say "just", as transformation matrices are quite powerful. They can store complex changes to the position and shape of an object, including rotating, scaling, moving, and skewing (or shearing) the view as it's drawn. This adds a little bit of programmer complexity if you want to do anything more than the absolute basics, but it opens up a world of possibilities.


To translate a view from its current position, you would pass the view's transform property here. To translate the view from its original position, you would pass in CGAffineTransformIdentity. Here is an example that would move the view five points to the right and ten points down.

theView.transform = CGAffineTransformTranslate(theView.transform, 5.0, 10.0);

Monday, September 14, 2009

interface rotation based on hand movement

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;//(interfaceOrientation == UIInterfaceOrientationPortrait);
}

Tuesday, September 8, 2009

IPHone timer Event

objectmoveTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(objectTimer) userInfo:nil repeats:YES];

-void(objectTimer)
{

// THis is execute Continously // since repeat is set to Yes :)
}

Monday, September 7, 2009

running Apps

in the "target " go to properties and set identifier as "com.ihexcode.first"
and add .mobileprovision and Distribution to your project

Friday, September 4, 2009

Thursday, September 3, 2009

Defining a Class

Defining a Class

Much of object-oriented programming consists of writing the code for new objects—defining new classes. In Objective-C, classes are defined in two parts:

*

An interface that declares the methods and instance variables of the class and names its superclass
*

An implementation that actually defines the class (contains the code that implements its methods)





/////////////////////////
Although the compiler doesn’t require it, the interface and implementation are usually separated into two different files. The interface file must be made available to anyone who uses the class.

A single file can declare or implement more than one class. Nevertheless, it’s customary to have a separate interface file for each class, if not also a separate implementation file. Keeping class interfaces separate better reflects their status as independent entities.

Interface and implementation files typically are named after the class. The name of the implementation file has the .m extension, indicating that it contains Objective-C source code. The interface file can be assigned any other extension. Because it’s included in other source files, the name of the interface file usually has the .h extension typical of header files. For example, the Rectangle class would be declared in Rectangle.h and defined in Rectangle.m.

Separating an object’s interface from its implementation fits well with the design of object-oriented programs. An object is a self-contained entity that can be viewed from the outside almost as a “black box.” Once you’ve determined how an object interacts with other elements in your program—that is, once you’ve declared its interface—you can freely alter its implementation without affecting any other part of the application.

/////////////
Class Interface

The declaration of a class interface begins with the compiler directive @interface and ends with the directive @end. (All Objective-C directives to the compiler begin with “@”.)

@interface ClassName : ItsSuperclass

{

instance variable declarations

}

method declarations

@end


////
The first line of the declaration presents the new class name and links it to its superclass. The superclass defines the position of the new class in the inheritance hierarchy



////
If the colon and superclass name are omitted, the new class is declared as a root class, a rival to the NSObject class.






///////////////////////
Inheritance

Class definitions are additive; each new class that you define is based on another class from which it inherits methods and instance variables. The new class simply adds to or modifies what it inherits. It doesn’t need to duplicate inherited code.

Inheritance links all classes together in a hierarchical tree with a single class at its root. When writing code that is based upon the Foundation framework, that root class is typically NSObject. Every class (except a root class) has a superclass one step nearer the root, and any class (including a root class) can be the superclass for any number of subclasses one step farther from the root. Figure 1-1 illustrates the hierarchy for a few of the classes used in the drawing program.

Some Drawing Program Classes

FEEDJIT Live