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.

Christian
  • 3
  • 4

1 Answers1

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!

Icaro
  • 13,141
  • 5
  • 51
  • 70
  • 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' – Christian May 29 '15 at 10:50
  • 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. – Icaro May 29 '15 at 10:56
  • I did put the error you just didn't look correctly. – Christian May 30 '15 at 01:20
  • Your code show "let deglat1 = DegreeLat1.text" you did not fix the code – Icaro May 30 '15 at 01:22
  • 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. – Christian May 30 '15 at 01:42
  • You should be able to click in edit just below your post, don't change what is already there just add a edit section in the end – Icaro May 30 '15 at 01:44
  • I am glad to help as I can, I already create a new place for you to post your new code – Icaro May 30 '15 at 01:46