Optional value change once I step out the brackets?











up vote
-1
down vote

favorite












while I'm inside brackets



when I step over and get out the brackets



My code when login button clicked



  Alamofire.request(Constant.login, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: Header ).responseJSON { response in



if let JSON = response.result.value as? [String:Any] {

if let ActionResult = JSON["ActionResult"] as? [String:Any]{

if let Errcode = ActionResult["Errcode"] as? NSNumber {

if Errcode == NSNumber(value: 0) {



// users rules and priviledges
if let ActionData = JSON["ActionData"] as? [String:Any] {



if let IsAdmin = ActionData["IsAdmin"] as? Bool {
UserDefaults.standard.set(IsAdmin, forKey: "IsAdmin")

}
if let IsMonitor = ActionData["IsMonitor"] as? Bool {
UserDefaults.standard.set(IsMonitor, forKey: "IsMonitor")

}




self.performSegue(withIdentifier: "goTest", sender: self)
}

}

}

}

}

}


and here my code when logout button clicked



        DispatchQueue.main.async {

let defaults = UserDefaults.standard
defaults.removeObject(forKey: "IsAdmin")
defaults.removeObject(forKey: "IsMonitor")

}

//segue to login vc again
performSegue(withIdentifier: "LoginVC", sender: self)


IsContractor set to true while I'm between the two brackets but when I step over and get out of the brackets I noticed that the value has changed to false ? Any explain please



more clarification



when I login by IsAdmin rule then logout and re login when with IsContractor rule the userDefault still has the previous values which is true for IsAdmin and false for IsContractor



but when I remove the app from the background ( delete from the memory ) he takes the correct value which is false for IsAdmin and true for IsContractor










