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










1















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)









share|improve this question









New contributor




Ayub Dahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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
If this question can be reworded to fit the rules in the help center, please edit the question.











  • 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















1















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)









share|improve this question









New contributor




Ayub Dahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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
If this question can be reworded to fit the rules in the help center, please edit the question.











  • 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













1












1








1








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)









share|improve this question









New contributor




Ayub Dahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












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






share|improve this question









New contributor




Ayub Dahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Ayub Dahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Mar 7 at 8:29









azinwi

11612




11612






New contributor




Ayub Dahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Mar 7 at 5:04









Ayub DahirAyub Dahir

84




84




New contributor




Ayub Dahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Ayub Dahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Ayub Dahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




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
If this question can be reworded to fit the rules in the help center, please edit the question.







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
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 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












  • 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







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












1 Answer
1






active

oldest

votes


















3














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.






share|improve this answer































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    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.






    share|improve this answer





























      3














      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.






      share|improve this answer



























        3












        3








        3







        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.






        share|improve this answer















        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 7 at 5:19

























        answered Mar 7 at 5:12









        DharmeshDharmesh

        51.2k23127151




        51.2k23127151















            Popular posts from this blog

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme