Expression type '@lvalue String?' is ambiguous without more context when += to UILabel.textHow to enumerate an enum with String type?How to get image from UIImagePickerController and Pass to next VCHow to hide and show label when navigation VC1 to VC2 back and forthSwift 2 iOS 9 animation disappears after button text changedUIAlertController action crashes with error exc_bad_access while performing network oparation of 5 to 6 secsUnable to dismiss MFMailComposeViewController from a separate ViewControllerHow to optimize UITableViewCell, because my UITableView lagsHow do I pass data from a UIViewController to UITabBarController?Swift Error - Use of undeclared type 'cell' - Collection ViewBMI app print result is 0 even with variable being hard coded

What defenses are there against being summoned by the Gate spell?

Is this a crack on the carbon frame?

How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?

What is the offset in a seaplane's hull?

How does one intimidate enemies without having the capacity for violence?

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?

Did Shadowfax go to Valinor?

What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)

Problem of parity - Can we draw a closed path made up of 20 line segments...

How to say job offer in Mandarin/Cantonese?

What's the output of a record cartridge playing an out-of-speed record

Do VLANs within a subnet need to have their own subnet for router on a stick?

Is it unprofessional to ask if a job posting on GlassDoor is real?

Minkowski space

Arthur Somervell: 1000 Exercises - Meaning of this notation

Why, historically, did Gödel think CH was false?

How do I create uniquely male characters?

In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?

can i play a electric guitar through a bass amp?

Theorems that impeded progress

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

Why are electrically insulating heatsinks so rare? Is it just cost?

Font hinting is lost in Chrome-like browsers (for some languages )

Why can't I see bouncing of a switch on an oscilloscope?



Expression type '@lvalue String?' is ambiguous without more context when += to UILabel.text


How to enumerate an enum with String type?How to get image from UIImagePickerController and Pass to next VCHow to hide and show label when navigation VC1 to VC2 back and forthSwift 2 iOS 9 animation disappears after button text changedUIAlertController action crashes with error exc_bad_access while performing network oparation of 5 to 6 secsUnable to dismiss MFMailComposeViewController from a separate ViewControllerHow to optimize UITableViewCell, because my UITableView lagsHow do I pass data from a UIViewController to UITabBarController?Swift Error - Use of undeclared type 'cell' - Collection ViewBMI app print result is 0 even with variable being hard coded






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying to add the string "7" to a label when someone tabs the button labeled 7.



But when using += "7", it gives me the error "Expression type '@lvalue String?' is ambiguous without more context", when using the operator = "7" it works fine. Why doesn't += "7" work?



class NumberPadController: UIViewController 
@IBOutlet weak var valueLabel: UILabel!

/// set value in main vc and return to that.
@IBAction func doneEntering(_ sender: Any)
guard let valueString = valueLabel.text, let valueDouble = Double(valueString), let presentingVC = self.presentingViewController as? ViewController else
// FIXME: Show error
dismiss(animated: true, completion: nil)
return


presentingVC.valuePassedFromNumPad = valueDouble
dismiss(animated: true, completion: nil)


@IBAction func seven(_ sender: Any)
valueLabel.text += "7" // Expression type '@lvalue String?' is ambiguous without more context
valueLabel.text = "a" // works fine











share|improve this question
























  • what the OP you expect , you want to perform some operation or else

    – Anbu.Karthik
    Mar 8 at 4:20











  • You just need to unwrap the optional value before adding up. Just make sure UILabel text property it is not nil before incrementing its value: valueLabel.text! += "7"

    – Leo Dabus
    Mar 8 at 4:37











  • It is worth saying that you should not use the UI to pass values around. If you need the label string value for future use you should keep a reference to its value.

    – Leo Dabus
    Mar 8 at 4:42


















0















I am trying to add the string "7" to a label when someone tabs the button labeled 7.



But when using += "7", it gives me the error "Expression type '@lvalue String?' is ambiguous without more context", when using the operator = "7" it works fine. Why doesn't += "7" work?



