Function calling same parameter own parameters(Array) Swift












0















My question so basic.I cant call function with same array parameter as shown in the below.



import UIKit

var myArray = [String]() // <= This line from one class

func myArrayFunc1(arg_myArray: String...) { . //This function from same class with array
myArray = arg_myArray
}

func myArrayFunc2(arg2_myArray: String...) { //This function from another class
myArrayFunc1(arg_myArray: arg2_myArray) // <= This line gives error
}


My error is :
Cannot convert value of type '[String]' to expected argument type 'String'










share|improve this question























  • Please show the complete code along with the classes which hold the methods.

    – Rakesha Shastri
    Nov 26 '18 at 7:05








  • 1





    Known problem: bugs.swift.org/browse/SR-128

    – Gereon
    Nov 26 '18 at 7:07






  • 1





    Possible duplicate of How to forward functions with variadic parameters?

    – Cristik
    Nov 26 '18 at 7:47
















0















My question so basic.I cant call function with same array parameter as shown in the below.



import UIKit

var myArray = [String]() // <= This line from one class

func myArrayFunc1(arg_myArray: String...) { . //This function from same class with array
myArray = arg_myArray
}

func myArrayFunc2(arg2_myArray: String...) { //This function from another class
myArrayFunc1(arg_myArray: arg2_myArray) // <= This line gives error
}


My error is :
Cannot convert value of type '[String]' to expected argument type 'String'










share|improve this question























  • Please show the complete code along with the classes which hold the methods.

    – Rakesha Shastri
    Nov 26 '18 at 7:05








  • 1





    Known problem: bugs.swift.org/browse/SR-128

    – Gereon
    Nov 26 '18 at 7:07






  • 1





    Possible duplicate of How to forward functions with variadic parameters?

    – Cristik
    Nov 26 '18 at 7:47














0












0








0








My question so basic.I cant call function with same array parameter as shown in the below.



import UIKit

var myArray = [String]() // <= This line from one class

func myArrayFunc1(arg_myArray: String...) { . //This function from same class with array
myArray = arg_myArray
}

func myArrayFunc2(arg2_myArray: String...) { //This function from another class
myArrayFunc1(arg_myArray: arg2_myArray) // <= This line gives error
}


My error is :
Cannot convert value of type '[String]' to expected argument type 'String'










share|improve this question














My question so basic.I cant call function with same array parameter as shown in the below.



import UIKit

var myArray = [String]() // <= This line from one class

func myArrayFunc1(arg_myArray: String...) { . //This function from same class with array
myArray = arg_myArray
}

func myArrayFunc2(arg2_myArray: String...) { //This function from another class
myArrayFunc1(arg_myArray: arg2_myArray) // <= This line gives error
}


My error is :
Cannot convert value of type '[String]' to expected argument type 'String'







arrays swift






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 7:02









Qwe QweQwe Qwe

458




458













  • Please show the complete code along with the classes which hold the methods.

    – Rakesha Shastri
    Nov 26 '18 at 7:05








  • 1





    Known problem: bugs.swift.org/browse/SR-128

    – Gereon
    Nov 26 '18 at 7:07






  • 1





    Possible duplicate of How to forward functions with variadic parameters?

    – Cristik
    Nov 26 '18 at 7:47



















  • Please show the complete code along with the classes which hold the methods.

    – Rakesha Shastri
    Nov 26 '18 at 7:05








  • 1





    Known problem: bugs.swift.org/browse/SR-128

    – Gereon
    Nov 26 '18 at 7:07






  • 1





    Possible duplicate of How to forward functions with variadic parameters?

    – Cristik
    Nov 26 '18 at 7:47

















Please show the complete code along with the classes which hold the methods.

– Rakesha Shastri
Nov 26 '18 at 7:05







Please show the complete code along with the classes which hold the methods.

– Rakesha Shastri
Nov 26 '18 at 7:05






1




1





Known problem: bugs.swift.org/browse/SR-128

– Gereon
Nov 26 '18 at 7:07





Known problem: bugs.swift.org/browse/SR-128

– Gereon
Nov 26 '18 at 7:07




1




1





Possible duplicate of How to forward functions with variadic parameters?

– Cristik
Nov 26 '18 at 7:47





Possible duplicate of How to forward functions with variadic parameters?

– Cristik
Nov 26 '18 at 7:47












2 Answers
2






active

oldest

votes


















1














You can't assign arg_myArray as myArray because arg_myArray isn't array of strings but just single string.



If you need to assign new array as myArray replace this:



func myArrayFunc1(arg_myArray: String...) {
myArray = arg_myArray
}

func myArrayFunc2(arg2_myArray: String...) {
myArrayFunc1(arg_myArray: arg2_myArray)
}


with



func myArrayFunc1(arg_myArray: [String]) {
myArray = arg_myArray
}

func myArrayFunc2(arg2_myArray: [String]) {
myArrayFunc1(arg_myArray: arg2_myArray)
}


But if you need to just add single string to your string array you can use myArray.append(/* string */) to append new object (in your case string value) to array



func myArrayFunc1(arg_myArray: String) {
myArray.append(arg_myArray)
}

func myArrayFunc2(arg2_myArray: String) {
myArrayFunc1(arg_myArray: arg2_myArray)
}





