Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7590737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:28:46+00:00 2026-05-30T20:28:46+00:00

EDIT: this is my full code: i have a array how look like this:

  • 0

EDIT: this is my full code:

i have a array how look like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <dict>
        <key>destinataire</key>
        <string>david</string>
        <key>expediteur</key>
        <string>sophie</string>
        <key>idMessage</key>
        <string>1729</string>
        <key>message</key>
        <string>ok a plus</string>
        <key>photoExp</key>
        <string>http://photos/hbrJUlrTgj.jpg</string>
        <key>statusE</key>
        <string>1</string>
    </dict>
    <dict>
        <key>destinataire</key>
        <string>david</string>
        <key>expediteur</key>
        <string>max</string>
        <key>idMessage</key>
        <string>1730</string>
        <key>message</key>
        <string>ok a plus</string>
        <key>photoExp</key>
        <string>http:///photos/4xlWoAHT8b.jpg</string>
        <key>statusE</key>
        <string>1</string>
    </dict>
    <dict>
        <key>destinataire</key>
        <string>david</string>
        <key>expediteur</key>
        <string>michel</string>
        <key>idMessage</key>
        <string>1731</string>
        <key>message</key>
        <string>ok a plus</string>
        <key>photoExp</key>
        <string>http:///photos/TR7oO6O8Z8.jpg</string>
        <key>statusE</key>
        <string>1</string>
    </dict>
</array>
</plist>

i need to put new datas in this array but in my new data i have this :

<dict>
            <key>destinataire</key>
            <string>david</string>
            <key>expediteur</key>
            <string>sophie</string>
            <key>idMessage</key>
            <string>1729</string>
            <key>message</key>
            <string>ok a plus</string>
            <key>photoExp</key>
            <string>http://photos/hbrJUlrTgj.jpg</string>
            <key>statusE</key>
            <string>1</string>
        </dict>

sophie is already exist in my array so i have to find the index in my array where sophie appears to put my new data

so i do this to try to find duplicates datas and replace it

if ([[allMessageArray valueForKey:@"expediteur"]containsObject:[dicoChat2 objectForKey:@"expediteur"]] ) 
    {
    for( int i=0;i<[allMessageArray count];i++)
      {
    NSDictionary *dicoChat22 = [allMessageArray objectAtIndex:i];

    NSMutableDictionary *  datas2= [[NSMutableDictionary alloc]init];

    [datas2 setObject:[dicoChat22 objectForKey:@"destinataire"] forKey:@"destinataire"];
    [datas2 setObject:[dicoChat22 objectForKey:@"expediteur"] forKey:@"expediteur"];
    [datas2 setObject:[dicoChat22 objectForKey:@"photoExp"] forKey:@"photoExp"];
    [datas2 setObject:[dicoChat22 objectForKey:@"statusE"] forKey:@"statusE"];
    [datas2 setObject:[dicoChat22 objectForKey:@"idMessage"] forKey:@"idMessage"];

    [allMessageArray replaceObjectAtIndex:i withObject:datas2];
    [allMessageArray writeToFile:datAllString atomically:YES];
     }

    }

when i try to use replaceObjectAtindex:i it works but all my datas has been replaced in every index.
so i know i didn’t find the good index
how i can found it?

thx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:28:47+00:00Added an answer on May 30, 2026 at 8:28 pm

    I don’t understand very well what you trying to do but here is a possible solution (if your allMessageArray is really an array, because you use valueForKey: with it !!!) :

    // 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];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataset obtained from MySQL that goes like this: Array ( [0]
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
Edit: This code is fine. I found a logic bug somewhere that doesn't exist
(EDIT: This question is now outdated for my particular issue, as Google Code supports
I have next code block: $.post('page.php', function(data) { //data - full page info });
I have defined a generic tree-node class like this: template<class DataType> class GenericNode {
I have this code: <input type=hidden id=editorTitle name=title value=home> <textarea name=text id=editorText></textarea> But when
I have a piece of Perl code somewhat like the following (strongly simplified): There
(Sorry if it's a trivial question.) I have documents that looks like this (Python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.