class NumberPadController: UIViewController 
@IBOutlet weak var valueLabel: UILabel!

/// set value in main vc and return to that.
@IBAction func doneEntering(_ sender: Any)
guard let valueString = valueLabel.text, let valueDouble = Double(valueString), let presentingVC = self.presentingViewController as? ViewController else
// FIXME: Show error
dismiss(animated: true, completion: nil)
return


presentingVC.valuePassedFromNumPad = valueDouble
dismiss(animated: true, completion: nil)


@IBAction func seven(_ sender: Any)
valueLabel.text += "7" // Expression type '@lvalue String?' is ambiguous without more context
valueLabel.text = "a" // works fine











share|improve this question
























  • what the OP you expect , you want to perform some operation or else

    – Anbu.Karthik
    Mar 8 at 4:20











  • You just need to unwrap the optional value before adding up. Just make sure UILabel text property it is not nil before incrementing its value: valueLabel.text! += "7"

    – Leo Dabus
    Mar 8 at 4:37











  • It is worth saying that you should not use the UI to pass values around. If you need the label string value for future use you should keep a reference to its value.

    – Leo Dabus
    Mar 8 at 4:42














0












0








0








I am trying to add the string "7" to a label when someone tabs the button labeled 7.



But when using += "7", it gives me the error "Expression type '@lvalue String?' is ambiguous without more context", when using the operator = "7" it works fine. Why doesn't += "7" work?



class NumberPadController: UIViewController 
@IBOutlet weak var valueLabel: UILabel!

/// set value in main vc and return to that.
@IBAction func doneEntering(_ sender: Any)
guard let valueString = valueLabel.text, let valueDouble = Double(valueString), let presentingVC = self.presentingViewController as? ViewController else
// FIXME: Show error
dismiss(animated: true, completion: nil)
return


presentingVC.valuePassedFromNumPad = valueDouble
dismiss(animated: true, completion: nil)


@IBAction func seven(_ sender: Any)
valueLabel.text += "7" // Expression type '@lvalue String?' is ambiguous without more context
valueLabel.text = "a" // works fine











share|improve this question
















I am trying to add the string "7" to a label when someone tabs the button labeled 7.



But when using += "7", it gives me the error "Expression type '@lvalue String?' is ambiguous without more context", when using the operator = "7" it works fine. Why doesn't += "7" work?



class NumberPadController: UIViewController 
@IBOutlet weak var valueLabel: UILabel!

/// set value in main vc and return to that.
@IBAction func doneEntering(_ sender: Any)
guard let valueString = valueLabel.text, let valueDouble = Double(valueString), let presentingVC = self.presentingViewController as? ViewController else
// FIXME: Show error
dismiss(animated: true, completion: nil)
return


presentingVC.valuePassedFromNumPad = valueDouble
dismiss(animated: true, completion: nil)


@IBAction func seven(_ sender: Any)
valueLabel.text += "7" // Expression type '@lvalue String?' is ambiguous without more context
valueLabel.text = "a" // works fine








ios swift uilabel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 8:44









AtulParmar

1,374623




1,374623










asked Mar 8 at 4:16









BruceBruce

441215




441215












  • what the OP you expect , you want to perform some operation or else

    – Anbu.Karthik
    Mar 8 at 4:20











  • You just need to unwrap the optional value before adding up. Just make sure UILabel text property it is not nil before incrementing its value: valueLabel.text! += "7"

    – Leo Dabus
    Mar 8 at 4:37











  • It is worth saying that you should not use the UI to pass values around. If you need the label string value for future use you should keep a reference to its value.

    – Leo Dabus
    Mar 8 at 4:42


















  • what the OP you expect , you want to perform some operation or else

    – Anbu.Karthik
    Mar 8 at 4:20











  • You just need to unwrap the optional value before adding up. Just make sure UILabel text property it is not nil before incrementing its value: valueLabel.text! += "7"

    – Leo Dabus
    Mar 8 at 4:37











  • It is worth saying that you should not use the UI to pass values around. If you need the label string value for future use you should keep a reference to its value.

    – Leo Dabus
    Mar 8 at 4:42

















