Why cannot I set an object inside NSMutable dictionary












1















I have mutable dictionary object, which is part of Model class, declared as below.



@interface Obj : NSObject
@property NSMutableDictionary *obj;


Values of obj are given below.




{
0 = (
0,
"5.00",
"5.59",
"14.00",
"14.59",
"22.00",
"22.59"
);
1 = (
1,
"5.00",
"5.59",
"14.00",
"14.59",
"22.00",
"22.59"
);
2 = (
2,
"5.00",
"5.59",
"14.00",
"14.59",
"22.00",
"22.59"
);
3 = (
3,
"5.00",
"5.59",
"14.00",
"14.59",
"22.00",
"22.59"
);
4 = (
4,
"5.00",
"5.59",
"14.00",
"14.59",
"22.00",
"22.59"
);
5 = (
5,
"5.00",
"5.59",
"14.00",
"14.59",
"22.00",
"22.59"
);
6 = (
6,
"5.00",
"5.59",
"14.00",
"14.59",
"22.00",
"22.59"
);
}




My app always crashes with following line of code when I try to set/update the values for a particular key.



[Obj.obj setValue:array3 forKey:string];


where array3 has following values.




(
4,
5,
6,
14,
15,
22,
23
)




I have tried changing the line to



[Obj.obj setObject:array3 forKey:string];



But I always get the same error as below.




Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance 0x6040001b3160'











