Function calling same parameter own parameters(Array) Swift
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
add a comment |
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
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
add a comment |
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
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
arrays swift
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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)
}
add a comment |
You can update this line like below.
var myArray: [String] = [String]()
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
}
add a comment |
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)
}
add a comment |
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)
}
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)
}
edited Nov 26 '18 at 7:11
answered Nov 26 '18 at 7:05
Robert DreslerRobert Dresler
6,0802626
6,0802626
add a comment |
add a comment |
You can update this line like below.
var myArray: [String] = [String]()
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
add a comment |
You can update this line like below.
var myArray: [String] = [String]()
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
add a comment |
You can update this line like below.
var myArray: [String] = [String]()
You can update this line like below.
var myArray: [String] = [String]()
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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