• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convert CGFloat to NSNumber
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert CGFloat to NSNumber


  • Subject: Re: Convert CGFloat to NSNumber
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 24 Feb 2015 18:16:23 +0000

On Feb 24, 2015, at 08:14 , Charles Jenkins <email@hidden> wrote:
>
> A structure?!? I did look it up in the documentation, and all I found was “the basic type for all floating-point values.” That the basis of all floating-point types could be a structure never occurred to me.

That’s not really what the quoted statement means.


On Feb 24, 2015, at 09:02 , Kyle Sluder <email@hidden> wrote:

> You need to create either a Double or Float from the CGFloat before you
> can pass it to the NSNumber initializer:

The following work, too (Xcode 6.1.1):

	let f1: NSNumber = font.pointSize
	let f2 = font.pointSize as NSNumber

What’s going on here, I think, is that NSNumber (in Obj-C) does not have an initializer that takes a CGFloat parameter, only initializers for float and double, but it never mattered (in Obj-C) because CGFloat was one of the other types. This carries over to Swift, except that there CGFloat is a distinct type, rather than being one or other of float or double.

AFAICT, the above forms work, not because there is an automatic conversion from CGFloat to double (let alone from CGFloat to NSNumber), but rather because CGFloat is FloatLiteralConvertible, and there are FloatLiteralConvertible variants of the ‘=‘ and ‘as’ operators.

(Things may have changed in Swift 1.2, though.)



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Convert CGFloat to NSNumber
      • From: Marco S Hyman <email@hidden>
References: 
 >Convert CGFloat to NSNumber (From: Charles Jenkins <email@hidden>)
 >Re: Convert CGFloat to NSNumber (From: Roland King <email@hidden>)
 >Re: Convert CGFloat to NSNumber (From: Charles Jenkins <email@hidden>)

  • Prev by Date: Re: Displaying multiple errors in NSOpenPanel beginSheetModalForWindow:completionHandler:
  • Next by Date: Re: Convert CGFloat to NSNumber
  • Previous by thread: Re: Convert CGFloat to NSNumber
  • Next by thread: Re: Convert CGFloat to NSNumber
  • Index(es):
    • Date
    • Thread