conditional binding must have Optional type, not 'String' [duplicate]Conditional Binding: if let error – Initializer for conditional binding must have Optional typeBound value in a conditional binding must be of optional typeConditional Binding: if let error – Initializer for conditional binding must have Optional typeInitializer for conditional binding must have Optional type, not 'NSManagedObjectContextInitializer for conditional binding must have Optional type, not 'String' on HTTPCookieStorageError: Initializer for conditional binding must have optional type, not 'String'“Initializer for conditional binding must have Optional type, not '[String]'”Initialzer for conditional binding must have Optional type not 'String'Firebase update: Initializer for conditional binding must have Optional type, not 'String'iOS Swift: Initializer for conditional binding must have Optional type, not '() -> String?Initializer for conditional binding must have Optional type, not 'NSNumber' in Swift
Entire circuit dead after GFCI outlet
Is using 'echo' to display attacker-controlled data on the terminal dangerous?
Is it possible to have a wealthy country without a middle class?
Someone whose aspirations exceed abilities or means
Why are MBA programs closing?
Ability To Change Root User Password (Vulnerability?)
Electricity free spaceship
Is it a bad idea to to run 24 tap and shock lands in standard
Overlapping String-Blocks
Why 1,2 printed by a command in $() is not interpolated?
How to communicate to my GM that not being allowed to use stealth isn't fun for me?
Teaching a class likely meant to inflate the GPA of student athletes
Is it possible for a vehicle to be manufactured without a catalytic converter?
Determining fair price for profitable mobile app business
Bb13b9 confusion
An easy proof that an isometry preserving the zero vector is linear
Check if three arrays contains the same element
Live action TV show where High school Kids go into the virtual world and have to clear levels
How do you say "homebrewer" in Spanish?
If I leave the US through an airport, do I have to return through the same airport?
Why does Sin[b-a] simplify to -Sin[a-b]?
Why we don’t make use of the t-distribution for constructing a confidence interval for a proportion?
A map of non-pathological topology?
Second (easy access) account in case my bank screws up
conditional binding must have Optional type, not 'String' [duplicate]
Conditional Binding: if let error – Initializer for conditional binding must have Optional typeBound value in a conditional binding must be of optional typeConditional Binding: if let error – Initializer for conditional binding must have Optional typeInitializer for conditional binding must have Optional type, not 'NSManagedObjectContextInitializer for conditional binding must have Optional type, not 'String' on HTTPCookieStorageError: Initializer for conditional binding must have optional type, not 'String'“Initializer for conditional binding must have Optional type, not '[String]'”Initialzer for conditional binding must have Optional type not 'String'Firebase update: Initializer for conditional binding must have Optional type, not 'String'iOS Swift: Initializer for conditional binding must have Optional type, not '() -> String?Initializer for conditional binding must have Optional type, not 'NSNumber' in Swift
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This question already has an answer here:
Conditional Binding: if let error – Initializer for conditional binding must have Optional type
5 answers
I understand that The text property of UILabel is optional, I tried adding an else but i'm not sure what else to add.
productData.product.productName is me getting the name of the product from the database
if var pName = productData.product.productName //error
self.productName.text = pName
@IBOutlet weak var pName: UILabel!
Initializer for conditional binding must have Optional type, not 'String' is the error I get, It was working I think im not sure where its gone wrong
ios swift
marked as duplicate by vadian
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();
);
);
);
Mar 24 at 19:20
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.
add a comment |
This question already has an answer here:
Conditional Binding: if let error – Initializer for conditional binding must have Optional type
5 answers
I understand that The text property of UILabel is optional, I tried adding an else but i'm not sure what else to add.
productData.product.productName is me getting the name of the product from the database
if var pName = productData.product.productName //error
self.productName.text = pName
@IBOutlet weak var pName: UILabel!
Initializer for conditional binding must have Optional type, not 'String' is the error I get, It was working I think im not sure where its gone wrong
ios swift
marked as duplicate by vadian
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();
);
);
);
Mar 24 at 19:20
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.
The error is pretty clear.productData.product.productName
is not optional. Why have you tried to unwrap it?
– Rakesha Shastri
Mar 24 at 19:14
@RakeshaShastri im trying to update the pName label with productName
– kmnflask
Mar 24 at 19:26
add a comment |
This question already has an answer here:
Conditional Binding: if let error – Initializer for conditional binding must have Optional type
5 answers
I understand that The text property of UILabel is optional, I tried adding an else but i'm not sure what else to add.
productData.product.productName is me getting the name of the product from the database
if var pName = productData.product.productName //error
self.productName.text = pName
@IBOutlet weak var pName: UILabel!
Initializer for conditional binding must have Optional type, not 'String' is the error I get, It was working I think im not sure where its gone wrong
ios swift
This question already has an answer here:
Conditional Binding: if let error – Initializer for conditional binding must have Optional type
5 answers
I understand that The text property of UILabel is optional, I tried adding an else but i'm not sure what else to add.
productData.product.productName is me getting the name of the product from the database
if var pName = productData.product.productName //error
self.productName.text = pName
@IBOutlet weak var pName: UILabel!
Initializer for conditional binding must have Optional type, not 'String' is the error I get, It was working I think im not sure where its gone wrong
This question already has an answer here:
Conditional Binding: if let error – Initializer for conditional binding must have Optional type
5 answers
ios swift
ios swift
asked Mar 24 at 19:10
kmnflaskkmnflask
759
759
marked as duplicate by vadian
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();
);
);
);
Mar 24 at 19:20
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
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();
);
);
);
Mar 24 at 19:20
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.
The error is pretty clear.productData.product.productName
is not optional. Why have you tried to unwrap it?
– Rakesha Shastri
Mar 24 at 19:14
@RakeshaShastri im trying to update the pName label with productName
– kmnflask
Mar 24 at 19:26
add a comment |
The error is pretty clear.productData.product.productName
is not optional. Why have you tried to unwrap it?
– Rakesha Shastri
Mar 24 at 19:14
@RakeshaShastri im trying to update the pName label with productName
– kmnflask
Mar 24 at 19:26
The error is pretty clear.
productData.product.productName
is not optional. Why have you tried to unwrap it?– Rakesha Shastri
Mar 24 at 19:14
The error is pretty clear.
productData.product.productName
is not optional. Why have you tried to unwrap it?– Rakesha Shastri
Mar 24 at 19:14
@RakeshaShastri im trying to update the pName label with productName
– kmnflask
Mar 24 at 19:26
@RakeshaShastri im trying to update the pName label with productName
– kmnflask
Mar 24 at 19:26
add a comment |
2 Answers
2
active
oldest
votes
It states that the use of if condition is unnecessary, because the 'productName' is not optional.
You can directly add the value to your label.
self.productName.text = productData.product.productName //Product name is not optional
Optional chaining is used when you try to get a optional value.
For example, if you want to get the text of label then you'll require if condition.
if var text = self.productName.text //Text in label is optional
print(text)
so how do I updated the label with the productName?
– kmnflask
Mar 24 at 19:26
Assigning the 'productData.product.productName' to the label will update the 'productName' to it.
– sinner
Mar 24 at 19:29
so i tried pName = productData.product.productName and i get cannot assign string to UILabel error
– kmnflask
Mar 24 at 20:59
add a comment |
It seems like the compiler is complaining that productData.product.productName
is NOT an Optional. The if var name = ____
construct only works on Optionals.
If you are testing for a non-empty String, you may want to check the count
or isEmpty
instead.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It states that the use of if condition is unnecessary, because the 'productName' is not optional.
You can directly add the value to your label.
self.productName.text = productData.product.productName //Product name is not optional
Optional chaining is used when you try to get a optional value.
For example, if you want to get the text of label then you'll require if condition.
if var text = self.productName.text //Text in label is optional
print(text)
so how do I updated the label with the productName?
– kmnflask
Mar 24 at 19:26
Assigning the 'productData.product.productName' to the label will update the 'productName' to it.
– sinner
Mar 24 at 19:29
so i tried pName = productData.product.productName and i get cannot assign string to UILabel error
– kmnflask
Mar 24 at 20:59
add a comment |
It states that the use of if condition is unnecessary, because the 'productName' is not optional.
You can directly add the value to your label.
self.productName.text = productData.product.productName //Product name is not optional
Optional chaining is used when you try to get a optional value.
For example, if you want to get the text of label then you'll require if condition.
if var text = self.productName.text //Text in label is optional
print(text)
so how do I updated the label with the productName?
– kmnflask
Mar 24 at 19:26
Assigning the 'productData.product.productName' to the label will update the 'productName' to it.
– sinner
Mar 24 at 19:29
so i tried pName = productData.product.productName and i get cannot assign string to UILabel error
– kmnflask
Mar 24 at 20:59
add a comment |
It states that the use of if condition is unnecessary, because the 'productName' is not optional.
You can directly add the value to your label.
self.productName.text = productData.product.productName //Product name is not optional
Optional chaining is used when you try to get a optional value.
For example, if you want to get the text of label then you'll require if condition.
if var text = self.productName.text //Text in label is optional
print(text)
It states that the use of if condition is unnecessary, because the 'productName' is not optional.
You can directly add the value to your label.
self.productName.text = productData.product.productName //Product name is not optional
Optional chaining is used when you try to get a optional value.
For example, if you want to get the text of label then you'll require if condition.
if var text = self.productName.text //Text in label is optional
print(text)
answered Mar 24 at 19:13
sinnersinner
323112
323112
so how do I updated the label with the productName?
– kmnflask
Mar 24 at 19:26
Assigning the 'productData.product.productName' to the label will update the 'productName' to it.
– sinner
Mar 24 at 19:29
so i tried pName = productData.product.productName and i get cannot assign string to UILabel error
– kmnflask
Mar 24 at 20:59
add a comment |
so how do I updated the label with the productName?
– kmnflask
Mar 24 at 19:26
Assigning the 'productData.product.productName' to the label will update the 'productName' to it.
– sinner
Mar 24 at 19:29
so i tried pName = productData.product.productName and i get cannot assign string to UILabel error
– kmnflask
Mar 24 at 20:59
so how do I updated the label with the productName?
– kmnflask
Mar 24 at 19:26
so how do I updated the label with the productName?
– kmnflask
Mar 24 at 19:26
Assigning the 'productData.product.productName' to the label will update the 'productName' to it.
– sinner
Mar 24 at 19:29
Assigning the 'productData.product.productName' to the label will update the 'productName' to it.
– sinner
Mar 24 at 19:29
so i tried pName = productData.product.productName and i get cannot assign string to UILabel error
– kmnflask
Mar 24 at 20:59
so i tried pName = productData.product.productName and i get cannot assign string to UILabel error
– kmnflask
Mar 24 at 20:59
add a comment |
It seems like the compiler is complaining that productData.product.productName
is NOT an Optional. The if var name = ____
construct only works on Optionals.
If you are testing for a non-empty String, you may want to check the count
or isEmpty
instead.
add a comment |
It seems like the compiler is complaining that productData.product.productName
is NOT an Optional. The if var name = ____
construct only works on Optionals.
If you are testing for a non-empty String, you may want to check the count
or isEmpty
instead.
add a comment |
It seems like the compiler is complaining that productData.product.productName
is NOT an Optional. The if var name = ____
construct only works on Optionals.
If you are testing for a non-empty String, you may want to check the count
or isEmpty
instead.
It seems like the compiler is complaining that productData.product.productName
is NOT an Optional. The if var name = ____
construct only works on Optionals.
If you are testing for a non-empty String, you may want to check the count
or isEmpty
instead.
answered Mar 24 at 19:19
Mike HayMike Hay
2,5791626
2,5791626
add a comment |
add a comment |
The error is pretty clear.
productData.product.productName
is not optional. Why have you tried to unwrap it?– Rakesha Shastri
Mar 24 at 19:14
@RakeshaShastri im trying to update the pName label with productName
– kmnflask
Mar 24 at 19:26