পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Sunday, February 5, 2017

Objective-C Numbers

In Objective-C programming language, in order to save the basic data types like int, float, bool in object form,
Objective-C provides a range of methods to work with NSNumber and important ones are listed in following table.

S.N. Method and Description
1 + (NSNumber *)numberWithBool:(BOOL)value Creates and returns an NSNumber object containing a given value, treating it as a BOOL.
2 + (NSNumber *)numberWithChar:(char)value Creates and returns an NSNumber object containing a given value, treating it as a signed char.
3 + (NSNumber *)numberWithDouble:(double)value Creates and returns an NSNumber object containing a given value, treating it as a double.
4 + (NSNumber *)numberWithFloat:(float)value Creates and returns an NSNumber object containing a given value, treating it as a float.
5 + (NSNumber *)numberWithInt:(int)value Creates and returns an NSNumber object containing a given value, treating it as a signed int.
6 + (NSNumber *)numberWithInteger:(NSInteger)value Creates and returns an NSNumber object containing a given value, treating it as an NSInteger.
7 - (BOOL)boolValue Returns the receiver's value as a BOOL.
8 - (char)charValue Returns the receiver's value as a char.
9 - (double)doubleValue Returns the receiver's value as a double.
10 - (float)floatValue Returns the receiver's value as a float.
11 - (NSInteger)integerValue Returns the receiver's value as an NSInteger.
12 - (int)intValue Returns the receiver's value as an int.
13 - (NSString *)stringValue Returns the receiver's value as a human-readable string.
Here is a simple example for using NSNumber which multiplies two numbers and returns the product.
#import <Foundation/Foundation.h>

@interface SampleClass:NSObject

- (NSNumber *)multiplyA:(NSNumber *)a withB:(NSNumber *)b;

@end

@implementation SampleClass

- (NSNumber *)multiplyA:(NSNumber *)a withB:(NSNumber *)b
{
   float number1 = [a floatValue];
   float number2 = [b floatValue];
   float product = number1 * number2;
   NSNumber *result = [NSNumber numberWithFloat:product];
   return result;
}

@end

int main()
{
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

   SampleClass *sampleClass = [[SampleClass alloc]init];
   NSNumber *a = [NSNumber numberWithFloat:10.5];
   NSNumber *b = [NSNumber numberWithFloat:10.0];   
   NSNumber *result = [sampleClass multiplyA:a withB:b];
   NSString *resultString = [result stringValue];
   NSLog(@"The product is %@",resultString);

   [pool drain];
   return 0;
}
Now when we compile and run the program, we will get the following result.
2013-09-14 18:53:40.575 demo[16787] The product is 105

No comments:

Post a Comment