Exploring the Foundation Framework in iPhone - NS Thread & Number Class

  • (4.0)
  •   |   405 Ratings

NS thread:-

An NSThread object controls a thread of execution. Use this class when you want to have an OBJECTIVE-C method run in its own thread of execution. Threads are especially useful when you need to perform a lengthy task, but don’t want it to block the execution of the rest of the application. In particular, you can use threads to avoid blocking the main thread of the application, which handles user interface and event-related actions. Threads can also be used to divide a large job into several smaller jobs, which can lead to performance increases on multi-core computers. (Refer to EXPLORING THE FOUNDATION FRAMEWORK to know various class types)

 (void) view Did load
[NSThread detachNewThreadSelector:
 @ Selector  (blackGroundThread) to Target :self WithObjects  : nil];
For (int :=0; i<100; i++)
NSLog (@ “ mainThread”);

// sleep made for some seconds:

[NSThread SleepForTimeInterval:2];
NSLog (@ “the thread is sleep”,);

// getting current thread:

NSThread * currentThread= [NSThread CurrentThread];
NSLog (@ “the Current thread is %@”,  current Thread)];
// prepare thread in another way:-

    [ self PerformSelectorInBackground:
     @ selector ( backGround thread) WithObject : nil];
-(void) back ground thread
     For (int i=0; i<100; i++)
NSLog (@ “ child Thread”);

Multi threading:-

** In most of the modern OS, it is possible for an application to split into many threads that all execute concurrently.
** When a program is split into many threads, each thread acts like its own individual program except that all the threads work in the same memory space.
** Multi threads can run on multiple CPUS providing performance and improvement. A multi thread application work as well as sign single CPU system, but with added speed in objective C, there is a special class for threading i.e. NSThread class.

Inclined to build a profession as IOS Developer? Then here is the blog post on iPhone Development Certification Training.

Ns thread:-

>> If you need to run relative task on the back ground of the application after same task, we use thread concept.
>> Ns thread class deal with function for creating thread semaphones monitors.

NS user defaults:-

//saving user name and password into user defaults object:

  NSUserDefaults *defaults  =
[ nNSUserDefaults StandardUserDefaults];
[defaults SetObject: @ “Kumar” for key:@ “userName”];
[ defaults SetObject:@ “12345” for key: @ “password”];
[defaults synchronize];

getting user name and password from the user default

       NSUserDefault *defaultt2   =
    [ NSUserDefaults    StandardUserDefaults];
NSString *UserName =
[Default2 ObjectForkey  :@  “User Name”];
NSString * password  =
[Default2 ObjectForkey :@ “password”];
NSLog (@ “UserName is %@pass word is % @”, user name, password);


// Converting int to ns number:

Int x;
NSNumber      *a num = [NSNumber  NumberWithInt :x];
NSNumber        *b num=[NSNumber   NumberWithFloat:6.6];
NSNumber        *c num  =[ NSNumber   NumberWithChar: ‘c’];
NSNumber       *d num= [NSNumber   NumberWithBool :Yes];
NSArray          * a array=
     [NSArray  arrayWithObjects: a num, b num , c num, d num, nil];
NSLog  (@ “a array is % @”,  aArray);

//how to convert ns number to primary data types

 int   y=[ anum    intValue];
 float  y=[bnum     floatValue];
char ch  =[cnum  charvalue];
Bool   y=  [ dnum boolvalue ];


Frequently Asked iPhone Interview Questions & Answers


Popular Courses in 2018

Get Updates on Tech posts, Interview & Certification questions and training schedules