How do I update this variable with data [on hold]2019 Community Moderator ElectionSwift closure with AlamofireHow to call Objective-C code from SwiftAsynchronous Request not properly updating variablesLocal and Global variables in SwiftHow to access a variable value outside of Parse's getObjectInBackgroundWithId blockCan't get closure to close over variablesSwift: function with custom data array(solved)->Accessing array outside of callHow to store response from dataTaskWithUrl in other variable?Declaring variable inside function not updating outside swiftVariable value becomes nil after fbsdk graph requestPassing variable outside of a function for use in Swift 3
Having the player face themselves after the mid-game
Outlet with 3 sets of wires
Why does cron require MTA for logging?
Should I take out a loan for a friend to invest on my behalf?
Power Strip for Europe
Is divide-by-zero a security vulnerability?
Has a sovereign Communist government ever run, and conceded loss, on a fair election?
how to modify custom status text color in UI component grid magento 2?
Doubts in understanding some concepts of potential energy
I reported the illegal activity of my boss to his boss. My boss found out. Now I am being punished. What should I do?
Professor forcing me to attend a conference, I can't afford even with 50% funding
Plausibility of Mushroom Buildings
I can't die. Who am I?
Haman going to the second feast dirty
After `ssh` without `-X` to a machine, is it possible to change `$DISPLAY` to make it work like `ssh -X`?
Is it possible that a question has only two answers?
Do items de-spawn?
Rationale to prefer local variables over instance variables?
Was it really inappropriate to write a pull request for the company I interviewed with?
Is it safe to abruptly remove Arduino power?
What is better: yes / no radio, or simple checkbox?
Trig Subsitution When There's No Square Root
When a wind turbine does not produce enough electricity how does the power company compensate for the loss?
Recommendation letter by significant other if you worked with them professionally?
How do I update this variable with data [on hold]
2019 Community Moderator ElectionSwift closure with AlamofireHow to call Objective-C code from SwiftAsynchronous Request not properly updating variablesLocal and Global variables in SwiftHow to access a variable value outside of Parse's getObjectInBackgroundWithId blockCan't get closure to close over variablesSwift: function with custom data array(solved)->Accessing array outside of callHow to store response from dataTaskWithUrl in other variable?Declaring variable inside function not updating outside swiftVariable value becomes nil after fbsdk graph requestPassing variable outside of a function for use in Swift 3
New programmer here! I'm working with a network request and below is a snippet of my code. After I complete the network request I want to store a value from the request into a variable. However, when the variable is called outside of the if let statement it is NOT updated. Essentially, the print statement inside the if let statement prints the value I'm looking for, but the print statement outside of the if let
statement prints the default value I set for that variable. The variable is global. I need to use that updated variable elsewhere in my code, any ideas?
if let data = data
self.nameLabel.text = data.name
person = data.name
print(person)
print(person)
swift
New contributor
put on hold as off-topic by rmaddy, Dale Burrell, Gilles Gouaillardet, Pablo Cegarra, Uma Madhavi Mar 7 at 8:05
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – rmaddy, Dale Burrell, Gilles Gouaillardet, Pablo Cegarra, Uma Madhavi
add a comment |
New programmer here! I'm working with a network request and below is a snippet of my code. After I complete the network request I want to store a value from the request into a variable. However, when the variable is called outside of the if let statement it is NOT updated. Essentially, the print statement inside the if let statement prints the value I'm looking for, but the print statement outside of the if let
statement prints the default value I set for that variable. The variable is global. I need to use that updated variable elsewhere in my code, any ideas?
if let data = data
self.nameLabel.text = data.name
person = data.name
print(person)
print(person)
swift
New contributor
put on hold as off-topic by rmaddy, Dale Burrell, Gilles Gouaillardet, Pablo Cegarra, Uma Madhavi Mar 7 at 8:05
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – rmaddy, Dale Burrell, Gilles Gouaillardet, Pablo Cegarra, Uma Madhavi
3
You don't show enough context. Most likely yourprint
is outside of the async completion block.
– rmaddy
Mar 7 at 5:06
Also try to replace one print something like print("(person) : person from inside"), makes debugging easier.
– Ebin Joy
Mar 7 at 5:14
add a comment |
New programmer here! I'm working with a network request and below is a snippet of my code. After I complete the network request I want to store a value from the request into a variable. However, when the variable is called outside of the if let statement it is NOT updated. Essentially, the print statement inside the if let statement prints the value I'm looking for, but the print statement outside of the if let
statement prints the default value I set for that variable. The variable is global. I need to use that updated variable elsewhere in my code, any ideas?
if let data = data
self.nameLabel.text = data.name
person = data.name
print(person)
print(person)
swift
New contributor
New programmer here! I'm working with a network request and below is a snippet of my code. After I complete the network request I want to store a value from the request into a variable. However, when the variable is called outside of the if let statement it is NOT updated. Essentially, the print statement inside the if let statement prints the value I'm looking for, but the print statement outside of the if let
statement prints the default value I set for that variable. The variable is global. I need to use that updated variable elsewhere in my code, any ideas?
if let data = data
self.nameLabel.text = data.name
person = data.name
print(person)
print(person)
swift
swift
New contributor
New contributor
edited Mar 7 at 8:29
azinwi
11612
11612
New contributor
asked Mar 7 at 5:04
Ayub DahirAyub Dahir
84
84
New contributor
New contributor
put on hold as off-topic by rmaddy, Dale Burrell, Gilles Gouaillardet, Pablo Cegarra, Uma Madhavi Mar 7 at 8:05
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – rmaddy, Dale Burrell, Gilles Gouaillardet, Pablo Cegarra, Uma Madhavi
put on hold as off-topic by rmaddy, Dale Burrell, Gilles Gouaillardet, Pablo Cegarra, Uma Madhavi Mar 7 at 8:05
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – rmaddy, Dale Burrell, Gilles Gouaillardet, Pablo Cegarra, Uma Madhavi
3
You don't show enough context. Most likely yourprint
is outside of the async completion block.
– rmaddy
Mar 7 at 5:06
Also try to replace one print something like print("(person) : person from inside"), makes debugging easier.
– Ebin Joy
Mar 7 at 5:14
add a comment |
3
You don't show enough context. Most likely yourprint
is outside of the async completion block.
– rmaddy
Mar 7 at 5:06
Also try to replace one print something like print("(person) : person from inside"), makes debugging easier.
– Ebin Joy
Mar 7 at 5:14
3
3
You don't show enough context. Most likely your
print
is outside of the async completion block.– rmaddy
Mar 7 at 5:06
You don't show enough context. Most likely your
print
is outside of the async completion block.– rmaddy
Mar 7 at 5:06
Also try to replace one print something like print("(person) : person from inside"), makes debugging easier.
– Ebin Joy
Mar 7 at 5:14
Also try to replace one print something like print("(person) : person from inside"), makes debugging easier.
– Ebin Joy
Mar 7 at 5:14
add a comment |
1 Answer
1
active
oldest
votes
First of all you didn't showed complete code so I am guessing you need main queue to update your UILabel
first as shown in below code:
DispatchQueue.main.async
self.nameLabel.text = data.name
next thing is if you want to access the value somewhere else once your request completes and UILabel
updated then you can get the value from it this way:
let value = self.nameLabel.text!
And if you want to access the value once request complete then you can use closure and HERE you can check example of it.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First of all you didn't showed complete code so I am guessing you need main queue to update your UILabel
first as shown in below code:
DispatchQueue.main.async
self.nameLabel.text = data.name
next thing is if you want to access the value somewhere else once your request completes and UILabel
updated then you can get the value from it this way:
let value = self.nameLabel.text!
And if you want to access the value once request complete then you can use closure and HERE you can check example of it.
add a comment |
First of all you didn't showed complete code so I am guessing you need main queue to update your UILabel
first as shown in below code:
DispatchQueue.main.async
self.nameLabel.text = data.name
next thing is if you want to access the value somewhere else once your request completes and UILabel
updated then you can get the value from it this way:
let value = self.nameLabel.text!
And if you want to access the value once request complete then you can use closure and HERE you can check example of it.
add a comment |
First of all you didn't showed complete code so I am guessing you need main queue to update your UILabel
first as shown in below code:
DispatchQueue.main.async
self.nameLabel.text = data.name
next thing is if you want to access the value somewhere else once your request completes and UILabel
updated then you can get the value from it this way:
let value = self.nameLabel.text!
And if you want to access the value once request complete then you can use closure and HERE you can check example of it.
First of all you didn't showed complete code so I am guessing you need main queue to update your UILabel
first as shown in below code:
DispatchQueue.main.async
self.nameLabel.text = data.name
next thing is if you want to access the value somewhere else once your request completes and UILabel
updated then you can get the value from it this way:
let value = self.nameLabel.text!
And if you want to access the value once request complete then you can use closure and HERE you can check example of it.
edited Mar 7 at 5:19
answered Mar 7 at 5:12
DharmeshDharmesh
51.2k23127151
51.2k23127151
add a comment |
add a comment |
3
You don't show enough context. Most likely your
print
is outside of the async completion block.– rmaddy
Mar 7 at 5:06
Also try to replace one print something like print("(person) : person from inside"), makes debugging easier.
– Ebin Joy
Mar 7 at 5:14