Edit and save profile error Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value...











up vote
0
down vote

favorite













This question already has an answer here:




  • What does “fatal error: unexpectedly found nil while unwrapping an Optional value” mean?

    8 answers




I'm trying to implement a ViewController feature to edit and save Profiles with the help of Firebase but, I get the error: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value when using this code below:



@IBAction func saveButton(_ sender: Any) {
var data = Data()
data = profileImage.image!.jpegData(compressionQuality: 0.1)!
DataService.dataService.SaveProfile(username: usernameTextfield.text!, email: emailTextfield.text!, data: data as NSData)
}









share|improve this question













marked as duplicate by vadian swift
Users with the  swift badge can single-handedly close swift questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 9:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • don't use ! if you are not sure that it must have value use this ?
    – wings
    Nov 20 at 9:26















up vote
0
down vote

favorite













This question already has an answer here:




  • What does “fatal error: unexpectedly found nil while unwrapping an Optional value” mean?

    8 answers




I'm trying to implement a ViewController feature to edit and save Profiles with the help of Firebase but, I get the error: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value when using this code below:



@IBAction func saveButton(_ sender: Any) {
var data = Data()
data = profileImage.image!.jpegData(compressionQuality: 0.1)!
DataService.dataService.SaveProfile(username: usernameTextfield.text!, email: emailTextfield.text!, data: data as NSData)
}









share|improve this question













marked as duplicate by vadian swift
Users with the  swift badge can single-handedly close swift questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 9:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • don't use ! if you are not sure that it must have value use this ?
    – wings
    Nov 20 at 9:26













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • What does “fatal error: unexpectedly found nil while unwrapping an Optional value” mean?

    8 answers




I'm trying to implement a ViewController feature to edit and save Profiles with the help of Firebase but, I get the error: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value when using this code below:



@IBAction func saveButton(_ sender: Any) {
var data = Data()
data = profileImage.image!.jpegData(compressionQuality: 0.1)!
DataService.dataService.SaveProfile(username: usernameTextfield.text!, email: emailTextfield.text!, data: data as NSData)
}









share|improve this question














This question already has an answer here:




  • What does “fatal error: unexpectedly found nil while unwrapping an Optional value” mean?

    8 answers




I'm trying to implement a ViewController feature to edit and save Profiles with the help of Firebase but, I get the error: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value when using this code below:



@IBAction func saveButton(_ sender: Any) {
var data = Data()
data = profileImage.image!.jpegData(compressionQuality: 0.1)!
DataService.dataService.SaveProfile(username: usernameTextfield.text!, email: emailTextfield.text!, data: data as NSData)
}




This question already has an answer here:




  • What does “fatal error: unexpectedly found nil while unwrapping an Optional value” mean?

    8 answers








swift xcode firebase






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 9:11









potatoonion

93




93




marked as duplicate by vadian swift
Users with the  swift badge can single-handedly close swift questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 9:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by vadian swift
Users with the  swift badge can single-handedly close swift questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 20 at 9:40


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • don't use ! if you are not sure that it must have value use this ?
    – wings
    Nov 20 at 9:26


















  • don't use ! if you are not sure that it must have value use this ?
    – wings
    Nov 20 at 9:26
















don't use ! if you are not sure that it must have value use this ?
– wings
Nov 20 at 9:26




don't use ! if you are not sure that it must have value use this ?
– wings
Nov 20 at 9:26












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










You may use following ( if let statements ) to check optional value errors.



@IBAction func saveButton(_ sender: Any) {
var data = Data()
if let image = profileImage.image {
if let data = image.jpegData(compressionQuality: 0.1) {
DataService.dataService.SaveProfile(username: usernameTextfield.text!, email: emailTextfield.text!, data: data as NSData)
}
}
}





share|improve this answer





















  • the code solved the error, but the save button don't work
    – potatoonion
    Nov 20 at 9:50






  • 1




    @potatoonion because you don't have a valid image in the image view.
    – Rakesha Shastri
    Nov 20 at 10:03












  • @RakeshaShastri um how do I fix that?
    – potatoonion
    Nov 20 at 10:17










  • It's your image view. You should store an image there?
    – Rakesha Shastri
    Nov 20 at 10:35










  • I tried store a image but nothing still happens when I click on the save button, thought it's also the username and email textfields that don't save either when I try to change it. Maybe something is wrong with the button?
    – potatoonion
    Nov 20 at 10:58


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










You may use following ( if let statements ) to check optional value errors.



@IBAction func saveButton(_ sender: Any) {
var data = Data()
if let image = profileImage.image {
if let data = image.jpegData(compressionQuality: 0.1) {
DataService.dataService.SaveProfile(username: usernameTextfield.text!, email: emailTextfield.text!, data: data as NSData)
}
}
}