what the OP you expect , you want to perform some operation or else

– Anbu.Karthik
Mar 8 at 4:20





what the OP you expect , you want to perform some operation or else

– Anbu.Karthik
Mar 8 at 4:20













You just need to unwrap the optional value before adding up. Just make sure UILabel text property it is not nil before incrementing its value: valueLabel.text! += "7"

– Leo Dabus
Mar 8 at 4:37





You just need to unwrap the optional value before adding up. Just make sure UILabel text property it is not nil before incrementing its value: valueLabel.text! += "7"

– Leo Dabus
Mar 8 at 4:37













It is worth saying that you should not use the UI to pass values around. If you need the label string value for future use you should keep a reference to its value.

– Leo Dabus
Mar 8 at 4:42






It is worth saying that you should not use the UI to pass values around. If you need the label string value for future use you should keep a reference to its value.

– Leo Dabus
Mar 8 at 4:42













2 Answers
2






active

oldest

votes


















3














The text property is optional. One way to do this safely would be to use append along with optional chaining:



valueLabel.text?.append("7")


or use += with optional chaining:



valueLabel.text? += "7"


If the label is nil, these would safely do nothing. If you'd like the label to be "7" if it was nil, then use @RickyMo's solution.






share|improve this answer

























  • How can I calculate my foodPrice label value with foodQuantity value? var quantity = 1 and foodPrice.text *= quantity. I am getting same error

    – Emre Değirmenci
    Mar 9 at 11:17







  • 1





    @EmreDeğirmenci, you need to take the String that is in foodPrice.text, convert it to a Double, multiply that by Double(quantity), then convert that Double back to a String. Something like let price = Double(foodPrice.text ?? "") ?? 0; let total = price * Double(quantity); foodPrice.text = "(total)"

    – vacawama
    Mar 9 at 12:58


















4














text property is optional. To do it safely :



valueLabel.text = (valueLabel.text ?? "") + "7"





