0

In Obj C I used to use some code for pick up data from label, pull it in float and doing any calcul needed.

float chiffre1 = [[label1 text] floatValue];
float chiffre2 = [[label2 text] floatValue];

float number1 = chiffre1 + chiffre2;

Now in Swift I try to do the same thing but always end up with error. the code work very well in play ground, but when I use it in my app, and try to use data from a UILabel, doesn't work anymore.

@IBOutlet weak var DegreeLat1: UILabel!
@IBoutlet etc...

let deglat1 = DegreeLat1.text

let number2 = MinutLat1.text?.toInt()

let minlat1 = number2! / 60

let etc....

let lat1 = (degrelat1 + minlat1 + seclat1) * pi /180 // error "could not find an overload for "*" that accepts the supplied argument

let long1 = (etc...) * pi / 180

I tried many thing check almost everywhere can't find what I do wrong.

2
  • What is pi? You should be using M_PI. Commented May 28, 2015 at 2:57
  • Take a closer look at the types you are using when calculating lat1. They all should be Double, but deglat1 is a String, minlat1 likely an Int... Commented May 28, 2015 at 3:02

1 Answer 1

0

I am not sure what exactly you are trying to do but some things I found that looks wrong, you should include the errors you are finding to make it easier to help you.

let deglat1 = (DegreeLat1.text? as NSString).floatValue
let number2 = MinutLat1.text?.toInt()
let minlat1 = number2! / 60
let lat1 = (degrelat1 + minlat1 + seclat1) * M_PI / 180 

I hope that help!

Sign up to request clarification or add additional context in comments.

7 Comments

Thank you I didn't know for the M_PI. Yes I forgot to show pi was = at 3.141592654. I did put the error In the code boxe, who was "// error "could not find an overload for "*" that accepts the supplied argument". I just tried to write the the way you did but it give me more error. "error, String? is not convertible to 'NSString'
Sorry I am confuse do you still have the error? If so do you wanna update the question with the new code so we can help you.
I did put the error you just didn't look correctly.
Your code show "let deglat1 = DegreeLat1.text" you did not fix the code
I was just trying to answer to my question, because I managed with your help to fix the problem. But a message said this post is close and I can not send what I did for make my code to work. I have to find the way to re-open the post.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.