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
swift
|
show 13 more comments
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
swift
IsIsContractor
defined outside theif
also? If yes, then you have two variables with the same name.
– Cristik
Nov 18 at 8:14
1
Unrelated but never use KVC methodsetValue(_:forKey
to save data inUserDefaults
. Use alwaysset(_ :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
@faresIsContracter
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
|
show 13 more comments
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
swift
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
swift
edited Nov 18 at 10:53
asked Nov 18 at 8:05
fares
85
85
IsIsContractor
defined outside theif
also? If yes, then you have two variables with the same name.
– Cristik
Nov 18 at 8:14
1
Unrelated but never use KVC methodsetValue(_:forKey
to save data inUserDefaults
. Use alwaysset(_ :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
@faresIsContracter
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
|
show 13 more comments
IsIsContractor
defined outside theif
also? If yes, then you have two variables with the same name.
– Cristik
Nov 18 at 8:14
1
Unrelated but never use KVC methodsetValue(_:forKey
to save data inUserDefaults
. Use alwaysset(_ :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
@faresIsContracter
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
|
show 13 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Is
IsContractor
defined outside theif
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 inUserDefaults
. Use alwaysset(_ :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