Why cannot I modify an object inside my method












0















I am calling an Api asynchronously to get the data. Then I am assigning the data to a shared instance successfully inside a block given below.



RestApiManager *api= [[RestApiManager alloc]init];
[ObjectBuilder sharedManager];

self.obj = [[Object alloc]init];
[api get_data:credential.password finish:^(NSDictionary *data) {

if(data){
self.obj = [ObjectBuilder obj:data];
[[ObjectBuilder sharedManager]setObject:self.obj];

}


This all working as expected except when I try to update some of the values in one of NSMutableDictionary properties of the obj.



- (void)update: (NSInteger) temp {

array3 = [[NSMutableArray alloc]init];
NSNumber *start =[[NSNumber numberWithInteger:var];
[NSNumber numberWithInteger:var2];
NSNumber *temp2 =[NSNumber numberWithInteger:temp];
[array3 addObject:temp2];
[array3 addObject:start];
[array3 addObject:end];
[self.obj.sch setObject:array3 forKey:temp2];

}



[obj.sch setObject:array3 forKey:temp2]; always crashes my app.




Now I have vague idea whats going on, basically I am setting obj inside a block code, whilst in my update function I am trying to change the contents outside block code.



The error I get is




reason: '-[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance




Note this error goes away if i declare line




[[ObjectBuilder sharedManager]setObject:obj];




Outside the finish:^ block
But then I lose all the data obtained from api call.



Object is declared as below @interface Object : NSObject
@property (strong, nonatomic) NSMutableDictionary *sch;










share|improve this question




















  • 1





    And what's the error message? What I don't understand is what is obj on that line? Because in the code before, it's a local var.

    – Larme
    Nov 16 '18 at 12:56











  • @Larme I updated the code, and error I am getting and also added the line which explains when the error disappears, but I lose the data.

    – humble_pie
    Nov 16 '18 at 14:15






  • 2





    __NSDictionaryI means NSImmutableDictionary (that's why there is an uppercase "i" at the end), in other words, a NSDictionary, not a NSMutableDictionary.

    – Larme
    Nov 16 '18 at 14:26






  • 1





    If you have a new issue, post a new question with clear and specific details. And you may as well delete this question.

    – rmaddy
    Nov 16 '18 at 16:41






  • 1





    My comment wasn't actaually an attenpt to fix your issue, only additional information. Please follow rmaddys advice and create a new question for the new issue.

    – Julian F. Weinert
    Nov 17 '18 at 18:38
















0















I am calling an Api asynchronously to get the data. Then I am assigning the data to a shared instance successfully inside a block given below.



RestApiManager *api= [[RestApiManager alloc]init];
[ObjectBuilder sharedManager];

self.obj = [[Object alloc]init];
[api get_data:credential.password finish:^(NSDictionary *data) {

if(data){
self.obj = [ObjectBuilder obj:data];
[[ObjectBuilder sharedManager]setObject:self.obj];

}


This all working as expected except when I try to update some of the values in one of NSMutableDictionary properties of the obj.



- (void)update: (NSInteger) temp {

array3 = [[NSMutableArray alloc]init];
NSNumber *start =[[NSNumber numberWithInteger:var];
[NSNumber numberWithInteger:var2];
NSNumber *temp2 =[NSNumber numberWithInteger:temp];
[array3 addObject:temp2];
[array3 addObject:start];
[array3 addObject:end];
[self.obj.sch setObject:array3 forKey:temp2];

}



[obj.sch setObject:array3 forKey:temp2]; always crashes my app.




Now I have vague idea whats going on, basically I am setting obj inside a block code, whilst in my update function I am trying to change the contents outside block code.



The error I get is




reason: '-[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance




Note this error goes away if i declare line




[[ObjectBuilder sharedManager]setObject:obj];




Outside the finish:^ block
But then I lose all the data obtained from api call.



Object is declared as below @interface Object : NSObject
@property (strong, nonatomic) NSMutableDictionary *sch;










share|improve this question




















  • 1





    And what's the error message? What I don't understand is what is obj on that line? Because in the code before, it's a local var.

    – Larme
    Nov 16 '18 at 12:56











  • @Larme I updated the code, and error I am getting and also added the line which explains when the error disappears, but I lose the data.

    – humble_pie
    Nov 16 '18 at 14:15






  • 2





    __NSDictionaryI means NSImmutableDictionary (that's why there is an uppercase "i" at the end), in other words, a NSDictionary, not a NSMutableDictionary.

    – Larme
    Nov 16 '18 at 14:26






  • 1





    If you have a new issue, post a new question with clear and specific details. And you may as well delete this question.

    – rmaddy
    Nov 16 '18 at 16:41






  • 1





    My comment wasn't actaually an attenpt to fix your issue, only additional information. Please follow rmaddys advice and create a new question for the new issue.

    – Julian F. Weinert
    Nov 17 '18 at 18:38














0












0








0


0






I am calling an Api asynchronously to get the data. Then I am assigning the data to a shared instance successfully inside a block given below.



RestApiManager *api= [[RestApiManager alloc]init];
[ObjectBuilder sharedManager];

self.obj = [[Object alloc]init];
[api get_data:credential.password finish:^(NSDictionary *data) {

if(data){
self.obj = [ObjectBuilder obj:data];
[[ObjectBuilder sharedManager]setObject:self.obj];

}


This all working as expected except when I try to update some of the values in one of NSMutableDictionary properties of the obj.



- (void)update: (NSInteger) temp {

array3 = [[NSMutableArray alloc]init];
NSNumber *start =[[NSNumber numberWithInteger:var];
[NSNumber numberWithInteger:var2];
NSNumber *temp2 =[NSNumber numberWithInteger:temp];
[array3 addObject:temp2];
[array3 addObject:start];
[array3 addObject:end];
[self.obj.sch setObject:array3 forKey:temp2];

}



[obj.sch setObject:array3 forKey:temp2]; always crashes my app.




Now I have vague idea whats going on, basically I am setting obj inside a block code, whilst in my update function I am trying to change the contents outside block code.



The error I get is




reason: '-[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance




Note this error goes away if i declare line




[[ObjectBuilder sharedManager]setObject:obj];




Outside the finish:^ block
But then I lose all the data obtained from api call.



Object is declared as below @interface Object : NSObject
@property (strong, nonatomic) NSMutableDictionary *sch;










share|improve this question
















I am calling an Api asynchronously to get the data. Then I am assigning the data to a shared instance successfully inside a block given below.



RestApiManager *api= [[RestApiManager alloc]init];
[ObjectBuilder sharedManager];

self.obj = [[Object alloc]init];
[api get_data:credential.password finish:^(NSDictionary *data) {

if(data){
self.obj = [ObjectBuilder obj:data];
[[ObjectBuilder sharedManager]setObject:self.obj];

}


This all working as expected except when I try to update some of the values in one of NSMutableDictionary properties of the obj.



- (void)update: (NSInteger) temp {

array3 = [[NSMutableArray alloc]init];
NSNumber *start =[[NSNumber numberWithInteger:var];
[NSNumber numberWithInteger:var2];
NSNumber *temp2 =[NSNumber numberWithInteger:temp];
[array3 addObject:temp2];
[array3 addObject:start];
[array3 addObject:end];
[self.obj.sch setObject:array3 forKey:temp2];

}



[obj.sch setObject:array3 forKey:temp2]; always crashes my app.




Now I have vague idea whats going on, basically I am setting obj inside a block code, whilst in my update function I am trying to change the contents outside block code.



The error I get is




reason: '-[__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance




Note this error goes away if i declare line




[[ObjectBuilder sharedManager]setObject:obj];




Outside the finish:^ block
But then I lose all the data obtained from api call.



Object is declared as below @interface Object : NSObject
@property (strong, nonatomic) NSMutableDictionary *sch;







objective-c asynchronous objective-c-blocks






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 14:34







humble_pie

















asked Nov 16 '18 at 10:51









humble_piehumble_pie

446




446








  • 1





    And what's the error message? What I don't understand is what is obj on that line? Because in the code before, it's a local var.

    – Larme
    Nov 16 '18 at 12:56











  • @Larme I updated the code, and error I am getting and also added the line which explains when the error disappears, but I lose the data.

    – humble_pie
    Nov 16 '18 at 14:15






  • 2





    __NSDictionaryI means NSImmutableDictionary (that's why there is an uppercase "i" at the end), in other words, a NSDictionary, not a NSMutableDictionary.

    – Larme
    Nov 16 '18 at 14:26






  • 1





    If you have a new issue, post a new question with clear and specific details. And you may as well delete this question.

    – rmaddy
    Nov 16 '18 at 16:41






  • 1





    My comment wasn't actaually an attenpt to fix your issue, only additional information. Please follow rmaddys advice and create a new question for the new issue.

    – Julian F. Weinert
    Nov 17 '18 at 18:38














  • 1





    And what's the error message? What I don't understand is what is obj on that line? Because in the code before, it's a local var.

    – Larme
    Nov 16 '18 at 12:56











  • @Larme I updated the code, and error I am getting and also added the line which explains when the error disappears, but I lose the data.

    – humble_pie
    Nov 16 '18 at 14:15






  • 2





    __NSDictionaryI means NSImmutableDictionary (that's why there is an uppercase "i" at the end), in other words, a NSDictionary, not a NSMutableDictionary.

    – Larme
    Nov 16 '18 at 14:26






  • 1





    If you have a new issue, post a new question with clear and specific details. And you may as well delete this question.

    – rmaddy
    Nov 16 '18 at 16:41






  • 1





    My comment wasn't actaually an attenpt to fix your issue, only additional information. Please follow rmaddys advice and create a new question for the new issue.

    – Julian F. Weinert
    Nov 17 '18 at 18:38








1




1





And what's the error message? What I don't understand is what is obj on that line? Because in the code before, it's a local var.

– Larme
Nov 16 '18 at 12:56





And what's the error message? What I don't understand is what is obj on that line? Because in the code before, it's a local var.

– Larme
Nov 16 '18 at 12:56













@Larme I updated the code, and error I am getting and also added the line which explains when the error disappears, but I lose the data.

– humble_pie
Nov 16 '18 at 14:15





@Larme I updated the code, and error I am getting and also added the line which explains when the error disappears, but I lose the data.

– humble_pie
Nov 16 '18 at 14:15




2




2





__NSDictionaryI means NSImmutableDictionary (that's why there is an uppercase "i" at the end), in other words, a NSDictionary, not a NSMutableDictionary.

– Larme
Nov 16 '18 at 14:26





__NSDictionaryI means NSImmutableDictionary (that's why there is an uppercase "i" at the end), in other words, a NSDictionary, not a NSMutableDictionary.

– Larme
Nov 16 '18 at 14:26




1




1





If you have a new issue, post a new question with clear and specific details. And you may as well delete this question.

– rmaddy
Nov 16 '18 at 16:41





If you have a new issue, post a new question with clear and specific details. And you may as well delete this question.

– rmaddy
Nov 16 '18 at 16:41




1




1





My comment wasn't actaually an attenpt to fix your issue, only additional information. Please follow rmaddys advice and create a new question for the new issue.

– Julian F. Weinert
Nov 17 '18 at 18:38





My comment wasn't actaually an attenpt to fix your issue, only additional information. Please follow rmaddys advice and create a new question for the new issue.

– Julian F. Weinert
Nov 17 '18 at 18:38












0






active

oldest

votes












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%2f53336370%2fwhy-cannot-i-modify-an-object-inside-my-method%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53336370%2fwhy-cannot-i-modify-an-object-inside-my-method%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

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python