Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How declare methods in objective c? And how to call them?

Answer Posted / Rohit Rai

In Objective-C, you can define methods (functions) inside classes. To declare a method, use the following syntax:

```objectivec
-(returnType)methodName:(parameters);
```

Here's an example of a method that calculates the area of a rectangle with two parameters for width and height:

```objectivec
- (double)calculateRectangleAreaWithWidth:(double)width andHeight:(double)height {
double area = width * height;
return area;
}
```

To call the method, create an instance of the class containing the method and invoke it:

```objectivec
Rectangle *rectangle = [[Rectangle alloc] init];
double result = [rectangle calculateRectangleAreaWithWidth:10.0 andHeight:5.0];
NSLog(@"The area is %f", result);
```

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

No New Questions to Answer in this Category !!    You can

Post New Questions

Answer Questions in Different Category