Can't change input Value in Swift 4.2











up vote
-1
down vote

favorite












I have an input UITextField and want to change his value.



I defined this UITextField like this:



@IBOutlet weak var valueInput: UITextField!


Than in viewDidLoad() I make delegate - self:



valueInput?.delegate = self


and then in viewDidLoad I try to assign value to input like this:



if let priceIn = self.valueIn Input {
valueIn.text! = strPr // (this is var and it has String format I've checked it, and I also try to make print(strPr) and I get a value)
}


Unfortunately this string is not working:



valueIn.text! = strPr


But if I write something like this



valueIn.text! = "11"


This one will work.



I've tried to to something like this also, but it's not working also:



valueIn.text! = "(strPr)"


Anyone have any ideas?



Thanks for any answer, hope somebody had the same problem and know how to resolve it.










share|improve this question
























  • What do you mean by "it's not working"? Do you get a compile time error? What is the type of valueIn?
    – Daniel T.
    Nov 16 at 14:04












  • self.valueIn Input — what does it even mean? It is not valid Swift.
    – user28434
    Nov 16 at 14:10






  • 1




    Show the code where strPr is declared and populated – by the way please use more descriptive variable names. I guess it's a timing/asynchonous issue. And if you mean if let priceIn = self.valueInput this optional binding is pointless because the outlet is connected reliably before viewDidLoad is called.
    – vadian
    Nov 16 at 14:14












  • Yes print(strPr) before valueIn.text! = strPr
    – canister_exister
    Nov 16 at 14:47












  • Delete this line if let priceIn = self.valueIn Input {
    – canister_exister
    Nov 16 at 14:52















up vote
-1
down vote

favorite












I have an input UITextField and want to change his value.



I defined this UITextField like this:



@IBOutlet weak var valueInput: UITextField!


Than in viewDidLoad() I make delegate - self:



valueInput?.delegate = self


and then in viewDidLoad I try to assign value to input like this:



if let priceIn = self.valueIn Input {
valueIn.text! = strPr // (this is var and it has String format I've checked it, and I also try to make print(strPr) and I get a value)
}


Unfortunately this string is not working:



valueIn.text! = strPr


But if I write something like this



valueIn.text! = "11"


This one will work.



I've tried to to something like this also, but it's not working also:



valueIn.text! = "(strPr)"


Anyone have any ideas?



Thanks for any answer, hope somebody had the same problem and know how to resolve it.










share|improve this question
























  • What do you mean by "it's not working"? Do you get a compile time error? What is the type of valueIn?
    – Daniel T.
    Nov 16 at 14:04












  • self.valueIn Input — what does it even mean? It is not valid Swift.
    – user28434
    Nov 16 at 14:10






  • 1




    Show the code where strPr is declared and populated – by the way please use more descriptive variable names. I guess it's a timing/asynchonous issue. And if you mean if let priceIn = self.valueInput this optional binding is pointless because the outlet is connected reliably before viewDidLoad is called.
    – vadian
    Nov 16 at 14:14












  • Yes print(strPr) before valueIn.text! = strPr
    – canister_exister
    Nov 16 at 14:47












  • Delete this line if let priceIn = self.valueIn Input {
    – canister_exister
    Nov 16 at 14:52













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I have an input UITextField and want to change his value.



I defined this UITextField like this:



@IBOutlet weak var valueInput: UITextField!


Than in viewDidLoad() I make delegate - self:



valueInput?.delegate = self


and then in viewDidLoad I try to assign value to input like this:



if let priceIn = self.valueIn Input {
valueIn.text! = strPr // (this is var and it has String format I've checked it, and I also try to make print(strPr) and I get a value)
}


Unfortunately this string is not working:



valueIn.text! = strPr


But if I write something like this



valueIn.text! = "11"


This one will work.



I've tried to to something like this also, but it's not working also:



valueIn.text! = "(strPr)"


Anyone have any ideas?



Thanks for any answer, hope somebody had the same problem and know how to resolve it.










share|improve this question















I have an input UITextField and want to change his value.



I defined this UITextField like this:



@IBOutlet weak var valueInput: UITextField!


Than in viewDidLoad() I make delegate - self:



valueInput?.delegate = self


and then in viewDidLoad I try to assign value to input like this:



if let priceIn = self.valueIn Input {
valueIn.text! = strPr // (this is var and it has String format I've checked it, and I also try to make print(strPr) and I get a value)
}


Unfortunately this string is not working:



valueIn.text! = strPr


But if I write something like this



valueIn.text! = "11"


This one will work.



I've tried to to something like this also, but it's not working also:



valueIn.text! = "(strPr)"


Anyone have any ideas?



Thanks for any answer, hope somebody had the same problem and know how to resolve it.







ios swift swift4.2 xcode10.1






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 at 14:07









vadian

138k13144165




138k13144165










asked Nov 16 at 13:54









Vitaliy Mckay

608




608












  • What do you mean by "it's not working"? Do you get a compile time error? What is the type of valueIn?
    – Daniel T.
    Nov 16 at 14:04












  • self.valueIn Input — what does it even mean? It is not valid Swift.
    – user28434
    Nov 16 at 14:10






  • 1




    Show the code where strPr is declared and populated – by the way please use more descriptive variable names. I guess it's a timing/asynchonous issue. And if you mean if let priceIn = self.valueInput this optional binding is pointless because the outlet is connected reliably before viewDidLoad is called.
    – vadian
    Nov 16 at 14:14












  • Yes print(strPr) before valueIn.text! = strPr
    – canister_exister
    Nov 16 at 14:47












  • Delete this line if let priceIn = self.valueIn Input {
    – canister_exister
    Nov 16 at 14:52


















  • What do you mean by "it's not working"? Do you get a compile time error? What is the type of valueIn?
    – Daniel T.
    Nov 16 at 14:04












  • self.valueIn Input — what does it even mean? It is not valid Swift.
    – user28434
    Nov 16 at 14:10






  • 1




    Show the code where strPr is declared and populated – by the way please use more descriptive variable names. I guess it's a timing/asynchonous issue. And if you mean if let priceIn = self.valueInput this optional binding is pointless because the outlet is connected reliably before viewDidLoad is called.
    – vadian
    Nov 16 at 14:14












  • Yes print(strPr) before valueIn.text! = strPr
    – canister_exister
    Nov 16 at 14:47












  • Delete this line if let priceIn = self.valueIn Input {
    – canister_exister
    Nov 16 at 14:52
















What do you mean by "it's not working"? Do you get a compile time error? What is the type of valueIn?
– Daniel T.
Nov 16 at 14:04






What do you mean by "it's not working"? Do you get a compile time error? What is the type of valueIn?
– Daniel T.
Nov 16 at 14:04














self.valueIn Input — what does it even mean? It is not valid Swift.
– user28434
Nov 16 at 14:10




self.valueIn Input — what does it even mean? It is not valid Swift.
– user28434
Nov 16 at 14:10




1




1




Show the code where strPr is declared and populated – by the way please use more descriptive variable names. I guess it's a timing/asynchonous issue. And if you mean if let priceIn = self.valueInput this optional binding is pointless because the outlet is connected reliably before viewDidLoad is called.
– vadian
Nov 16 at 14:14






Show the code where strPr is declared and populated – by the way please use more descriptive variable names. I guess it's a timing/asynchonous issue. And if you mean if let priceIn = self.valueInput this optional binding is pointless because the outlet is connected reliably before viewDidLoad is called.
– vadian
Nov 16 at 14:14














Yes print(strPr) before valueIn.text! = strPr
– canister_exister
Nov 16 at 14:47






Yes print(strPr) before valueIn.text! = strPr
– canister_exister
Nov 16 at 14:47














Delete this line if let priceIn = self.valueIn Input {
– canister_exister
Nov 16 at 14:52




Delete this line if let priceIn = self.valueIn Input {
– canister_exister
Nov 16 at 14:52












1 Answer
1






active

oldest

votes

















up vote
0
down vote













These lines are wrong:



valueIn.text! = strPr
valueIn.text! = "11"


valueIn.text! should only appear on the right side, in case you are sure valueIn references a valid object (not nil) and text is declared as var text: String?



Not sure exactly how your variables are declared, but try something like this:



valueIn.text = "11"


Or, if strPtr is an Optional, try this:



if let strPr = strPr {
valueIn.text = strPr
print("New valueIn.text: (valueIn.text!)")
}





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',
    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%2f53339241%2fcant-change-input-value-in-swift-4-2%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    These lines are wrong:



    valueIn.text! = strPr
    valueIn.text! = "11"


    valueIn.text! should only appear on the right side, in case you are sure valueIn references a valid object (not nil) and text is declared as var text: String?



    Not sure exactly how your variables are declared, but try something like this:



    valueIn.text = "11"


    Or, if strPtr is an Optional, try this:



    if let strPr = strPr {
    valueIn.text = strPr
    print("New valueIn.text: (valueIn.text!)")
    }





    share|improve this answer

























      up vote
      0
      down vote













      These lines are wrong:



      valueIn.text! = strPr
      valueIn.text! = "11"


      valueIn.text! should only appear on the right side, in case you are sure valueIn references a valid object (not nil) and text is declared as var text: String?



      Not sure exactly how your variables are declared, but try something like this:



      valueIn.text = "11"


      Or, if strPtr is an Optional, try this:



      if let strPr = strPr {
      valueIn.text = strPr
      print("New valueIn.text: (valueIn.text!)")
      }





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        These lines are wrong:



        valueIn.text! = strPr
        valueIn.text! = "11"


        valueIn.text! should only appear on the right side, in case you are sure valueIn references a valid object (not nil) and text is declared as var text: String?



        Not sure exactly how your variables are declared, but try something like this:



        valueIn.text = "11"


        Or, if strPtr is an Optional, try this:



        if let strPr = strPr {
        valueIn.text = strPr
        print("New valueIn.text: (valueIn.text!)")
        }





        share|improve this answer












        These lines are wrong:



        valueIn.text! = strPr
        valueIn.text! = "11"


        valueIn.text! should only appear on the right side, in case you are sure valueIn references a valid object (not nil) and text is declared as var text: String?



        Not sure exactly how your variables are declared, but try something like this:



        valueIn.text = "11"


        Or, if strPtr is an Optional, try this:



        if let strPr = strPr {
        valueIn.text = strPr
        print("New valueIn.text: (valueIn.text!)")
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 at 14:35









        ppalancica

        2,81541832




        2,81541832






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339241%2fcant-change-input-value-in-swift-4-2%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