RecordBTN.enabled == false swift - xcode

//result of call to '==' is unused
What does that mean and how can i fix it?
RecordBTN.enabled == false
The compiler is telling me type of expression is ambiguous without more content.
var recordSettings: [String: AnyObject] = [AVFormatIDKey : kAudioFormatAppleLossless, AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue, AVEncoderBitRateKey : 320000, AVNumberOfChannelsKey : 2, AVSampleRateKey : 44100.0 ]

In your statement RecordBTN.enabled == false, you are comparing RecordBTN.enabled to false, but you aren't doing anything with the result of the comparison (a Boolean value). You may want to store the result in a variable or use it in an if statement..
If you are trying to set RecordBTN.enabled to false, use the assignment operator (a single'='):
RecordBTN.enabled = false
The operators are well documented.

Related

Kotlin elvis operator vs "... == true" boolean expression check preformance

Assume we have nullable val a: Boolean?.
In code we want to assign value of a to another non-nullable variable val b: Boolean.
If a is true then we want b also to be true
If a is false or null the we want b to be false.
We can do this in 2 ways:
b = a ?: false
or
b = a == true
Which of the following approaches is better in terms of performance?

SpEL - Test multiple conditions in findAll

I am writing a SpEL condition.
It should be a basic IF, THEN, ELSE condition.
Currently it is this way:
cus_FinalCostBoolean == true ? FormDetails.findAll{cus_ForceRecommended == true}.min{cus_LastNegotiationRound} : FormDetails.findAll{cus_ForceRecommended == false}.min{cus_LastNegotiationRound}
where:
cus_FinalCostBoolean is a boolean variable
cus_ForceRecommended is a boolean variable
cus_LastNegotiationRound is a decimal number
Currently what this condition does is the following:
IF cus_FinalCostBoolean IS TRUE
THEN calculate min(cus_LastNegotiationRound) among all the entries that have cus_ForceRecommended = TRUE
ELSE calculate min(cus_LastNegotiationRound) among all the entries that have cus_ForceRecommended = FALSE
I'd like editing it the following way:
IF cus_FinalCostBoolean IS TRUE
THEN calculate min(cus_LastNegotiationRound) among all the entries that have cus_ForceRecommended = TRUE and cus_TechnicalEvaluationPassed = 'OK'
ELSE calculate min(cus_LastNegotiationRound) among all the entries that have cus_ForceRecommended = FALSE and cus_LastNegotiationRound is not null
where cus_TechnicalEvaluationPassed is a text variable
I was trying to editing it this way:
cus_FinalCostBoolean == true ? FormDetails.findAll{cus_ForceRecommended == true && cus_TechnicalEvaluationPassed == 'OK'}.min{cus_LastNegotiationRound} : FormDetails.findAll{cus_ForceRecommended == false && cus_LastNegotiationRound != null}.min{cus_LastNegotiationRound}
But it seems it does not work.
Could you help me?
Thank you.
Best regards.

How to alter Boolean value from true to false and vice-versa

I have a requirement in Go of altering the bool value and store it.
I am receiving value == true but I need to alter it and store the altered value.
I can think of only storing the alerted to a var and pass it in the next statement.
Eg psuedo code:
chnagevalue := false
if value == false {
changevalue == true
}
what's the best way to do it in Go? Is there any pre-defined way to do it?
Use the logical NOT operator ! to change true to false and vice versa:
changedValue := !value
There's a short answer, written somewhere else :-)
Yours is almost good too:
changedValue := false
if !value {
changedValue == true
}
An if statement is always about something being true.
so in the above it reads : if a value equals false is true then {}.
of course your mind reads it the short way :
if a value equals false then {}.
the switch of course works the best:
changedValue := !changedValue
BTW: I would never use a fieldname like "changedValue" because...
every variable is a value of some kind, so there is no need of writing that.
"changed" should be enough.
or, when it is a boolean like this , even better:
"isChanged" or "hasChanged"

Can I shortcut-check if a variable is `nil` and replace by a default value?

Is there a way to shortcut-check if a variable is nil, and give a default value if it is? For instance, replace
result = (var == nil ? defaultvalue : var)
with something like
result = selfifnotnil(var, default)
Of course I could write selfifnotnil function like the ternary above, but is there any built in option?
It's as simple as this (assuming that false and nil are treated the same)
result = var || defaultvalue
If false is a legitimate value (not a missing one), then you have to do that ternary.
result = var.nil? ? defaultvalue : var
Since nil is a falsely value. Therefore:
result = var || defaultvalue
Or if it is to check the var itself and assign default value. Also, if you are from another language, be careful which values are false in ruby.
result ||= default

Which is the Swift equivalent of isnan()?

Which is the equivalent of isnan() in Swift ?
I need to check if some operation results are valid and delete those invalid like x/0
Thanks
It's defined in the FloatingPointNumber protocol, which both the Float and Double types conform to. Usage is as follows:
let d = 3.0
let isNan = d.isNaN // False
let d = Double.NaN
let isNan = d.isNaN // True
If you're looking for a way to make this check yourself, you can. IEEE defines that NaN != NaN, meaning you can't directly compare NaN to a number to determine its is-a-number-ness. However, you can check that maybeNaN != maybeNaN. If this condition evaluates as true, you're dealing with NaN.
Although you should prefer using aVariable.isNaN to determine if a value is NaN.
As a bit of a side note, if you're less sure about the classification of the value you're working with, you can switch over value of your FloatingPointNumber conforming type's floatingPointClass property.
let noClueWhatThisIs: Double = // ...
switch noClueWhatThisIs.floatingPointClass {
case .SignalingNaN:
print(FloatingPointClassification.SignalingNaN)
case .QuietNaN:
print(FloatingPointClassification.QuietNaN)
case .NegativeInfinity:
print(FloatingPointClassification.NegativeInfinity)
case .NegativeNormal:
print(FloatingPointClassification.NegativeNormal)
case .NegativeSubnormal:
print(FloatingPointClassification.NegativeSubnormal)
case .NegativeZero:
print(FloatingPointClassification.NegativeZero)
case .PositiveZero:
print(FloatingPointClassification.PositiveZero)
case .PositiveSubnormal:
print(FloatingPointClassification.PositiveSubnormal)
case .PositiveNormal:
print(FloatingPointClassification.PositiveNormal)
case .PositiveInfinity:
print(FloatingPointClassification.PositiveInfinity)
}
Its values are declared in the FloatingPointClassification enum.
The accepted answer works but when I first saw it I wasn't exactly clear because of the example and i didn't know that NaN is an acronym for "not a number".
Here's an example from Apple for anyone who isn't clear:
let x = 0.0
let y = x * .infinity // y is a NaN because .infinity is not a number
if y.isNan {
print("this is NaN") // this will print
} else {
print("this isn't Nan")
}

Resources