share|improve this answer

































    0














    You can update this line like below.



    var myArray: [String] = [String]()





    share|improve this answer



















    • 2





      Although this code might solve the question, a good answer should always explain what the problem was and how this code helps.

      – BDL
      Nov 26 '18 at 9:19











    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%2f53476117%2ffunction-calling-same-parameter-own-parametersarray-swift%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









    1














    You can't assign arg_myArray as myArray because arg_myArray isn't array of strings but just single string.



    If you need to assign new array as myArray replace this:



    func myArrayFunc1(arg_myArray: String...) {
    myArray = arg_myArray
    }

    func myArrayFunc2(arg2_myArray: String...) {
    myArrayFunc1(arg_myArray: arg2_myArray)
    }


    with



    func myArrayFunc1(arg_myArray: [String]) {
    myArray = arg_myArray
    }

    func myArrayFunc2(arg2_myArray: [String]) {
    myArrayFunc1(arg_myArray: arg2_myArray)
    }


    But if you need to just add single string to your string array you can use myArray.append(/* string */) to append new object (in your case string value) to array



    func myArrayFunc1(arg_myArray: String) {
    myArray.append(arg_myArray)
    }

    func myArrayFunc2(arg2_myArray: String) {
    myArrayFunc1(arg_myArray: arg2_myArray)
    }





    share|improve this answer






























      1














      You can't assign arg_myArray as myArray because arg_myArray isn't array of strings but just single string.



      If you need to assign new array as myArray replace this:



      func myArrayFunc1(arg_myArray: String...) {
      myArray = arg_myArray
      }

      func myArrayFunc2(arg2_myArray: String...) {
      myArrayFunc1(arg_myArray: arg2_myArray)
      }


      with



      func myArrayFunc1(arg_myArray: [String]) {
      myArray = arg_myArray
      }

      func myArrayFunc2(arg2_myArray: [String]) {
      myArrayFunc1(arg_myArray: arg2_myArray)
      }


      But if you need to just add single string to your string array you can use myArray.append(/* string */) to append new object (in your case string value) to array



      func myArrayFunc1(arg_myArray: String) {
      myArray.append(arg_myArray)
      }

      func myArrayFunc2(arg2_myArray: String) {
      myArrayFunc1(arg_myArray: arg2_myArray)
      }





      share|improve this answer




























        1












        1








        1







        You can't assign arg_myArray as myArray because arg_myArray isn't array of strings but just single string.



        If you need to assign new array as myArray replace this:



        func myArrayFunc1(arg_myArray: String...) {
        myArray = arg_myArray
        }

        func myArrayFunc2(arg2_myArray: String...) {
        myArrayFunc1(arg_myArray: arg2_myArray)
        }


        with



        func myArrayFunc1(arg_myArray: [String]) {
        myArray = arg_myArray
        }

        func myArrayFunc2(arg2_myArray: [String]) {
        myArrayFunc1(arg_myArray: arg2_myArray)
        }


        But if you need to just add single string to your string array you can use myArray.append(/* string */) to append new object (in your case string value) to array



        func myArrayFunc1(arg_myArray: String) {
        myArray.append(arg_myArray)
        }

        func myArrayFunc2(arg2_myArray: String) {
        myArrayFunc1(arg_myArray: arg2_myArray)
        }





        share|improve this answer















        You can't assign arg_myArray as myArray because arg_myArray isn't array of strings but just single string.



        If you need to assign new array as myArray replace this:



        func myArrayFunc1(arg_myArray: String...) {
        myArray = arg_myArray
        }

        func myArrayFunc2(arg2_myArray: String...) {
        myArrayFunc1(arg_myArray: arg2_myArray)
        }


        with



        func myArrayFunc1(arg_myArray: [String]) {
        myArray = arg_myArray
        }

        func myArrayFunc2(arg2_myArray: [String]) {
        myArrayFunc1(arg_myArray: arg2_myArray)
        }


        But if you need to just add single string to your string array you can use myArray.append(/* string */) to append new object (in your case string value) to array



        func myArrayFunc1(arg_myArray: String) {
        myArray.append(arg_myArray)
        }

        func myArrayFunc2(arg2_myArray: String) {
        myArrayFunc1(arg_myArray: arg2_myArray)
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 26 '18 at 7:11

























        answered Nov 26 '18 at 7:05









        Robert DreslerRobert Dresler

        6,0802626




        6,0802626

























            0














            You can update this line like below.



            var myArray: [String] = [String]()





            share|improve this answer



















            • 2





              Although this code might solve the question, a good answer should always explain what the problem was and how this code helps.

              – BDL
              Nov 26 '18 at 9:19
















            0














            You can update this line like below.



            var myArray: [String] = [String]()





            share|improve this answer



















            • 2





              Although this code might solve the question, a good answer should always explain what the problem was and how this code helps.

              – BDL
              Nov 26 '18 at 9:19














            0












            0








            0







            You can update this line like below.



            var myArray: [String] = [String]()





            share|improve this answer













            You can update this line like below.



            var myArray: [String] = [String]()






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 26 '18 at 7:14









            ktr kathirktr kathir

            912624




            912624








            • 2





              Although this code might solve the question, a good answer should always explain what the problem was and how this code helps.

              – BDL
              Nov 26 '18 at 9:19














            • 2





              Although this code might solve the question, a good answer should always explain what the problem was and how this code helps.

              – BDL
              Nov 26 '18 at 9:19








            2




            2





            Although this code might solve the question, a good answer should always explain what the problem was and how this code helps.

            – BDL
            Nov 26 '18 at 9:19





            Although this code might solve the question, a good answer should always explain what the problem was and how this code helps.

            – BDL
            Nov 26 '18 at 9:19


















            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%2f53476117%2ffunction-calling-same-parameter-own-parametersarray-swift%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

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)