Cannot convert type 'Void' to 'String' in coercion in Swift












0














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










share|improve this question


















  • 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


















0














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










share|improve this question


















  • 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
















0












0








0







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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 10:14









Sam

103




103








  • 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
















  • 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










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














3 Answers
3






active

oldest

votes


















2














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()
}





share|improve this answer





















  • yea, this makes sense, thanks this helps :)
    – Sam
    Nov 21 '18 at 10:44



















-1














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
})





share|improve this answer





















  • similar to accepted answer
    – Mohammad Sadiq
    Nov 21 '18 at 13:21



















-1














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






share|improve this answer





















  • 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











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%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









2














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()
}





share|improve this answer





















  • yea, this makes sense, thanks this helps :)
    – Sam
    Nov 21 '18 at 10:44
















2














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()
}





share|improve this answer





















  • yea, this makes sense, thanks this helps :)
    – Sam
    Nov 21 '18 at 10:44














2












2








2






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()
}





share|improve this answer












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()
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 10:32









vadian

143k13154170




143k13154170












  • 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




yea, this makes sense, thanks this helps :)
– Sam
Nov 21 '18 at 10:44













-1














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
})





share|improve this answer





















  • similar to accepted answer
    – Mohammad Sadiq
    Nov 21 '18 at 13:21
















-1














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
})





share|improve this answer





















  • similar to accepted answer
    – Mohammad Sadiq
    Nov 21 '18 at 13:21














-1












-1








-1






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
})





share|improve this answer












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
})






share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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











-1














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






share|improve this answer





















  • 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














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






share|improve this answer





















  • 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












-1








-1






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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










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 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
















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


















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.





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.




draft saved


draft discarded














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





















































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

Wiesbaden

Marschland

Dieringhausen