Cannot convert value of type 'NSData?' to type 'Data' in coercion











up vote
0
down vote

favorite












Im trying to convert a base64 string to an UIImage



First. I decode the String as shown below



let decodedData = NSData(base64Encoded: decodeIMG, options: NSData.Base64DecodingOptions(rawValue: 0))


Then I try to convert the decoded data to an UIImage like this:



let decodedIamge = UIImage(data: decodedData as Data)


But on that line I get the following error:




Cannot convert value of type 'NSData?' to type 'Data' in coercion




I already tried using another approach to convert it by using an extension that looks like this



extension String {
//: ### Base64 encoding a string
func base64Encoded() -> String? {
if let data = self.data(using: .utf8) {
return data.base64EncodedString()
}
return nil
}

//: ### Base64 decoding a string
func base64Decoded() -> String? {
if let data = Data(base64Encoded: self) {
return String(data: data, encoding: .utf8)
}
return nil
}
}


And get this error




Incorrect argument label in call (have 'base64Encoded:', expected
'map:')











share|improve this question


















  • 1




    Why are you using NSData at all? Just use Data.
    – rmaddy
    Nov 9 at 19:54










  • It used to work like that, But then I updated Xcode and got this problem So instead of: let decodedData = NSData(base64Encoded: decodeIMG, options: NSData.Base64DecodingOptions(rawValue: 0)) I should do: let decodedData = Data(base64Encoded: decodeIMG) Thanks for your reply
    – Jesus Rojas
    Nov 9 at 19:56










  • String conversion to data using utf8 encoding will never return nil. return Data(utf8).base64EncodedString()
    – Leo Dabus
    Nov 9 at 20:04












  • @LeoDabus the error in the extension comes from the decoding part : Data(base64Encoded: self) - ERROR: Incorrect argument label in call (have 'base64Encoded:', expected 'map:') Thanks anyways
    – Jesus Rojas
    Nov 9 at 20:06






  • 1




    @LeoDabus It was the structure thing but the Structure was on another file lol Thank you so much <3
    – Jesus Rojas
    Nov 9 at 20:58















up vote
0
down vote

favorite












Im trying to convert a base64 string to an UIImage



First. I decode the String as shown below



let decodedData = NSData(base64Encoded: decodeIMG, options: NSData.Base64DecodingOptions(rawValue: 0))


Then I try to convert the decoded data to an UIImage like this:



let decodedIamge = UIImage(data: decodedData as Data)


But on that line I get the following error:




Cannot convert value of type 'NSData?' to type 'Data' in coercion




I already tried using another approach to convert it by using an extension that looks like this



extension String {
//: ### Base64 encoding a string
func base64Encoded() -> String? {
if let data = self.data(using: .utf8) {
return data.base64EncodedString()
}
return nil
}

//: ### Base64 decoding a string
func base64Decoded() -> String? {
if let data = Data(base64Encoded: self) {
return String(data: data, encoding: .utf8)
}
return nil
}
}


And get this error




Incorrect argument label in call (have 'base64Encoded:', expected
'map:')











share|improve this question


















  • 1




    Why are you using NSData at all? Just use Data.
    – rmaddy
    Nov 9 at 19:54










  • It used to work like that, But then I updated Xcode and got this problem So instead of: let decodedData = NSData(base64Encoded: decodeIMG, options: NSData.Base64DecodingOptions(rawValue: 0)) I should do: let decodedData = Data(base64Encoded: decodeIMG) Thanks for your reply
    – Jesus Rojas
    Nov 9 at 19:56










  • String conversion to data using utf8 encoding will never return nil. return Data(utf8).base64EncodedString()
    – Leo Dabus
    Nov 9 at 20:04












  • @LeoDabus the error in the extension comes from the decoding part : Data(base64Encoded: self) - ERROR: Incorrect argument label in call (have 'base64Encoded:', expected 'map:') Thanks anyways
    – Jesus Rojas
    Nov 9 at 20:06






  • 1




    @LeoDabus It was the structure thing but the Structure was on another file lol Thank you so much <3
    – Jesus Rojas
    Nov 9 at 20:58













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Im trying to convert a base64 string to an UIImage



First. I decode the String as shown below



let decodedData = NSData(base64Encoded: decodeIMG, options: NSData.Base64DecodingOptions(rawValue: 0))


Then I try to convert the decoded data to an UIImage like this:



let decodedIamge = UIImage(data: decodedData as Data)


But on that line I get the following error:




Cannot convert value of type 'NSData?' to type 'Data' in coercion




I already tried using another approach to convert it by using an extension that looks like this



extension String {
//: ### Base64 encoding a string
func base64Encoded() -> String? {
if let data = self.data(using: .utf8) {
return data.base64EncodedString()
}
return nil
}

//: ### Base64 decoding a string
func base64Decoded() -> String? {
if let data = Data(base64Encoded: self) {
return String(data: data, encoding: .utf8)
}
return nil
}
}


And get this error




Incorrect argument label in call (have 'base64Encoded:', expected
'map:')











share|improve this question













Im trying to convert a base64 string to an UIImage



First. I decode the String as shown below



