logo
down
shadow

SWIFT - 'double' not convertible to 'string'


SWIFT - 'double' not convertible to 'string'

By : user2950715
Date : November 17 2020, 11:58 AM
will be helpful for those in need I am learning the Swift language and I want to make a label equal what the PickerView has selected. I am making a countdown timer to learn the language and to learn about timing with the NSTimer. I am trying to convert the number, which is a double, to a string, which would be the UILabel. , Issue is with the following function:
code :
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String!
{
    return numbers[row]
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String!
{
    return "\(numbers[row])";
}
func pickerView(pickerView: UIPickerView!, didSelectRow row: Int, inComponent component: Int)
{
    subtractNumbers(\(numbers))
}
func pickerView(pickerView: UIPickerView!, didSelectRow row: Int, inComponent component: Int)
{
    subtractNumbers(numbers[row])
}


Share : facebook icon twitter icon
Swift Compiler error: 'Double' is not convertible to CGFloat

Swift Compiler error: 'Double' is not convertible to CGFloat


By : Dima
Date : March 29 2020, 07:55 AM
I hope this helps you . You can convert it with CGFloat(M_PI).
For example the following code should work in your case (note the use of CGFloat)
code :
let action = SKAction.rotateByAngle(CGFloat(M_PI), duration:1)
Swift[String: AnyObject] not convertible to T Swift Arrays

Swift[String: AnyObject] not convertible to T Swift Arrays


By : Sohel Hafiz
Date : March 29 2020, 07:55 AM
this one helps. I am not certain what exactly are you trying to achieve. but take a note - Arrays are generic collections that store specific type. Extension for Array might not know what type will be used in each case, so it cannot simply allow you to store Dictionary.
Here is an example on how to make your code more generic:
code :
extension Array {
    mutating func appendData(data: [String: T]?) {
        if data != nil {
            for (id, object) in data! {
                if var mutatingObject = object as? [String : AnyObject] {
                    mutatingObject["id"] = id
                }

                append(object)
            }
        }
    }
}
'String' is not convertible to 'Int' in Swift

'String' is not convertible to 'Int' in Swift


By : Rajxelton
Date : March 29 2020, 07:55 AM
around this issue I believe this is what you want, first in your adding function it should be:
code :
var firstStep2 = calculatedAnswer / 1
var secondStep2 = Int(firstStep2 * 10 * 10)
answerLabel.text = printSimplifiedFraction(Numerator: secondStep2)
func printSimplifiedFraction(Numerator numerator: Int, Denominator denominator: Int = 100) -> String
{
    // I haven't looked into this bit
    ...

    if(wholeNumbers > 0 && remainder > 0)
    {
        return ("Simplified fraction of \(numerator)/\(denominator) = \(wholeNumbers) \(finalNumerator)/\(finalDenominator)")
    }
    else if (wholeNumbers > 0 && remainder == 0)
    {
        return ("Simplified fraction of \(numerator)/\(denominator) = \(wholeNumbers)")
    }
    else
    {
        return ("Simplified fraction of \(numerator)/\(denominator) = \(finalNumerator)/\(finalDenominator)")
    }
}
let firstDenomInTextField = firstDenominatorTextField.text.toInt()
let firstNumInTextField = firstNumeratorTextField.text.toInt()
let firstWholeInTextField = firstWholeNumberTextField.text.toInt()

let secondDenomInTextField = secondDenominatorTextField.text.toInt()
let secondNumInTextField = secondNumeratorTextField.text.toInt()
let secondWholeInTextField = secondWholeNumberTextField.text.toInt()

var firstStep = firstWholeInTextField! + firstNumInTextField! / firstDenomInTextField!
var secondStep = secondWholeInTextField! + secondNumInTextField! / secondDenomInTextField!
var calculatedAnswer = (firstStep + secondStep)
var numerator = Int(calculatedAnswer * 10 * 10)
answerLabel.text = printSimplifiedFraction(Numerator: numerator)
Double is not convertible to UInt8, Swift error

Double is not convertible to UInt8, Swift error


By : user3357083
Date : March 29 2020, 07:55 AM
should help you out Would be more obvious if it would complain that CGFloat is not convertible to Double. Swift compiler errors are sometimes really bad.
All of your values are Double, except random3. Make it a Double as well and your code should work.
code :
let random3 = Double(arc4random_uniform(100))    
Swift 2.x to swift 3, XCode complaining error : 'String!' is not convertible to 'String'

Swift 2.x to swift 3, XCode complaining error : 'String!' is not convertible to 'String'


By : zaimah
Date : March 29 2020, 07:55 AM
I wish this helpful for you The issue is that myVar as String returns String? instead of String.
You can instead use myVar as! String, if you are sure that this conversion will always work.
Related Posts Related Posts :
  • FBSessionStateClosedLoginFailed when I am logged in through Settings
  • CGRect positioning according to center point
  • iOS: Update table view datasource with animations without core data
  • iOS : Where to start for AliPay integration?
  • Routing App Coverage File missing but not needed?
  • Drawing on a zoomable view
  • Append NSStrings and NSNumber to NSMutableArrays and make NSMutable dictionary
  • Terminating app due to uncaught exception 'NSRangeException' when calling dequeueReusableCellWithReuseIdentifier:forInde
  • Collision without physics (Cocos2D + Box2D iOS)
  • Creating a percentage based iOS layout
  • Update tableView row from AppDelegate Swift 4
  • Assigning return value of a class method to a variable error
  • how to display circular progress in delphi ios apps?
  • I can't figure how to fix this Expected identifier or '('
  • How to Test APIs in Swift 4?
  • Link error /Build/Products/Debug-iphonesimulator file not found
  • working with a very large JSON object in iOS
  • Turn off part of the iPhone Screen
  • Phonegap 3.0 app with facebook login using xCode
  • How to add interstitial admob ads to my ios project
  • adding tapku calendar to ios app
  • Add an alertcontroller in a global swift file?
  • Take square image with Cordova (Phonegap) Camera API?
  • Amazon S3 policy allowing only upload not overwrite
  • How to change the UILabel content by tapping?
  • Adding checkmark to selected table cell also checks another table cell
  • UICollectionView cellForItemAtIndexPath indexPath row is nil
  • Resize and set quality on JPEG image while retaining EXIF in iOS
  • How to push rootviewcontroller in Ios
  • How to add UIBarbuttonItem at centre on UInavigationbar in iOS
  • Would this IOS device test crash be expected
  • PickerView not showing any values
  • How to set root view controller in storyboard animated with navigation controller programmatically
  • Can anyone suggest me the effective way to deal with s3 upload fail because of timezone difference issue?
  • Getting list of files in documents folder
  • Error while using Realm Object as a singleton. Is it a good idea?
  • inserting into SQLite database
  • More nodes than I should
  • Facebook IOS SDK navigate to another controller after login not working
  • Swift Array - use "Contains" of type AnyObject
  • Sidebar menu with indicate navigationbar on iOS
  • Programmatically set size of UIView from Storyboard
  • Navigation bar blink
  • Web services issue on POST method
  • Parse.com error 'Method not allowed when Pinning is enabled.' when I use a PFQueryTableViewController subclass
  • Swift can't send URLRequest at all?
  • No Provisiong profiles with a valid signing identity were found and Failed to locate or generate matching signing assets
  • iOS: how to set httponly flag for NSHTTPCookie
  • How to get the mac address of a beacon in objective-c without knowing its UUID, major and minor values?
  • tableView is not showing data from JSON in swift
  • iTunes reject app for date of birth
  • SWIFT reporting "Extra argument in call" - works in Playground
  • save data depending on passed value in swift
  • webview not showing on full Screen of iphone 6
  • Location Notification's based on Latest iOS Feature
  • Adjusting Height of UITableViewCell
  • How to show five digit unicode in iphone
  • unwind doesn't work
  • Confusion about coordinates, frames & child nodes in SpriteKit on iOS?
  • If Statements not being recognized by Xcode
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org