Swift Data(contentsOf) Arguement passed to Call that takes no Arguements
let url = URL(string: "http://i.imgur.com/w5rkSIj.jpg")
let data = try? Data(contentsOf: url)
if let imageData = data {
let image = UIImage(data: imageData)
}
I am trying to do the above for loading an image from url but when i type the Data(contentsOf: url)
line i get an error saying "Argument passed to call that takes no argumens".
What may be causing this? NSData(contentsOf: url
) works but i need the Data one
ios swift xcode macos download
add a comment |
let url = URL(string: "http://i.imgur.com/w5rkSIj.jpg")
let data = try? Data(contentsOf: url)
if let imageData = data {
let image = UIImage(data: imageData)
}
I am trying to do the above for loading an image from url but when i type the Data(contentsOf: url)
line i get an error saying "Argument passed to call that takes no argumens".
What may be causing this? NSData(contentsOf: url
) works but i need the Data one
ios swift xcode macos download
Are you sure that's the error you're getting? You should be getting this error:error: value of optional type 'URL?' must be unwrapped to a value of type 'URL'
, because you have not unwrapped yoururl
variable. (At least that's what I get when pasting this code into a playground.)
– TylerTheCompiler
Dec 31 '18 at 7:45
Yes, I am sure of the error, I'm thinking I'm missing some kind of import so I addedimport foundation
but it didn't work, also I am running this in a UITableViewCell, .xib file, if that makes any difference.
– Kidd Kidd
Dec 31 '18 at 7:49
Is there a custom structData
?
– vadian
Dec 31 '18 at 7:50
No there is no custom struct data
– Kidd Kidd
Dec 31 '18 at 7:52
1
Yoururl
is an optional, and you need to unwrap it.
– Martin R
Dec 31 '18 at 9:14
add a comment |
let url = URL(string: "http://i.imgur.com/w5rkSIj.jpg")
let data = try? Data(contentsOf: url)
if let imageData = data {
let image = UIImage(data: imageData)
}
I am trying to do the above for loading an image from url but when i type the Data(contentsOf: url)
line i get an error saying "Argument passed to call that takes no argumens".
What may be causing this? NSData(contentsOf: url
) works but i need the Data one
ios swift xcode macos download
let url = URL(string: "http://i.imgur.com/w5rkSIj.jpg")
let data = try? Data(contentsOf: url)
if let imageData = data {
let image = UIImage(data: imageData)
}
I am trying to do the above for loading an image from url but when i type the Data(contentsOf: url)
line i get an error saying "Argument passed to call that takes no argumens".
What may be causing this? NSData(contentsOf: url
) works but i need the Data one
ios swift xcode macos download
ios swift xcode macos download
asked Dec 31 '18 at 7:14
Kidd KiddKidd Kidd
11
11
Are you sure that's the error you're getting? You should be getting this error:error: value of optional type 'URL?' must be unwrapped to a value of type 'URL'
, because you have not unwrapped yoururl
variable. (At least that's what I get when pasting this code into a playground.)
– TylerTheCompiler
Dec 31 '18 at 7:45
Yes, I am sure of the error, I'm thinking I'm missing some kind of import so I addedimport foundation
but it didn't work, also I am running this in a UITableViewCell, .xib file, if that makes any difference.
– Kidd Kidd
Dec 31 '18 at 7:49
Is there a custom structData
?
– vadian
Dec 31 '18 at 7:50
No there is no custom struct data
– Kidd Kidd
Dec 31 '18 at 7:52
1
Yoururl
is an optional, and you need to unwrap it.
– Martin R
Dec 31 '18 at 9:14
add a comment |
Are you sure that's the error you're getting? You should be getting this error:error: value of optional type 'URL?' must be unwrapped to a value of type 'URL'
, because you have not unwrapped yoururl
variable. (At least that's what I get when pasting this code into a playground.)
– TylerTheCompiler
Dec 31 '18 at 7:45
Yes, I am sure of the error, I'm thinking I'm missing some kind of import so I addedimport foundation
but it didn't work, also I am running this in a UITableViewCell, .xib file, if that makes any difference.
– Kidd Kidd
Dec 31 '18 at 7:49
Is there a custom structData
?
– vadian
Dec 31 '18 at 7:50
No there is no custom struct data
– Kidd Kidd
Dec 31 '18 at 7:52
1
Yoururl
is an optional, and you need to unwrap it.
– Martin R
Dec 31 '18 at 9:14
Are you sure that's the error you're getting? You should be getting this error:
error: value of optional type 'URL?' must be unwrapped to a value of type 'URL'
, because you have not unwrapped your url
variable. (At least that's what I get when pasting this code into a playground.)– TylerTheCompiler
Dec 31 '18 at 7:45
Are you sure that's the error you're getting? You should be getting this error:
error: value of optional type 'URL?' must be unwrapped to a value of type 'URL'
, because you have not unwrapped your url
variable. (At least that's what I get when pasting this code into a playground.)– TylerTheCompiler
Dec 31 '18 at 7:45
Yes, I am sure of the error, I'm thinking I'm missing some kind of import so I added
import foundation
but it didn't work, also I am running this in a UITableViewCell, .xib file, if that makes any difference.– Kidd Kidd
Dec 31 '18 at 7:49
Yes, I am sure of the error, I'm thinking I'm missing some kind of import so I added
import foundation
but it didn't work, also I am running this in a UITableViewCell, .xib file, if that makes any difference.– Kidd Kidd
Dec 31 '18 at 7:49
Is there a custom struct
Data
?– vadian
Dec 31 '18 at 7:50
Is there a custom struct
Data
?– vadian
Dec 31 '18 at 7:50
No there is no custom struct data
– Kidd Kidd
Dec 31 '18 at 7:52
No there is no custom struct data
– Kidd Kidd
Dec 31 '18 at 7:52
1
1
Your
url
is an optional, and you need to unwrap it.– Martin R
Dec 31 '18 at 9:14
Your
url
is an optional, and you need to unwrap it.– Martin R
Dec 31 '18 at 9:14
add a comment |
1 Answer
1
active
oldest
votes
url is optional variable so use optional binding
guard let url = URL(string: "http://i.imgur.com/w5rkSIj.jpg") else {
return
}
let data = try? Data(contentsOf: url)
if let imageData = data {
let image = UIImage(data: imageData)
}
The issue is not with the url, The Data function seems to not exist.
– Kidd Kidd
Dec 31 '18 at 13:08
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%2f53984651%2fswift-datacontentsof-arguement-passed-to-call-that-takes-no-arguements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
url is optional variable so use optional binding
guard let url = URL(string: "http://i.imgur.com/w5rkSIj.jpg") else {
return
}
let data = try? Data(contentsOf: url)
if let imageData = data {
let image = UIImage(data: imageData)
}
The issue is not with the url, The Data function seems to not exist.
– Kidd Kidd
Dec 31 '18 at 13:08
add a comment |
url is optional variable so use optional binding
guard let url = URL(string: "http://i.imgur.com/w5rkSIj.jpg") else {
return
}
let data = try? Data(contentsOf: url)
if let imageData = data {
let image = UIImage(data: imageData)
}
The issue is not with the url, The Data function seems to not exist.
– Kidd Kidd
Dec 31 '18 at 13:08
add a comment |
url is optional variable so use optional binding
guard let url = URL(string: "http://i.imgur.com/w5rkSIj.jpg") else {
return
}
let data = try? Data(contentsOf: url)
if let imageData = data {
let image = UIImage(data: imageData)
}
url is optional variable so use optional binding
guard let url = URL(string: "http://i.imgur.com/w5rkSIj.jpg") else {
return
}
let data = try? Data(contentsOf: url)
if let imageData = data {
let image = UIImage(data: imageData)
}
answered Dec 31 '18 at 10:30
Sourabh KumbharSourabh Kumbhar
19914
19914
The issue is not with the url, The Data function seems to not exist.
– Kidd Kidd
Dec 31 '18 at 13:08
add a comment |
The issue is not with the url, The Data function seems to not exist.
– Kidd Kidd
Dec 31 '18 at 13:08
The issue is not with the url, The Data function seems to not exist.
– Kidd Kidd
Dec 31 '18 at 13:08
The issue is not with the url, The Data function seems to not exist.
– Kidd Kidd
Dec 31 '18 at 13:08
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%2f53984651%2fswift-datacontentsof-arguement-passed-to-call-that-takes-no-arguements%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
Are you sure that's the error you're getting? You should be getting this error:
error: value of optional type 'URL?' must be unwrapped to a value of type 'URL'
, because you have not unwrapped yoururl
variable. (At least that's what I get when pasting this code into a playground.)– TylerTheCompiler
Dec 31 '18 at 7:45
Yes, I am sure of the error, I'm thinking I'm missing some kind of import so I added
import foundation
but it didn't work, also I am running this in a UITableViewCell, .xib file, if that makes any difference.– Kidd Kidd
Dec 31 '18 at 7:49
Is there a custom struct
Data
?– vadian
Dec 31 '18 at 7:50
No there is no custom struct data
– Kidd Kidd
Dec 31 '18 at 7:52
1
Your
url
is an optional, and you need to unwrap it.– Martin R
Dec 31 '18 at 9:14