let decodedData = NSData(base64Encoded: decodeIMG, options: NSData.Base64DecodingOptions(rawValue: 0))


Then I try to convert the decoded data to an UIImage like this:



let decodedIamge = UIImage(data: decodedData as Data)


But on that line I get the following error:




Cannot convert value of type 'NSData?' to type 'Data' in coercion




I already tried using another approach to convert it by using an extension that looks like this



extension String {
//: ### Base64 encoding a string
func base64Encoded() -> String? {
if let data = self.data(using: .utf8) {
return data.base64EncodedString()
}
return nil
}

//: ### Base64 decoding a string
func base64Decoded() -> String? {
if let data = Data(base64Encoded: self) {
return String(data: data, encoding: .utf8)
}
return nil
}
}


And get this error




Incorrect argument label in call (have 'base64Encoded:', expected
'map:')








ios swift uiimage base64






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 19:50









Jesus Rojas

1




1








  • 1




    Why are you using NSData at all? Just use Data.
    – rmaddy
    Nov 9 at 19:54










  • It used to work like that, But then I updated Xcode and got this problem So instead of: let decodedData = NSData(base64Encoded: decodeIMG, options: NSData.Base64DecodingOptions(rawValue: 0)) I should do: let decodedData = Data(base64Encoded: decodeIMG) Thanks for your reply
    – Jesus Rojas
    Nov 9 at 19:56










  • String conversion to data using utf8 encoding will never return nil. return Data(utf8).base64EncodedString()
    – Leo Dabus
    Nov 9 at 20:04












  • @LeoDabus the error in the extension comes from the decoding part : Data(base64Encoded: self) - ERROR: Incorrect argument label in call (have 'base64Encoded:', expected 'map:') Thanks anyways
    – Jesus Rojas
    Nov 9 at 20:06






  • 1




    @LeoDabus It was the structure thing but the Structure was on another file lol Thank you so much <3
    – Jesus Rojas
    Nov 9 at 20:58














  • 1




    Why are you using NSData at all? Just use Data.
    – rmaddy
    Nov 9 at 19:54










  • It used to work like that, But then I updated Xcode and got this problem So instead of: let decodedData = NSData(base64Encoded: decodeIMG, options: NSData.Base64DecodingOptions(rawValue: 0)) I should do: let decodedData = Data(base64Encoded: decodeIMG) Thanks for your reply
    – Jesus Rojas
    Nov 9 at 19:56










  • String conversion to data using utf8 encoding will never return nil. return Data(utf8).base64EncodedString()
    – Leo Dabus
    Nov 9 at 20:04












  • @LeoDabus the error in the extension comes from the decoding part : Data(base64Encoded: self) - ERROR: Incorrect argument label in call (have 'base64Encoded:', expected 'map:') Thanks anyways
    – Jesus Rojas
    Nov 9 at 20:06






  • 1




    @LeoDabus It was the structure thing but the Structure was on another file lol Thank you so much <3
    – Jesus Rojas
    Nov 9 at 20:58








1




1




Why are you using NSData at all? Just use Data.
– rmaddy
Nov 9 at 19:54




Why are you using NSData at all? Just use Data.
– rmaddy
Nov 9 at 19:54












It used to work like that, But then I updated Xcode and got this problem So instead of: let decodedData = NSData(base64Encoded: decodeIMG, options: NSData.Base64DecodingOptions(rawValue: 0)) I should do: let decodedData = Data(base64Encoded: decodeIMG) Thanks for your reply
– Jesus Rojas
Nov 9 at 19:56




It used to work like that, But then I updated Xcode and got this problem So instead of: let decodedData = NSData(base64Encoded: decodeIMG, options: NSData.Base64DecodingOptions(rawValue: 0)) I should do: let decodedData = Data(base64Encoded: decodeIMG) Thanks for your reply
– Jesus Rojas
Nov 9 at 19:56












String conversion to data using utf8 encoding will never return nil. return Data(utf8).base64EncodedString()
– Leo Dabus
Nov 9 at 20:04






String conversion to data using utf8 encoding will never return nil. return Data(utf8).base64EncodedString()
– Leo Dabus
Nov 9 at 20:04














@LeoDabus the error in the extension comes from the decoding part : Data(base64Encoded: self) - ERROR: Incorrect argument label in call (have 'base64Encoded:', expected 'map:') Thanks anyways
– Jesus Rojas
Nov 9 at 20:06




@LeoDabus the error in the extension comes from the decoding part : Data(base64Encoded: self) - ERROR: Incorrect argument label in call (have 'base64Encoded:', expected 'map:') Thanks anyways
– Jesus Rojas
Nov 9 at 20:06




1




1




@LeoDabus It was the structure thing but the Structure was on another file lol Thank you so much <3
– Jesus Rojas
Nov 9 at 20:58




@LeoDabus It was the structure thing but the Structure was on another file lol Thank you so much <3
– Jesus Rojas
Nov 9 at 20:58

















active

oldest

votes











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%2f53232411%2fcannot-convert-value-of-type-nsdata-to-type-data-in-coercion%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53232411%2fcannot-convert-value-of-type-nsdata-to-type-data-in-coercion%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







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()