Cannot convert type 'Void' to 'String' in coercion in Swift
So i'm using some libraries and one of the methods, has supposedly return value
let data2 = dataCollector.collectCardFraudData({ ( str:String) in })
But the problem is that the return value is of void type but i could see the value present in it, i've checked a lot of tutorials where they have suggested to change the return type, but since this being a library i don't think i can do that.Is there any other way to get that value converted to string ??
I'm also kinda new Swift, so please any inputs would be helpfull
Thanks
ios swift braintree braintree-sandbox braintree-data
add a comment |
So i'm using some libraries and one of the methods, has supposedly return value
let data2 = dataCollector.collectCardFraudData({ ( str:String) in })
But the problem is that the return value is of void type but i could see the value present in it, i've checked a lot of tutorials where they have suggested to change the return type, but since this being a library i don't think i can do that.Is there any other way to get that value converted to string ??
I'm also kinda new Swift, so please any inputs would be helpfull
Thanks
ios swift braintree braintree-sandbox braintree-data
2
Please add the declaration line ofcollectCardFraudData
– vadian
Nov 21 '18 at 10:18
- (void)collectCardFraudData:(void (^)(NSString *deviceData))completion;
– Sam
Nov 21 '18 at 10:25
not sure if this helps
– Sam
Nov 21 '18 at 10:25
@Sam collectCardFraudData not a return any value. this is a compilation block.if get a string inside a block
– Dixit Akabari
Nov 21 '18 at 10:26
add a comment |
So i'm using some libraries and one of the methods, has supposedly return value
let data2 = dataCollector.collectCardFraudData({ ( str:String) in })
But the problem is that the return value is of void type but i could see the value present in it, i've checked a lot of tutorials where they have suggested to change the return type, but since this being a library i don't think i can do that.Is there any other way to get that value converted to string ??
I'm also kinda new Swift, so please any inputs would be helpfull
Thanks
ios swift braintree braintree-sandbox braintree-data
So i'm using some libraries and one of the methods, has supposedly return value
let data2 = dataCollector.collectCardFraudData({ ( str:String) in })
But the problem is that the return value is of void type but i could see the value present in it, i've checked a lot of tutorials where they have suggested to change the return type, but since this being a library i don't think i can do that.Is there any other way to get that value converted to string ??
I'm also kinda new Swift, so please any inputs would be helpfull
Thanks
ios swift braintree braintree-sandbox braintree-data
ios swift braintree braintree-sandbox braintree-data
asked Nov 21 '18 at 10:14
Sam
103
103
2
Please add the declaration line ofcollectCardFraudData
– vadian
Nov 21 '18 at 10:18
- (void)collectCardFraudData:(void (^)(NSString *deviceData))completion;
– Sam
Nov 21 '18 at 10:25
not sure if this helps
– Sam
Nov 21 '18 at 10:25
@Sam collectCardFraudData not a return any value. this is a compilation block.if get a string inside a block
– Dixit Akabari
Nov 21 '18 at 10:26
add a comment |
2
Please add the declaration line ofcollectCardFraudData
– vadian
Nov 21 '18 at 10:18
- (void)collectCardFraudData:(void (^)(NSString *deviceData))completion;
– Sam
Nov 21 '18 at 10:25
not sure if this helps
– Sam
Nov 21 '18 at 10:25
@Sam collectCardFraudData not a return any value. this is a compilation block.if get a string inside a block
– Dixit Akabari
Nov 21 '18 at 10:26
2
2
Please add the declaration line of
collectCardFraudData
– vadian
Nov 21 '18 at 10:18
Please add the declaration line of
collectCardFraudData
– vadian
Nov 21 '18 at 10:18
- (void)collectCardFraudData:(void (^)(NSString *deviceData))completion;
– Sam
Nov 21 '18 at 10:25
- (void)collectCardFraudData:(void (^)(NSString *deviceData))completion;
– Sam
Nov 21 '18 at 10:25
not sure if this helps
– Sam
Nov 21 '18 at 10:25
not sure if this helps
– Sam
Nov 21 '18 at 10:25
@Sam collectCardFraudData not a return any value. this is a compilation block.if get a string inside a block
– Dixit Akabari
Nov 21 '18 at 10:26
@Sam collectCardFraudData not a return any value. this is a compilation block.if get a string inside a block
– Dixit Akabari
Nov 21 '18 at 10:26
add a comment |
3 Answers
3
active
oldest
votes
The function has no return value. The Swift equivalent is
func collectCardFraudData(completion: @escaping (String) -> Void)
So you have to call it with the syntax below. deviceData
is passed as a parameter and you have to call completion
when you're done.
dataCollector.collectCardFraudData { deviceData in
// do something with deviceData
completion()
}
yea, this makes sense, thanks this helps :)
– Sam
Nov 21 '18 at 10:44
add a comment |
I don't know much. Just the guess. Your function is returning the value via completion handler. You should use it like this
let data2 = dataCollector.collectCardFraudData({ str in
print(str) // str available here
})
similar to accepted answer
– Mohammad Sadiq
Nov 21 '18 at 13:21
add a comment |
As collectCardFraudData has a closure where it give you 'str' value inside that block direct assigning it to 'data2' is causing you error.
Try below code and please let me know if it works
var data2 = String()
dataCollector.collectCardFraudData({ str in
data2 = "(str)"
})
Thank you
1.collectCardFraudData
may be async function, and this code won't work; 2."(str)"
— why?str
is already aString
, why do you need to interpolate it intoString
?
– user28434
Nov 21 '18 at 12:27
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%2f53409770%2fcannot-convert-type-void-to-string-in-coercion-in-swift%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The function has no return value. The Swift equivalent is
func collectCardFraudData(completion: @escaping (String) -> Void)
So you have to call it with the syntax below. deviceData
is passed as a parameter and you have to call completion
when you're done.
dataCollector.collectCardFraudData { deviceData in
// do something with deviceData
completion()
}
yea, this makes sense, thanks this helps :)
– Sam
Nov 21 '18 at 10:44
add a comment |
The function has no return value. The Swift equivalent is
func collectCardFraudData(completion: @escaping (String) -> Void)
So you have to call it with the syntax below. deviceData
is passed as a parameter and you have to call completion
when you're done.
dataCollector.collectCardFraudData { deviceData in
// do something with deviceData
completion()
}
yea, this makes sense, thanks this helps :)
– Sam
Nov 21 '18 at 10:44
add a comment |
The function has no return value. The Swift equivalent is
func collectCardFraudData(completion: @escaping (String) -> Void)
So you have to call it with the syntax below. deviceData
is passed as a parameter and you have to call completion
when you're done.
dataCollector.collectCardFraudData { deviceData in
// do something with deviceData
completion()
}
The function has no return value. The Swift equivalent is
func collectCardFraudData(completion: @escaping (String) -> Void)
So you have to call it with the syntax below. deviceData
is passed as a parameter and you have to call completion
when you're done.
dataCollector.collectCardFraudData { deviceData in
// do something with deviceData
completion()
}
answered Nov 21 '18 at 10:32
vadian
143k13154170
143k13154170
yea, this makes sense, thanks this helps :)
– Sam
Nov 21 '18 at 10:44
add a comment |
yea, this makes sense, thanks this helps :)
– Sam
Nov 21 '18 at 10:44
yea, this makes sense, thanks this helps :)
– Sam
Nov 21 '18 at 10:44
yea, this makes sense, thanks this helps :)
– Sam
Nov 21 '18 at 10:44
add a comment |
I don't know much. Just the guess. Your function is returning the value via completion handler. You should use it like this
let data2 = dataCollector.collectCardFraudData({ str in
print(str) // str available here
})
similar to accepted answer
– Mohammad Sadiq
Nov 21 '18 at 13:21
add a comment |
I don't know much. Just the guess. Your function is returning the value via completion handler. You should use it like this
let data2 = dataCollector.collectCardFraudData({ str in
print(str) // str available here
})
similar to accepted answer
– Mohammad Sadiq
Nov 21 '18 at 13:21
add a comment |
I don't know much. Just the guess. Your function is returning the value via completion handler. You should use it like this
let data2 = dataCollector.collectCardFraudData({ str in
print(str) // str available here
})
I don't know much. Just the guess. Your function is returning the value via completion handler. You should use it like this
let data2 = dataCollector.collectCardFraudData({ str in
print(str) // str available here
})
answered Nov 21 '18 at 10:25
Mohammad Sadiq
2,1681321
2,1681321
similar to accepted answer
– Mohammad Sadiq
Nov 21 '18 at 13:21
add a comment |
similar to accepted answer
– Mohammad Sadiq
Nov 21 '18 at 13:21
similar to accepted answer
– Mohammad Sadiq
Nov 21 '18 at 13:21
similar to accepted answer
– Mohammad Sadiq
Nov 21 '18 at 13:21
add a comment |
As collectCardFraudData has a closure where it give you 'str' value inside that block direct assigning it to 'data2' is causing you error.
Try below code and please let me know if it works
var data2 = String()
dataCollector.collectCardFraudData({ str in
data2 = "(str)"
})
Thank you
1.collectCardFraudData
may be async function, and this code won't work; 2."(str)"
— why?str
is already aString
, why do you need to interpolate it intoString
?
– user28434
Nov 21 '18 at 12:27
add a comment |
As collectCardFraudData has a closure where it give you 'str' value inside that block direct assigning it to 'data2' is causing you error.
Try below code and please let me know if it works
var data2 = String()
dataCollector.collectCardFraudData({ str in
data2 = "(str)"
})
Thank you
1.collectCardFraudData
may be async function, and this code won't work; 2."(str)"
— why?str
is already aString
, why do you need to interpolate it intoString
?
– user28434
Nov 21 '18 at 12:27
add a comment |
As collectCardFraudData has a closure where it give you 'str' value inside that block direct assigning it to 'data2' is causing you error.
Try below code and please let me know if it works
var data2 = String()
dataCollector.collectCardFraudData({ str in
data2 = "(str)"
})
Thank you
As collectCardFraudData has a closure where it give you 'str' value inside that block direct assigning it to 'data2' is causing you error.
Try below code and please let me know if it works
var data2 = String()
dataCollector.collectCardFraudData({ str in
data2 = "(str)"
})
Thank you
answered Nov 21 '18 at 10:30
Manish Patel
43
43
1.collectCardFraudData
may be async function, and this code won't work; 2."(str)"
— why?str
is already aString
, why do you need to interpolate it intoString
?
– user28434
Nov 21 '18 at 12:27
add a comment |
1.collectCardFraudData
may be async function, and this code won't work; 2."(str)"
— why?str
is already aString
, why do you need to interpolate it intoString
?
– user28434
Nov 21 '18 at 12:27
1.
collectCardFraudData
may be async function, and this code won't work; 2. "(str)"
— why? str
is already a String
, why do you need to interpolate it into String
?– user28434
Nov 21 '18 at 12:27
1.
collectCardFraudData
may be async function, and this code won't work; 2. "(str)"
— why? str
is already a String
, why do you need to interpolate it into String
?– user28434
Nov 21 '18 at 12:27
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53409770%2fcannot-convert-type-void-to-string-in-coercion-in-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
2
Please add the declaration line of
collectCardFraudData
– vadian
Nov 21 '18 at 10:18
- (void)collectCardFraudData:(void (^)(NSString *deviceData))completion;
– Sam
Nov 21 '18 at 10:25
not sure if this helps
– Sam
Nov 21 '18 at 10:25
@Sam collectCardFraudData not a return any value. this is a compilation block.if get a string inside a block
– Dixit Akabari
Nov 21 '18 at 10:26