//ob_start();
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") )
{ header("Content-type: application/xhtml+xml;charset=utf-8"); }
else { header("Content-type: text/xml;charset=utf-8"); }
echo "\n";
// Write Code here
ob_get_contents();
//?>
Friday, June 3, 2011
Sunday, May 29, 2011
function with diff parameter
Objective-C program with multiple parameter
Objective-C enables programmer to use method with multiple parameter. These parameter can be of same type or of different type.
This is a sample program that shows sum of three numbers as output.
MyClass.h
#import
@interface MyClass:NSObject{
}
// declare method for more than one parameter
-(int) sum: (int) a andb: (int) b andc:(int)c;
@end
MyClass.m
#import
#import"MyClass.h"
@implementation MyClass
-(int) sum: (int) a andb: (int) b andc:(int)c;{
return a+b+c;
}
@end
MyClass.m
#import
#import"MyClass.m"
int main(){
MyClass *class = [[MyClass alloc]init];
printf("Sum is : %d",[class sum : 5 andb : 6 andc:10]);
[class release];
return ;
}
source rose india
Objective-C enables programmer to use method with multiple parameter. These parameter can be of same type or of different type.
This is a sample program that shows sum of three numbers as output.
MyClass.h
#import
@interface MyClass:NSObject{
}
// declare method for more than one parameter
-(int) sum: (int) a andb: (int) b andc:(int)c;
@end
MyClass.m
#import
#import"MyClass.h"
@implementation MyClass
-(int) sum: (int) a andb: (int) b andc:(int)c;{
return a+b+c;
}
@end
MyClass.m
#import
#import"MyClass.m"
int main(){
MyClass *class = [[MyClass alloc]init];
printf("Sum is : %d",[class sum : 5 andb : 6 andc:10]);
[class release];
return ;
}
source rose india
Monday, May 23, 2011
Difference betwen protocol and category
A protocol is the same thing as an interface in Java: it's essentially a contract that says, "Any class that implements this protocol will also implement these methods."
A category, on the other hand, just binds methods to a class. For example, in Cocoa, I can create a category for NSObject that will allow me to add methods to the NSObject class (and, of course, all subclasses), even though I don't really have access to NSObject.
To summarize: a protocol specifies what methods a class will implement; a category adds methods to an existing class.
The proper use of each, then, should be clear: Use protocols to declare a set of methods that a class must implement, and use categories to add methods to an existing class.
A category, on the other hand, just binds methods to a class. For example, in Cocoa, I can create a category for NSObject that will allow me to add methods to the NSObject class (and, of course, all subclasses), even though I don't really have access to NSObject.
To summarize: a protocol specifies what methods a class will implement; a category adds methods to an existing class.
The proper use of each, then, should be clear: Use protocols to declare a set of methods that a class must implement, and use categories to add methods to an existing class.
Delete Row in UITableView
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{ NSLog(@"matrix is her%@",appDelegate.favDetail);
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[appDelegate.favDetail removeObjectAtIndex: indexPath.row];
[tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
}
{ NSLog(@"matrix is her%@",appDelegate.favDetail);
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[appDelegate.favDetail removeObjectAtIndex: indexPath.row];
[tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
}
Wednesday, May 18, 2011
NSDate and time seperate
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd"];
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setDateFormat:@"HH:mm:ss"];
NSDate *now = [[NSDate alloc] init];
NSString *theDate = [dateFormat stringFromDate:now];
NSString *theTime = [timeFormat stringFromDate:now];
NSLog(@"\n"
"theDate: |%@| \n"
"theTime: |%@| \n"
, theDate, theTime);
[dateFormat setDateFormat:@"yyyy-MM-dd"];
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setDateFormat:@"HH:mm:ss"];
NSDate *now = [[NSDate alloc] init];
NSString *theDate = [dateFormat stringFromDate:now];
NSString *theTime = [timeFormat stringFromDate:now];
NSLog(@"\n"
"theDate: |%@| \n"
"theTime: |%@| \n"
, theDate, theTime);
Adding LibXML and OpenSSL to Xcode
header search path-> $(SDKROOT)/usr/include/libxml2
2) include any folder like iPhoneSimulator4.2.sdk and add this name
2) include any folder like iPhoneSimulator4.2.sdk and add this name
Thursday, May 5, 2011
make car c++
{ // car body
b2PolygonDef poly1, poly2;
// bottom half
poly1.vertexCount = 5;
poly1.vertices[4].Set(-2.2f,-0.74f);
poly1.vertices[3].Set(-2.2f,0);
poly1.vertices[2].Set(1.0f,0);
poly1.vertices[1].Set(2.2f,-0.2f);
poly1.vertices[0].Set(2.2f,-0.74f);
poly1.filter.groupIndex = -1;
poly1.density = 20.0f;
poly1.friction = 0.68f;
poly1.filter.groupIndex = -1;
// top half
poly2.vertexCount = 4;
poly2.vertices[3].Set(-1.7f,0);
poly2.vertices[2].Set(-1.3f,0.7f);
poly2.vertices[1].Set(0.5f,0.74f);
poly2.vertices[0].Set(1.0f,0);
poly2.filter.groupIndex = -1;
poly2.density = 5.0f;
poly2.friction = 0.68f;
poly2.filter.groupIndex = -1;
b2BodyDef bd;
bd.position.Set(-35.0f, 5.8f);
m_vehicle = m_world->CreateBody(&bd);
m_vehicle->CreateShape(&poly1);
m_vehicle->CreateShape(&poly2);
m_vehicle->SetMassFromShapes();
}
{ // vehicle wheels
b2CircleDef circ;
circ.density = 40.0f;
circ.radius = 0.38608f;
circ.friction = 0.8f;
circ.filter.groupIndex = -1;
b2BodyDef bd;
bd.allowSleep = false;
bd.position.Set(-33.8f, 5.0f);
m_rightWheel = m_world->CreateBody(&bd);
m_rightWheel->CreateShape(&circ);
m_rightWheel->SetMassFromShapes();
bd.position.Set(-36.2f, 5.0f);
m_leftWheel = m_world->CreateBody(&bd);
m_leftWheel->CreateShape(&circ);
m_leftWheel->SetMassFromShapes();
}
{ // join wheels to chassis
b2Vec2 anchor;
b2RevoluteJointDef jd;
jd.Initialize(m_vehicle, m_leftWheel, m_leftWheel->GetWorldCenter());
jd.collideConnected = false;
jd.enableMotor = true;
jd.maxMotorTorque = 10.0f;
jd.motorSpeed = 0.0f;
m_leftJoint = (b2RevoluteJoint*)m_world->CreateJoint(&jd);
jd.Initialize(m_vehicle, m_rightWheel, m_rightWheel->GetWorldCenter());
jd.collideConnected = false;
m_rightJoint = (b2RevoluteJoint*)m_world->CreateJoint(&jd);
}
{ // ground
b2PolygonDef box;
box.SetAsBox(11.5f, 0.5f);
box.friction = 0.62f;
#pragma mark plank height
b2BodyDef bd;
bd.position.Set(-26.0f, 4.8f);
b2Body* ground = m_world->CreateBody(&bd);
ground->CreateShape(&box);
}
b2PolygonDef poly1, poly2;
// bottom half
poly1.vertexCount = 5;
poly1.vertices[4].Set(-2.2f,-0.74f);
poly1.vertices[3].Set(-2.2f,0);
poly1.vertices[2].Set(1.0f,0);
poly1.vertices[1].Set(2.2f,-0.2f);
poly1.vertices[0].Set(2.2f,-0.74f);
poly1.filter.groupIndex = -1;
poly1.density = 20.0f;
poly1.friction = 0.68f;
poly1.filter.groupIndex = -1;
// top half
poly2.vertexCount = 4;
poly2.vertices[3].Set(-1.7f,0);
poly2.vertices[2].Set(-1.3f,0.7f);
poly2.vertices[1].Set(0.5f,0.74f);
poly2.vertices[0].Set(1.0f,0);
poly2.filter.groupIndex = -1;
poly2.density = 5.0f;
poly2.friction = 0.68f;
poly2.filter.groupIndex = -1;
b2BodyDef bd;
bd.position.Set(-35.0f, 5.8f);
m_vehicle = m_world->CreateBody(&bd);
m_vehicle->CreateShape(&poly1);
m_vehicle->CreateShape(&poly2);
m_vehicle->SetMassFromShapes();
}
{ // vehicle wheels
b2CircleDef circ;
circ.density = 40.0f;
circ.radius = 0.38608f;
circ.friction = 0.8f;
circ.filter.groupIndex = -1;
b2BodyDef bd;
bd.allowSleep = false;
bd.position.Set(-33.8f, 5.0f);
m_rightWheel = m_world->CreateBody(&bd);
m_rightWheel->CreateShape(&circ);
m_rightWheel->SetMassFromShapes();
bd.position.Set(-36.2f, 5.0f);
m_leftWheel = m_world->CreateBody(&bd);
m_leftWheel->CreateShape(&circ);
m_leftWheel->SetMassFromShapes();
}
{ // join wheels to chassis
b2Vec2 anchor;
b2RevoluteJointDef jd;
jd.Initialize(m_vehicle, m_leftWheel, m_leftWheel->GetWorldCenter());
jd.collideConnected = false;
jd.enableMotor = true;
jd.maxMotorTorque = 10.0f;
jd.motorSpeed = 0.0f;
m_leftJoint = (b2RevoluteJoint*)m_world->CreateJoint(&jd);
jd.Initialize(m_vehicle, m_rightWheel, m_rightWheel->GetWorldCenter());
jd.collideConnected = false;
m_rightJoint = (b2RevoluteJoint*)m_world->CreateJoint(&jd);
}
{ // ground
b2PolygonDef box;
box.SetAsBox(11.5f, 0.5f);
box.friction = 0.62f;
#pragma mark plank height
b2BodyDef bd;
bd.position.Set(-26.0f, 4.8f);
b2Body* ground = m_world->CreateBody(&bd);
ground->CreateShape(&box);
}
make bridge C++
#pragma mark bridge
b2Body* ground = NULL;
{
b2PolygonDef sd;
sd.SetAsBox(0.2f, 0.1f);
b2BodyDef bd;
bd.position.Set(0.0f, 0.0f);
ground = m_world->CreateBody(&bd);
ground->CreateShape(&sd);
}
{
b2PolygonDef sd;
sd.SetAsBox(0.5f, 0.125f);
sd.density = 20.0f;
sd.friction = 0.2f;
b2RevoluteJointDef jd;
const int32 numPlanks = 30;
b2Body* prevBody = ground;
for (int32 i = 0; i < numPlanks; ++i)
{
b2BodyDef bd;
bd.position.Set(-14.5f + 1.0f * i, 5.0f);
b2Body* body = m_world->CreateBody(&bd);
body->CreateShape(&sd);
body->SetMassFromShapes();
b2Vec2 anchor(-15.0f + 1.0f * i, 5.0f);
jd.Initialize(prevBody, body, anchor);
m_world->CreateJoint(&jd);
prevBody = body;
}
b2Vec2 anchor(-15.0f + 1.0f * numPlanks, 5.0f);
jd.Initialize(prevBody, ground, anchor);
m_world->CreateJoint(&jd);
}
b2Body* ground = NULL;
{
b2PolygonDef sd;
sd.SetAsBox(0.2f, 0.1f);
b2BodyDef bd;
bd.position.Set(0.0f, 0.0f);
ground = m_world->CreateBody(&bd);
ground->CreateShape(&sd);
}
{
b2PolygonDef sd;
sd.SetAsBox(0.5f, 0.125f);
sd.density = 20.0f;
sd.friction = 0.2f;
b2RevoluteJointDef jd;
const int32 numPlanks = 30;
b2Body* prevBody = ground;
for (int32 i = 0; i < numPlanks; ++i)
{
b2BodyDef bd;
bd.position.Set(-14.5f + 1.0f * i, 5.0f);
b2Body* body = m_world->CreateBody(&bd);
body->CreateShape(&sd);
body->SetMassFromShapes();
b2Vec2 anchor(-15.0f + 1.0f * i, 5.0f);
jd.Initialize(prevBody, body, anchor);
m_world->CreateJoint(&jd);
prevBody = body;
}
b2Vec2 anchor(-15.0f + 1.0f * numPlanks, 5.0f);
jd.Initialize(prevBody, ground, anchor);
m_world->CreateJoint(&jd);
}
Tuesday, May 3, 2011
Basics Pointer
if a is a struct use a.b
if a is a pointer to a struct use a->b
if a is an object pointer and b is a ivar use a->b
if a is an object pointer and b is a property use a
if a is a pointer to a struct use a->b
if a is an object pointer and b is a ivar use a->b
if a is an object pointer and b is a property use a
Monday, May 2, 2011
Struct in ObjC
// in interface
struct fruit {
int a;
};
// in implementation
int main()
{
struct fruit apple;
apple.a = 1;
return 0;
}
struct fruit {
int a;
};
// in implementation
int main()
{
struct fruit apple;
apple.a = 1;
return 0;
}
Subscribe to:
Posts (Atom)