share|improve this question



























    1















    I have mutable dictionary object, which is part of Model class, declared as below.



    @interface Obj : NSObject
    @property NSMutableDictionary *obj;


    Values of obj are given below.




    {
    0 = (
    0,
    "5.00",
    "5.59",
    "14.00",
    "14.59",
    "22.00",
    "22.59"
    );
    1 = (
    1,
    "5.00",
    "5.59",
    "14.00",
    "14.59",
    "22.00",
    "22.59"
    );
    2 = (
    2,
    "5.00",
    "5.59",
    "14.00",
    "14.59",
    "22.00",
    "22.59"
    );
    3 = (
    3,
    "5.00",
    "5.59",
    "14.00",
    "14.59",
    "22.00",
    "22.59"
    );
    4 = (
    4,
    "5.00",
    "5.59",
    "14.00",
    "14.59",
    "22.00",
    "22.59"
    );
    5 = (
    5,
    "5.00",
    "5.59",
    "14.00",
    "14.59",
    "22.00",
    "22.59"
    );
    6 = (
    6,
    "5.00",
    "5.59",
    "14.00",
    "14.59",
    "22.00",
    "22.59"
    );
    }




    My app always crashes with following line of code when I try to set/update the values for a particular key.



    [Obj.obj setValue:array3 forKey:string];


    where array3 has following values.




    (
    4,
    5,
    6,
    14,
    15,
    22,
    23
    )




    I have tried changing the line to



    [Obj.obj setObject:array3 forKey:string];



    But I always get the same error as below.




    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance 0x6040001b3160'











    share|improve this question

























      1












      1








      1








      I have mutable dictionary object, which is part of Model class, declared as below.



      @interface Obj : NSObject
      @property NSMutableDictionary *obj;


      Values of obj are given below.




      {
      0 = (
      0,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      1 = (
      1,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      2 = (
      2,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      3 = (
      3,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      4 = (
      4,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      5 = (
      5,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      6 = (
      6,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      }




      My app always crashes with following line of code when I try to set/update the values for a particular key.



      [Obj.obj setValue:array3 forKey:string];


      where array3 has following values.




      (
      4,
      5,
      6,
      14,
      15,
      22,
      23
      )




      I have tried changing the line to



      [Obj.obj setObject:array3 forKey:string];



      But I always get the same error as below.




      Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance 0x6040001b3160'











      share|improve this question














      I have mutable dictionary object, which is part of Model class, declared as below.



      @interface Obj : NSObject
      @property NSMutableDictionary *obj;


      Values of obj are given below.




      {
      0 = (
      0,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      1 = (
      1,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      2 = (
      2,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      3 = (
      3,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      4 = (
      4,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      5 = (
      5,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      6 = (
      6,
      "5.00",
      "5.59",
      "14.00",
      "14.59",
      "22.00",
      "22.59"
      );
      }




      My app always crashes with following line of code when I try to set/update the values for a particular key.



      [Obj.obj setValue:array3 forKey:string];


      where array3 has following values.




      (
      4,
      5,
      6,
      14,
      15,
      22,
      23
      )




      I have tried changing the line to



      [Obj.obj setObject:array3 forKey:string];



      But I always get the same error as below.




      Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance 0x6040001b3160'








      objective-c nsmutablearray






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 18:00









      humble_piehumble_pie

      425




      425
























          1 Answer
          1






          active

          oldest

          votes


















          1














          This looks like you're initializing the property with an immutable value (that's what the __NSDictionaryI is telling you). Perhaps something like:



          obj = @{};


          Or perhaps you're reading it out of a serializer. Those generally create immutable collections (though there are options for creating mutable collections depending on your serializer). Just defining the type of the pointer to the object doesn't make it that type; the object itself has to be created as a mutable dictionary.



          At some point there should be a line of code like:



          obj = [NSMutableDictionary new];


          or



          obj = [someImmutableDictionary mutableCopy];





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451179%2fwhy-cannot-i-set-an-object-inside-nsmutable-dictionary%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            This looks like you're initializing the property with an immutable value (that's what the __NSDictionaryI is telling you). Perhaps something like:



            obj = @{};


            Or perhaps you're reading it out of a serializer. Those generally create immutable collections (though there are options for creating mutable collections depending on your serializer). Just defining the type of the pointer to the object doesn't make it that type; the object itself has to be created as a mutable dictionary.



            At some point there should be a line of code like:



            obj = [NSMutableDictionary new];


            or



            obj = [someImmutableDictionary mutableCopy];





            share|improve this answer




























              1














              This looks like you're initializing the property with an immutable value (that's what the __NSDictionaryI is telling you). Perhaps something like:



              obj = @{};


              Or perhaps you're reading it out of a serializer. Those generally create immutable collections (though there are options for creating mutable collections depending on your serializer). Just defining the type of the pointer to the object doesn't make it that type; the object itself has to be created as a mutable dictionary.



              At some point there should be a line of code like:



              obj = [NSMutableDictionary new];


              or



              obj = [someImmutableDictionary mutableCopy];





              share|improve this answer


























                1












                1








                1







                This looks like you're initializing the property with an immutable value (that's what the __NSDictionaryI is telling you). Perhaps something like:



                obj = @{};


                Or perhaps you're reading it out of a serializer. Those generally create immutable collections (though there are options for creating mutable collections depending on your serializer). Just defining the type of the pointer to the object doesn't make it that type; the object itself has to be created as a mutable dictionary.



                At some point there should be a line of code like:



                obj = [NSMutableDictionary new];


                or



                obj = [someImmutableDictionary mutableCopy];





                share|improve this answer













                This looks like you're initializing the property with an immutable value (that's what the __NSDictionaryI is telling you). Perhaps something like:



                obj = @{};


                Or perhaps you're reading it out of a serializer. Those generally create immutable collections (though there are options for creating mutable collections depending on your serializer). Just defining the type of the pointer to the object doesn't make it that type; the object itself has to be created as a mutable dictionary.



                At some point there should be a line of code like:



                obj = [NSMutableDictionary new];


                or



                obj = [someImmutableDictionary mutableCopy];






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 19:00









                Rob NapierRob Napier

                201k28297423




                201k28297423
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451179%2fwhy-cannot-i-set-an-object-inside-nsmutable-dictionary%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    Refactoring coordinates for Minecraft Pi buildings written in Python