Powered by
Powered by
HuntMyIdeas-Inspire You To Make It Happen
Follow
   Me
  • Blogs
  • About Me
  • Home

iOS Interview Questions And Answers For 1-2 years Experienced Candidates.

3/3/2016

0 Comments

 
Picture
1.How do I convert NSMutableArray to NSArray?

Answer:

In this post I have explained some key functionalities of NSArray and NSMutableArray.

I would like to elaborate some possible solutions with explanation.

1)NSArray *array = [NSArray arrayWithArray:mutableArray];
​
Note:
What if the NSMutableArray is nil ?

NSMutableArray *mutableArray = nil;
NSArray *array = [NSArray arrayWithArray:mutableArray];

In the above case,the array is returned as an empty array.
​

(array == @[] )

For Example:-

 (Which is an empty array but not nil).


2)NSArray *array = [mutableArray copy];

Note:
What if the NSMutableArray is nil ?


NSMutableArray *mutableArray = nil;
NSArray *array = [mutableArray copy];
The above code returns array as nil. (array==nil)


3)
NSArray *array = [[NSArray alloc] initWithArray:mutableArray];

It returns an array which is not autoreleased.

Note:

NSArray *array = [NSArray arrayWithArray:mutableArray];

It returns an array which is autoreleased.

Read:-
Top iOS Interview Questions And Answers for Beginners
Most Important iPhone interview Questions and Answers 

2.How to convert an NSArray to String in Objective-C ?
Answer:-


NSArray  *array1 = [NSArray arrayWithObjects:@"a", @"b", @"c", nil];
NSString *StringVal = [array1 componentsJoinedByString:@","];


It returns a String with value "abc".

Read:
Basic iOS interview Questions And Answers 
​Most Important iPhone interview Questions and Answers

3.How to convert an NSMutableArray to String in Objective-C ?
Answer:-


MArray = [[NSMutableArray alloc] init];
[MArray addObject:@"ABCD"];
[MArray addObject:@"EFGH"];
NSString *StringVal=[MArray description];

                                  OR
NSString *StringVal=[MArray componentsJoinedByString:@", "];

Read:
What are the differences between Cocoa and Cocoa Touch?
In-App Purchase Tutorial in Cocos2d-x using SDKBOX .

4.How to sort an NSMutableArray with custom objects in it?
Answer:-


We can easily sort an array using Blocks.

NSArray *MySortedarray;
MySortedarray = [BillDetails sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {    NSDate *first = [(Person*)a birthDate];
NSDate *second = [(Person*)b birthDate];
 return [first compare:second];
}];


Read:
Best Tutorials- Properties in objective C
Top 5 Simple iOS Interview Questions And Answers

5.How can I fill an NSMutableArray dynamically?
Answer:-


int count = [CArray count];
NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:count];
for (NSString  *name in CArray) {
 UIImage *image = [UIImage imageNamed:name]; 
 [resultArray addObject: image];

}

Read:
What is the difference between IBOutlet and IBAction in iOS ?
Top iOS interview Questions And Answers Collection


6.How to replace content of NSMutableArray with NSArray ?
Answer:


DataArray = [resultArray mutableCopy];

In the above example, DataArray is NSMutableArray and resultArray is NSArray.
OR
NSMutableArray *DataArray = [[NSMutableArray alloc] initWithContentsOfArray:resultArray];

Read:
Some important points About View Controller.
What Are The Main Responsibilities Of A View Controller ?
Explain The Difference Between loadView() And viewDidLoad() in iOS
​How To Explain UIViewController Life Cycle in iOS ?
​
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    Enter your email address:

    Delivered by FeedBurner

    RSS Feed

    Archives

    December 2019
    August 2018
    January 2018
    December 2017
    November 2017
    October 2017
    August 2017
    April 2017
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    December 2014
    November 2014
    October 2014
    September 2014
    August 2014
    July 2014
    June 2014


    ​​Categories

    All
    Affiliate Marketing
    Alexa Rank
    Apple's Latest Updates
    Blog Tips
    Cocos2d X
    Cocos2d-x
    Google AdSense Tips
    Grab-some-ultimate-ideas
    How-to-create-a-twinkling-star-background-effect-in-ios
    In-App Purchase Tutorial In Cocos2d-x (C++) Using SDKBOX
    Ios Interview Questions And Answers
    IOS Multiple Choice Questions And Answers
    Objective C
    Online Business
    Python
    Secrets To Effective IPhone App Marketing
    SEO Tips
    Swift Interview Questions
    Swift Tutorials
    Top 10 Articles Objective C
    Top 10 Articles-Objective-C
    Top 10 Popular Movies Ever
    Top 10 Popular Things To Know
    Top 10 Ultimate Issues Xcode
    Top 400 IOS Interview Questions
    Top IOS Sample Projects To Learn From
    Top Secrets To App Marketing
    UICollectionView
    Unity 3D
    Xcode

WELCOME TO HUNTMYIDEAS

Picture
I am Jitendra Gochhayat,an iOS Developer,Designer,blogger,
​from Odisha,India.
I write about ​​​blog tips and,
Make money online Tips,
​Objective C tutorials
SUSCRIBE TO NEWSLETTER

    Subscribe to this blog and receive notifications of new posts by email

Suscribe
Picture
Picture
Picture
Picture
Picture
HuntMyIdeas-2016 Powered By Weebly
Picture
Powered by Create your own unique website with customizable templates.
Powered by
Powered by