Add multiple recipients to MFMailcomposer torecepients: field - Xcode IOS - ios

I have an existing program that enables me to 'tag' an email and add it to an ARRAY , I am then trying to use that ARRAY in my existing program and add it
array2 has had a group of email addresses added to it so consists of "something#sky.com,some#sky.com"
NSArray *toRecipients = [NSArray addObjectToArray:array2];
[composer setToRecipients:toRecipients];
Please don't 'flame' my code or message as I am typing the above from memory

MFMailComposeViewController *recipntNames = [[MFMailComposeViewController alloc] init];
NSArray *toRecipientsNames = [NSArray arrayWithObjects:#"something#sky.com",#"some#sky.com",nil];
[recipntNames setToRecipients:toRecipientsNames];
or use this array2 is your NSMutableArray Name
NSArray *array = [array2 copy];
[recipntNames setToRecipients:toRecipientsNames];
need more reference use this link

I would recommend to you, that using [composer setToRecipients:array2] would be better :-)

Related

What does the #[] symbol represent in objective-c?

I'm learning objective-c, Interviewer asked me this question
What's does the #[] symbol mean in objective-c?
It is a NSArray class literal. You can create instance using this
NSArray *array = #[];
the diff way to do this
NSArray *array = [[NSArray alloc] init];
The result the same
It is an empty array since you can create your array like this:
NSArray* array = #[#"A", #"B"];

Can't have access to NSDictionary in NSArray

I have a very strange behaviour with NSArray.
Firstly, i parsed an XML file and return a valid NSArray with NSDictionary inside:
NSArray *arrayOfDict = [parser parseWithXMLFile:filename];
In debugger it's fully valid. Then, i want to proccess all dictionaries in this array:
NSMutableArray* arrayOfProducts = [[NSMutableArray alloc] init];
for (NSDictionary* dict in arrayOfDict) {
Product* product = [[Product alloc] initWithName:dict[#"name"]
type:dict[#"type"]
imageName:dict[#"image"]
description:dict[#"description"]];
[arrayOfProducts addObject:product];
[product release];
}
And in this loop is a problem: a dict variable has value nil. And i don't know what to do with this. In debugger i evaluate value of arrayOfDict[someIndex] and get a right value, but in the programm itself it doesn't work.
May be it's the problem with MRR, i don't feel myself confidenly while using MRR and there is a mistake of using it.
P.S. I know that using MRR is stupid today, but in this project i must use it.

iOS - Add NSDictinary key values into an NSArray sequencialy

I have a NSDictionary and a NSArray:
self.dataDic = [[[NSDictionary alloc] init] autorelease];
self.dataDicKey = [[[NSArray alloc] init] autorelease];
These are the key and value of my NSDictionary:
self.dataDic =
#{#"Ring Cloud" :#[#"Contact Cloud", #"Image Cloud", #"Data Cloud"],
#"Ring Tools" :#[#"Sticker Market", #"Live Poll", #"Mail"],
#"Ring Apps" :#[#"Studio", #"Player"]};
Now what I want is to insert all the key value of my self.dataDic into self.dataDicKey sequentially. That means it looks like this:
self.dataDicKey = [[[NSArray alloc] initWithObjects:#"Ring Cloud", #"Ring Tools", #"Ring Apps",nil] autorelease];
I have tried with this:
self.imageDicKey = [[[self.imageDic allKeys] reverseObjectEnumerator] allObjects];
But it's not actually sorted the values. If any one have any suggestion please share it with me.
Thanks a lot in advance.
If you are trying to get the keys as objects in your NSArray you should try this method
self.DataDicKey = [[NSArray alloc]initWithArray:[self.imageDic allKeys]];
One thing to remember that NSDictionary allKeys method returns only the keys regardless of order they were saved. as its KVP
This will copy your NSDictionary keys into NSArray
NSDictionary keys are unsorted - maybe you could save the keys in array before you enter the data to the dictionary

Add other object to NSArray

I made a small code
NSArray* _options = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:[UIImage imageNamed:#"2"],#"img",name,#"text"
, nil],nil];
Now, I want add other object to _options. What should i do?
I make more test but no success.
Thank for all
you can use [NSArray arrayByAddingObject:]
_options = [_options arrayByAddingObject:object];
or change _options to NSMutableArray
NSMutableArray *_options = [NSMutableArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:[UIImage imageNamed:#"2"],#"img",name,#"text"
, nil],nil];
[_options addObject:object];
and you may want to use modern syntax
NSMutableArray *_options = [#[#{#"img":[UIImage imageNamed:#"2"],#"text":name}] mutableCopy];
[_options addObject:object];
NSArray does not allow any changes to be made; you can use an NSMutableArray instead like this:
NSMutableArray *mutable = [_options mutableCopy];
[mutable addObject:yourObject];
NSDictionary is same in that it can't be mutated.
You can't add objects to a NSArray, to do so, you need a NSMutableArray.
However, you can add objects to NSArray when creating it with : arrayWithObjects
First, create an NSMutableArray, as you can make changes to it as you see fit later throughout your code:
NSMutableArray *newOptions = [NSMutableArray alloc]init];
[newOptions setArray:_options];
[newOptions addObject:yourObject];

Read Mutable Array from File / Plist

Here is my problem. I show files out of an MutableArray in a UITableView with UISearchBar.
Therefore I made an Array:
allTableData = [[NSMutableArray alloc] initWithObjects:
[[CRFParts alloc] initWithName:#"ABC" andDescription:#"DEF"],
[[CRFParts alloc] initWithName:#"GHI" andDescription:#"JKL"],
nil];
I have round about 2000 lines of this. I build me simple strings out of an excel file but the code inside my .m is huge than. Is there a possibility to read these content out of an file (plist/txt)?
Thanks for helping!
Try looking at This Question. It has a lot of good code on how to read a plist and dictionaries vs arrays.
And next time, search before you ask.
You can easely use:
NSArray *array = [[NSArray alloc] initWithContentsOfURL:url];
or NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfURL:url];
Check out Apple Documentation on the topic.
Be careful on what structure you are loading as a plist can represent and array or a dictionary at its root. Other thread about it

Resources