NSMutableArray change object at Index

Ads
 

NSMutableArray change object at Index

NSMutableArray change object at Index

View Answers

March 26, 2012 at 1:39 PM

// Browse all messages (you can use "for (NSDictionary *message in allMessageArray)" enumerate loop but because we need the index to replace object, it's the best way to do that)
for (int index = 0; index < allMessageArray.count; ++index) {
  // Get current message dictionary
  NSDictionary *message = [allMessageArray objectAtIndex:index];

  // If message came from good sender (you can use isEqualToString: if both objects are NSString instance)
  if ([[message objectForKey:@"expediteur"] isEqual:[dicoChat2 objectForKey:@"expediteur"]]) {
    // Create an autoreleased mutable copy of message array to modify some data
    NSMutableDictionary *messageModified = [NSMutableDictionary dictionaryWithDictionary:message];

    // *** Modify what you want in messageModified dictionary ***

    // Replace original message with modified message in array (assume that allMessageArray is a mutable array) (It's very bad to modify an array in its enumerate loop but because we don't remove/add an object to the array, it's fine to do like that)
    [allMessageArray replaceObjectAtIndex:index withObject:messageModified];

    // *** If you know that you will have always only one message in array with good sender, you can break the loop here ***
  }
}

// Write array to file
[allMessageArray writeToFile:datAllString atomically:YES];

Ads









Related Tutorials/Questions & Answers:
NSMutableArray change object at Index
NSMutableArray change object at Index   NSMutableArray change object at Index   // Browse all messages (you can use "for (NSDictionary... to replace object, it's the best way to do that) for (int index = 0; index <
How to change object item to integer item
How to change object item to integer item  How to change objectitem to integer item?thankyou
Advertisements
NSMutableArray example
of Creating and and adding object in NSMutableArray: First create a object...In this section we will discuss about the NSMutableArray with some examples to clarify its use in programming. NSMutableArray class adds insert and delete
NSMutableArray Example Code
NSMutableArray Example Code  creating and allocating memory to the NSMutableArray in objective c.   Hi, Just follow the given steps to create and addobject in NSMutableArray: Step 1 in the header file create a object
NSArray from NSMutableArray
NSArray from NSMutableArray  HI, How to make NSArray from NSMutableArray? Thanks
NSMutableArray Search String
NSMutableArray Search String  Hi all, In my iPhone SDK application.. i wanted to search from the table data. My question is ..do i need to innsert the table data into search array? thanks
remove all objects from NSMutablearray
objects from nsmutablearray? Thanks   HI, Here is the code for creating NSMutablearray, adding objects and then removing all the objects: NSMutableArray *myArray = [[NSMutableArray alloc] init]; [myArray addObject:@"One"]; [myArray
object
object  is it possible to create object in the same class..?.   Yes, you can. class CreateObject { CreateObject(){ System.out.println("I have an object."); } public static void main(String[] args
How to change background, change background
How to change background       This example will teach you to change background of any object... a picture to change background. Selection: Make selection by the Magic wand tool
index of javaprogram
index of javaprogram  what is the step of learning java. i am not asking syllabus am i am asking the step of program to teach a pesonal student.   To learn java, please visit the following link: Java Tutorial
index
change password
change password  how to change password in the login form.... by giving options to user like this old password, new password.. pls help
Change Email
Change Email  Hi, I need to change my Rose India register email address for receive email, How did it possible
rename index in elasticsearch
rename index in elasticsearch  How to rename index in elasticsearch? I have an index with millions of records in it. I want to rename this index... is the command to rename index in elasticsearch? I am using Elasticsearch 6.1. Thanks
JavaScript array index of
by an array object and store in a variable index. Finally the document. write...JavaScript array index of  In this Tutorial we want to describe that makes you to easy to understand JavaScript array index of. We are using JavaScript
password change
password change  Hi , I am using jsf and trying to write a code to change the password of a user . Ihave to retrine userid fromdata base how to do that using session
Drop Index
Drop Index       Drop Index is used to remove one or more indexes from the current database. Understand with Example The Tutorial illustrate an example from Drop Index
ModuleNotFoundError: No module named 'index'
ModuleNotFoundError: No module named 'index'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'index' How to remove the ModuleNotFoundError: No module named 'index'
ModuleNotFoundError: No module named 'index'
ModuleNotFoundError: No module named 'index'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'index' How to remove the ModuleNotFoundError: No module named 'index'
ModuleNotFoundError: No module named 'index-by'
ModuleNotFoundError: No module named 'index-by'  Hi, My Python... 'index-by' How to remove the ModuleNotFoundError: No module named 'index... to install padas library. You can install index-by python with following
Mysql Btree Index
Mysql Btree Index  Mysql BTree Index Which tree is implemented to btree index? (Binary tree or Bplus tree or Bminus tree
object creation
object creation  when will java object is created? is it at runtime or compiletime
z-index always on top
z-index always on top  Hi, How to make my div always on top using the z-index property? Thanks   Hi, You can use the following code: .mydiv { z-index:9999; } Thanks
Object Oriented
Object Oriented  C++ is Purely object oriented or not .Then why java called purely object oriented
Object reference not set to an instance of an object
Object reference not set to an instance of an object  Object reference not set to an instance of an object
change appearance of alert box
change appearance of alert box  how to change the appearance of an alert() box
Change orientation of UIViewController
Change orientation of UIViewController  Is it possible to change the UIViewController orientation dynamically
change value of mutable string
change value of mutable string  How to change value of mutable string
change content of cell javascript
change content of cell javascript  change content of cell javascript
change xml dynamically
change xml dynamically  How to change an XML dynamically in Java
Version of com.thesett>index dependency
List of Version of com.thesett>index dependency

Ads