share|improve this question
























  • Is IsContractor defined outside the if also? If yes, then you have two variables with the same name.
    – Cristik
    Nov 18 at 8:14






  • 1




    Unrelated but never use KVC method setValue(_:forKey to save data in UserDefaults. Use always set(_ :forKey and please conform to the naming convention that variable names start with a lowercase letter. What do you mean with step over and get out of the brackets?
    – vadian
    Nov 18 at 8:19












  • @Cristik nope I don't have another value with same name
    – fares
    Nov 18 at 8:38










  • @vadian sure sir I was using set instead of setValue but got same result and what I mean with step over is that I make bread point and go forward step by step using the debugger in Xcode I hope its clear for you now
    – fares
    Nov 18 at 8:41










  • @fares IsContracter is valid only inside the brackets. So, what do you mean when you say "I step over and get out of the brackets I noticed that the value has changed to false"
    – Rakesha Shastri
    Nov 18 at 8:42















up vote
-1
down vote

favorite












while I'm inside brackets



when I step over and get out the brackets



My code when login button clicked



  Alamofire.request(Constant.login, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: Header ).responseJSON { response in



if let JSON = response.result.value as? [String:Any] {

if let ActionResult = JSON["ActionResult"] as? [String:Any]{

if let Errcode = ActionResult["Errcode"] as? NSNumber {

if Errcode == NSNumber(value: 0) {



// users rules and priviledges
if let ActionData = JSON["ActionData"] as? [String:Any] {



if let IsAdmin = ActionData["IsAdmin"] as? Bool {
UserDefaults.standard.set(IsAdmin, forKey: "IsAdmin")

}
if let IsMonitor = ActionData["IsMonitor"] as? Bool {
UserDefaults.standard.set(IsMonitor, forKey: "IsMonitor")

}




self.performSegue(withIdentifier: "goTest", sender: self)
}

}

}

}

}

}


and here my code when logout button clicked



        DispatchQueue.main.async {

let defaults = UserDefaults.standard
defaults.removeObject(forKey: "IsAdmin")
defaults.removeObject(forKey: "IsMonitor")

}

//segue to login vc again
performSegue(withIdentifier: "LoginVC", sender: self)


IsContractor set to true while I'm between the two brackets but when I step over and get out of the brackets I noticed that the value has changed to false ? Any explain please



more clarification



when I login by IsAdmin rule then logout and re login when with IsContractor rule the userDefault still has the previous values which is true for IsAdmin and false for IsContractor



but when I remove the app from the background ( delete from the memory ) he takes the correct value which is false for IsAdmin and true for IsContractor










share|improve this question
























  • Is IsContractor defined outside the if also? If yes, then you have two variables with the same name.
    – Cristik
    Nov 18 at 8:14






  • 1




    Unrelated but never use KVC method setValue(_:forKey to save data in UserDefaults. Use always set(_ :forKey and please conform to the naming convention that variable names start with a lowercase letter. What do you mean with step over and get out of the brackets?
    – vadian
    Nov 18 at 8:19












  • @Cristik nope I don't have another value with same name
    – fares
    Nov 18 at 8:38










  • @vadian sure sir I was using set instead of setValue but got same result and what I mean with step over is that I make bread point and go forward step by step using the debugger in Xcode I hope its clear for you now
    – fares
    Nov 18 at 8:41










  • @fares IsContracter is valid only inside the brackets. So, what do you mean when you say "I step over and get out of the brackets I noticed that the value has changed to false"
    – Rakesha Shastri
    Nov 18 at 8:42













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











while I'm inside brackets



when I step over and get out the brackets



My code when login button clicked



  Alamofire.request(Constant.login, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: Header ).responseJSON { response in



if let JSON = response.result.value as? [String:Any] {

if let ActionResult = JSON["ActionResult"] as? [String:Any]{

if let Errcode = ActionResult["Errcode"] as? NSNumber {

if Errcode == NSNumber(value: 0) {



// users rules and priviledges
if let ActionData = JSON["ActionData"] as? [String:Any] {



if let IsAdmin = ActionData["IsAdmin"] as? Bool {
UserDefaults.standard.set(IsAdmin, forKey: "IsAdmin")

}
if let IsMonitor = ActionData["IsMonitor"] as? Bool {
UserDefaults.standard.set(IsMonitor, forKey: "IsMonitor")

}




self.performSegue(withIdentifier: "goTest", sender: self)
}

}

}

}

}

}


and here my code when logout button clicked



        DispatchQueue.main.async {

let defaults = UserDefaults.standard
defaults.removeObject(forKey: "IsAdmin")
defaults.removeObject(forKey: "IsMonitor")

}

//segue to login vc again
performSegue(withIdentifier: "LoginVC", sender: self)


IsContractor set to true while I'm between the two brackets but when I step over and get out of the brackets I noticed that the value has changed to false ? Any explain please



more clarification



when I login by IsAdmin rule then logout and re login when with IsContractor rule the userDefault still has the previous values which is true for IsAdmin and false for IsContractor



but when I remove the app from the background ( delete from the memory ) he takes the correct value which is false for IsAdmin and true for IsContractor










share|improve this question















while I'm inside brackets



when I step over and get out the brackets



My code when login button clicked



  Alamofire.request(Constant.login, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: Header ).responseJSON { response in



if let JSON = response.result.value as? [String:Any] {

if let ActionResult = JSON["ActionResult"] as? [String:Any]{

if let Errcode = ActionResult["Errcode"] as? NSNumber {

if Errcode == NSNumber(value: 0) {



// users rules and priviledges
if let ActionData = JSON["ActionData"] as? [String:Any] {



if let IsAdmin = ActionData["IsAdmin"] as? Bool {
UserDefaults.standard.set(IsAdmin, forKey: "IsAdmin")

}
if let IsMonitor = ActionData["IsMonitor"] as? Bool {
UserDefaults.standard.set(IsMonitor, forKey: "IsMonitor")

}




self.performSegue(withIdentifier: "goTest", sender: self)
}

}

}

}

}

}


and here my code when logout button clicked



        DispatchQueue.main.async {

let defaults = UserDefaults.standard
defaults.removeObject(forKey: "IsAdmin")
defaults.removeObject(forKey: "IsMonitor")

}

//segue to login vc again
performSegue(withIdentifier: "LoginVC", sender: self)


IsContractor set to true while I'm between the two brackets but when I step over and get out of the brackets I noticed that the value has changed to false ? Any explain please



more clarification



when I login by IsAdmin rule then logout and re login when with IsContractor rule the userDefault still has the previous values which is true for IsAdmin and false for IsContractor



but when I remove the app from the background ( delete from the memory ) he takes the correct value which is false for IsAdmin and true for IsContractor







swift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 at 10:53

























asked Nov 18 at 8:05









fares

85




85












  • Is IsContractor defined outside the if also? If yes, then you have two variables with the same name.
    – Cristik
    Nov 18 at 8:14






  • 1




    Unrelated but never use KVC method setValue(_:forKey to save data in UserDefaults. Use always set(_ :forKey and please conform to the naming convention that variable names start with a lowercase letter. What do you mean with step over and get out of the brackets?
    – vadian
    Nov 18 at 8:19












  • @Cristik nope I don't have another value with same name
    – fares
    Nov 18 at 8:38










  • @vadian sure sir I was using set instead of setValue but got same result and what I mean with step over is that I make bread point and go forward step by step using the debugger in Xcode I hope its clear for you now
    – fares
    Nov 18 at 8:41










  • @fares IsContracter is valid only inside the brackets. So, what do you mean when you say "I step over and get out of the brackets I noticed that the value has changed to false"
    – Rakesha Shastri
    Nov 18 at 8:42


















  • Is IsContractor defined outside the if also? If yes, then you have two variables with the same name.
    – Cristik
    Nov 18 at 8:14






  • 1




    Unrelated but never use KVC method setValue(_:forKey to save data in UserDefaults. Use always set(_ :forKey and please conform to the naming convention that variable names start with a lowercase letter. What do you mean with step over and get out of the brackets?
    – vadian
    Nov 18 at 8:19












  • @Cristik nope I don't have another value with same name
    – fares
    Nov 18 at 8:38










  • @vadian sure sir I was using set instead of setValue but got same result and what I mean with step over is that I make bread point and go forward step by step using the debugger in Xcode I hope its clear for you now
    – fares
    Nov 18 at 8:41










  • @fares IsContracter is valid only inside the brackets. So, what do you mean when you say "I step over and get out of the brackets I noticed that the value has changed to false"
    – Rakesha Shastri
    Nov 18 at 8:42
















Is IsContractor defined outside the if also? If yes, then you have two variables with the same name.
– Cristik
Nov 18 at 8:14




Is IsContractor defined outside the if also? If yes, then you have two variables with the same name.
– Cristik
Nov 18 at 8:14




1




1




Unrelated but never use KVC method setValue(_:forKey to save data in UserDefaults. Use always set(_ :forKey and please conform to the naming convention that variable names start with a lowercase letter. What do you mean with step over and get out of the brackets?
– vadian
Nov 18 at 8:19






Unrelated but never use KVC method setValue(_:forKey to save data in UserDefaults. Use always set(_ :forKey and please conform to the naming convention that variable names start with a lowercase letter. What do you mean with step over and get out of the brackets?
– vadian
Nov 18 at 8:19














@Cristik nope I don't have another value with same name
– fares
Nov 18 at 8:38




@Cristik nope I don't have another value with same name
– fares
Nov 18 at 8:38












@vadian sure sir I was using set instead of setValue but got same result and what I mean with step over is that I make bread point and go forward step by step using the debugger in Xcode I hope its clear for you now
– fares
Nov 18 at 8:41




@vadian sure sir I was using set instead of setValue but got same result and what I mean with step over is that I make bread point and go forward step by step using the debugger in Xcode I hope its clear for you now
– fares
Nov 18 at 8:41












@fares IsContracter is valid only inside the brackets. So, what do you mean when you say "I step over and get out of the brackets I noticed that the value has changed to false"
– Rakesha Shastri
Nov 18 at 8:42




@fares IsContracter is valid only inside the brackets. So, what do you mean when you say "I step over and get out of the brackets I noticed that the value has changed to false"
– Rakesha Shastri
Nov 18 at 8:42

















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',
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%2f53358975%2foptional-value-change-once-i-step-out-the-brackets%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358975%2foptional-value-change-once-i-step-out-the-brackets%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

Costa Masnaga

Fotorealismo

Sidney Franklin