share|improve this answer























    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%2f55056650%2fexpression-type-lvalue-string-is-ambiguous-without-more-context-when-to-u%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    The text property is optional. One way to do this safely would be to use append along with optional chaining:



    valueLabel.text?.append("7")


    or use += with optional chaining:



    valueLabel.text? += "7"


    If the label is nil, these would safely do nothing. If you'd like the label to be "7" if it was nil, then use @RickyMo's solution.






    share|improve this answer

























    • How can I calculate my foodPrice label value with foodQuantity value? var quantity = 1 and foodPrice.text *= quantity. I am getting same error

      – Emre Değirmenci
      Mar 9 at 11:17







    • 1





      @EmreDeğirmenci, you need to take the String that is in foodPrice.text, convert it to a Double, multiply that by Double(quantity), then convert that Double back to a String. Something like let price = Double(foodPrice.text ?? "") ?? 0; let total = price * Double(quantity); foodPrice.text = "(total)"

      – vacawama
      Mar 9 at 12:58















    3














    The text property is optional. One way to do this safely would be to use append along with optional chaining:



    valueLabel.text?.append("7")


    or use += with optional chaining:



    valueLabel.text? += "7"


    If the label is nil, these would safely do nothing. If you'd like the label to be "7" if it was nil, then use @RickyMo's solution.






    share|improve this answer

























    • How can I calculate my foodPrice label value with foodQuantity value? var quantity = 1 and foodPrice.text *= quantity. I am getting same error

      – Emre Değirmenci
      Mar 9 at 11:17







    • 1





      @EmreDeğirmenci, you need to take the String that is in foodPrice.text, convert it to a Double, multiply that by Double(quantity), then convert that Double back to a String. Something like let price = Double(foodPrice.text ?? "") ?? 0; let total = price * Double(quantity); foodPrice.text = "(total)"

      – vacawama
      Mar 9 at 12:58













    3












    3








    3







    The text property is optional. One way to do this safely would be to use append along with optional chaining:



    valueLabel.text?.append("7")


    or use += with optional chaining:



    valueLabel.text? += "7"


    If the label is nil, these would safely do nothing. If you'd like the label to be "7" if it was nil, then use @RickyMo's solution.






    share|improve this answer















    The text property is optional. One way to do this safely would be to use append along with optional chaining:



    valueLabel.text?.append("7")


    or use += with optional chaining:



    valueLabel.text? += "7"


    If the label is nil, these would safely do nothing. If you'd like the label to be "7" if it was nil, then use @RickyMo's solution.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 8 at 11:36

























    answered Mar 8 at 4:30









    vacawamavacawama

    99.7k15178204




    99.7k15178204












    • How can I calculate my foodPrice label value with foodQuantity value? var quantity = 1 and foodPrice.text *= quantity. I am getting same error

      – Emre Değirmenci
      Mar 9 at 11:17







    • 1





      @EmreDeğirmenci, you need to take the String that is in foodPrice.text, convert it to a Double, multiply that by Double(quantity), then convert that Double back to a String. Something like let price = Double(foodPrice.text ?? "") ?? 0; let total = price * Double(quantity); foodPrice.text = "(total)"

      – vacawama
      Mar 9 at 12:58

















    • How can I calculate my foodPrice label value with foodQuantity value? var quantity = 1 and foodPrice.text *= quantity. I am getting same error

      – Emre Değirmenci
      Mar 9 at 11:17







    • 1





      @EmreDeğirmenci, you need to take the String that is in foodPrice.text, convert it to a Double, multiply that by Double(quantity), then convert that Double back to a String. Something like let price = Double(foodPrice.text ?? "") ?? 0; let total = price * Double(quantity); foodPrice.text = "(total)"

      – vacawama
      Mar 9 at 12:58
















    How can I calculate my foodPrice label value with foodQuantity value? var quantity = 1 and foodPrice.text *= quantity. I am getting same error

    – Emre Değirmenci
    Mar 9 at 11:17






    How can I calculate my foodPrice label value with foodQuantity value? var quantity = 1 and foodPrice.text *= quantity. I am getting same error

    – Emre Değirmenci
    Mar 9 at 11:17





    1




    1





    @EmreDeğirmenci, you need to take the String that is in foodPrice.text, convert it to a Double, multiply that by Double(quantity), then convert that Double back to a String. Something like let price = Double(foodPrice.text ?? "") ?? 0; let total = price * Double(quantity); foodPrice.text = "(total)"

    – vacawama
    Mar 9 at 12:58





    @EmreDeğirmenci, you need to take the String that is in foodPrice.text, convert it to a Double, multiply that by Double(quantity), then convert that Double back to a String. Something like let price = Double(foodPrice.text ?? "") ?? 0; let total = price * Double(quantity); foodPrice.text = "(total)"

    – vacawama
    Mar 9 at 12:58













    4














    text property is optional. To do it safely :



    valueLabel.text = (valueLabel.text ?? "") + "7"





    share|improve this answer



























      4














      text property is optional. To do it safely :



      valueLabel.text = (valueLabel.text ?? "") + "7"





      share|improve this answer

























        4












        4








        4







        text property is optional. To do it safely :



        valueLabel.text = (valueLabel.text ?? "") + "7"





        share|improve this answer













        text property is optional. To do it safely :



        valueLabel.text = (valueLabel.text ?? "") + "7"






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 4:23









        Ricky MoRicky Mo

        1,9771212




        1,9771212



























            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%2f55056650%2fexpression-type-lvalue-string-is-ambiguous-without-more-context-when-to-u%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

            1928 у кіно

            Захаров Федір Захарович

            Ель Греко