share|improve this answer





















  • the code solved the error, but the save button don't work
    – potatoonion
    Nov 20 at 9:50






  • 1




    @potatoonion because you don't have a valid image in the image view.
    – Rakesha Shastri
    Nov 20 at 10:03












  • @RakeshaShastri um how do I fix that?
    – potatoonion
    Nov 20 at 10:17










  • It's your image view. You should store an image there?
    – Rakesha Shastri
    Nov 20 at 10:35










  • I tried store a image but nothing still happens when I click on the save button, thought it's also the username and email textfields that don't save either when I try to change it. Maybe something is wrong with the button?
    – potatoonion
    Nov 20 at 10:58















up vote
2
down vote



accepted










You may use following ( if let statements ) to check optional value errors.



@IBAction func saveButton(_ sender: Any) {
var data = Data()
if let image = profileImage.image {
if let data = image.jpegData(compressionQuality: 0.1) {
DataService.dataService.SaveProfile(username: usernameTextfield.text!, email: emailTextfield.text!, data: data as NSData)
}
}
}





share|improve this answer





















  • the code solved the error, but the save button don't work
    – potatoonion
    Nov 20 at 9:50






  • 1




    @potatoonion because you don't have a valid image in the image view.
    – Rakesha Shastri
    Nov 20 at 10:03












  • @RakeshaShastri um how do I fix that?
    – potatoonion
    Nov 20 at 10:17










  • It's your image view. You should store an image there?
    – Rakesha Shastri
    Nov 20 at 10:35










  • I tried store a image but nothing still happens when I click on the save button, thought it's also the username and email textfields that don't save either when I try to change it. Maybe something is wrong with the button?
    – potatoonion
    Nov 20 at 10:58













up vote
2
down vote



accepted







up vote
2
down vote



accepted






You may use following ( if let statements ) to check optional value errors.



@IBAction func saveButton(_ sender: Any) {
var data = Data()
if let image = profileImage.image {
if let data = image.jpegData(compressionQuality: 0.1) {
DataService.dataService.SaveProfile(username: usernameTextfield.text!, email: emailTextfield.text!, data: data as NSData)
}
}
}





share|improve this answer












You may use following ( if let statements ) to check optional value errors.



@IBAction func saveButton(_ sender: Any) {
var data = Data()
if let image = profileImage.image {
if let data = image.jpegData(compressionQuality: 0.1) {
DataService.dataService.SaveProfile(username: usernameTextfield.text!, email: emailTextfield.text!, data: data as NSData)
}
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 9:26









SHS

8321327




8321327












  • the code solved the error, but the save button don't work
    – potatoonion
    Nov 20 at 9:50






  • 1




    @potatoonion because you don't have a valid image in the image view.
    – Rakesha Shastri
    Nov 20 at 10:03












  • @RakeshaShastri um how do I fix that?
    – potatoonion
    Nov 20 at 10:17










  • It's your image view. You should store an image there?
    – Rakesha Shastri
    Nov 20 at 10:35










  • I tried store a image but nothing still happens when I click on the save button, thought it's also the username and email textfields that don't save either when I try to change it. Maybe something is wrong with the button?
    – potatoonion
    Nov 20 at 10:58


















  • the code solved the error, but the save button don't work
    – potatoonion
    Nov 20 at 9:50






  • 1




    @potatoonion because you don't have a valid image in the image view.
    – Rakesha Shastri
    Nov 20 at 10:03












  • @RakeshaShastri um how do I fix that?
    – potatoonion
    Nov 20 at 10:17










  • It's your image view. You should store an image there?
    – Rakesha Shastri
    Nov 20 at 10:35










  • I tried store a image but nothing still happens when I click on the save button, thought it's also the username and email textfields that don't save either when I try to change it. Maybe something is wrong with the button?
    – potatoonion
    Nov 20 at 10:58
















the code solved the error, but the save button don't work
– potatoonion
Nov 20 at 9:50




the code solved the error, but the save button don't work
– potatoonion
Nov 20 at 9:50




1




1




@potatoonion because you don't have a valid image in the image view.
– Rakesha Shastri
Nov 20 at 10:03






@potatoonion because you don't have a valid image in the image view.
– Rakesha Shastri
Nov 20 at 10:03














@RakeshaShastri um how do I fix that?
– potatoonion
Nov 20 at 10:17




@RakeshaShastri um how do I fix that?
– potatoonion
Nov 20 at 10:17












It's your image view. You should store an image there?
– Rakesha Shastri
Nov 20 at 10:35




It's your image view. You should store an image there?
– Rakesha Shastri
Nov 20 at 10:35












I tried store a image but nothing still happens when I click on the save button, thought it's also the username and email textfields that don't save either when I try to change it. Maybe something is wrong with the button?
– potatoonion
Nov 20 at 10:58




I tried store a image but nothing still happens when I click on the save button, thought it's also the username and email textfields that don't save either when I try to change it. Maybe something is wrong with the button?
– potatoonion
Nov 20 at 10:58



Popular posts from this blog

Feedback on college project

Futebolista

Albești (Vaslui)