Swift 'fabs' is deprecated: renamed to 'abs' [closed] - ios

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
When I try using fabs on a CGFloat number in Swift 5, I get this warning:
'fabs' is deprecated: renamed to 'abs'
But when I use abs, it's argument is only Integer, not Float or Double. I am using XCode 12 if that matters. How do I resolve this?

You're probably using abs from the Foundation framework.
Try the following:
Swift.abs(CGFloat(1.0))
Foundation.abs(CGFloat(1.0)) // Cannot convert value of type 'CGFloat' to expected argument type 'Int32'
Swift.abs(CGFloat(1.0)) // Compiles successfully

Just use CGFloat.magnitude
CGFloat(-1.23).magnitude // => 1.23

Related

How to convert characters of a string "One" into an Integer "1" in swift [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have implemented an quiz application in swift 4.0. Here, user can enter his choice from ("one" or "1") to ("four" or "4") .
If the user can provide his choice as an integer(Eg 1,2,3, or 4)then there is no issue.
but if he provide his choice as an alphabet characters (Eg "one","two", ..), then i am facing the issues while validating correct answer.
Kindly, could anyone help me, How to convert word characters "one" into integer 1 etc..
thanks a lot in advance.
You can use NumberFormatter in this way:
let formatter = NumberFormatter()
formatter.numberStyle = .spellOut
let number = formatter.number(from: "one hundred twenty-five")
print(number) // print out 125
https://developer.apple.com/documentation/foundation/numberformatter/1408845-number

String capitalization not working [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
What can be the reason of string capitalization not working?
A database column:
t.string "name", limit: 255
Some example:
flower_name = Flower.find_by(id: 1).name #=> "chamomile©"
Trying to capitalize (got the same output):
flower_name.capitalize #=> "chamomile©"
Checking if it is string:
flower_name.is_a?(String) #=> true
capitalize works with ASCII characters only. Is there any chance your string contains non-ascii letters?
Try
flower_name.mb_chars.capitalize.to_s
mb_chars method may help you if you are using Rails >= 3.
'æ-ý'.mb_chars.upcase
=> "Æ-Ý"
If you're not using Rails, you can:
use directly active_support gem:
require 'active_support/core_ext/string/multibyte'
try unicode gem.
I hope you will find an answer in this similar question: Special character uppercase

syntax error, unexpected tINTEGER, expecting '(' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
My code is
for i in 0..array_dif.count-1
a = array_dif[i] - array_dif[0]
b = array_dif[array_dif.count-1] - array_dif[0]
norm = a.0/b
array_norm[i] = norm
end
And i'm getting the following error:
rb:135: no .<digit> floating literal anymore; put 0 before dot (SyntaxError)
norm = a.0/b
^
C:/piegas/config/initializers/backtrace_silencers.rb:135: syntax error, unexpected tINTEGER, expecting '('
norm = a.0/b
^
I don't know whats wrong with it
norm = a.0/b is an invalid statement (aka SyntaxError).
What do you want that statement to do?
norm = a/b might make sense.
norm = array_dif[0]/b might also make sense.
But without knowing the purpose of the code, it's difficult to know what the correct solution is.
What do you mean by a.0/b? It is invalid. If you were trying to convert a to float then it would be a.to_f/b.

Swift error: prefix/postfix '=' is reserved [duplicate]

This question already has answers here:
Is this response from the compiler valid?
(3 answers)
Closed 8 years ago.
I am getting error message:
prefix/postfix '=' is reserved
for below simple in swift.
var c=0,a=2,b=4
c= a+b
any idea why I am getting this error?
Check this:
Is this response from the compiler valid?
Swift isn't entirely whitespace-agnostic like C... in particular, it uses whitespace to distinguish prefix from postfix operators (because ++i++ in C is a grammar oddity). But it's not ridiculously strict about whitespace like Python either.
P.S. So you have to add whitespace before =.
If I use a single space after variable "c" name, this error is get removed.
c = a+b

Programming with Erlang [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm learning Erlang and I'm trying to understand this code that was used as an example.
-module(tutorial5).
-export([format_temps/1]).
format_temps(List_of_cities) ->
convert_list_to_c(List_of_cities).
convert_list_to_c([{Name, {f, F}} | Rest]) ->
Converted_City = {Name, {c, (F -32)* 5 / 9}},
[Converted_City | convert_list_to_c(Rest)];
convert_list_to_c([City | Rest]) ->
[City | convert_list_to_c(Rest)];
convert_list_to_c([]) ->
[].
I am unsure of how to use these methods to get what I need. The most I know about this is that I'm supposed to be able to form a list of cities and their temperatures, and then be able to convert their temperatures from farenheit to celsius and vice versa. Any HELP would be appreciated.
The only callable function in the module tutorial5 is format_temps/1 (it takes one argument). It takes a list of city/temp where each city/temp is a tuple of the form {City,{f,Fahrenheit}} for example {berlin,{f,60}}. The function return a list of city/temp where the temp part is now {c,Celsius}. An example call from the shell with its return would be:
> tutorial5:format_temps([{berlin,{f,59}},{london,{f,50}},{stockholm,{f,50}}]).
[{berlin,{c,15.0}},{london,{c,10.0}},{stockholm,{c,10.0}}]
Some points to note are:
When calling a function in another module you MUST always include the module name
The words starting with lower case letters are atoms, literal constants with a name, while those starting with upper case letters (from my text) are variables. The look alike but are very different.

Resources