• 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: Casting NSRect to CGRect?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Casting NSRect to CGRect?


  • Subject: Re: Casting NSRect to CGRect?
  • From: Christophe Dore <email@hidden>
  • Date: Fri, 18 Jan 2002 10:52:09 +0100

You'd better try also to add an assertion which ensure that thoses types are actually the same.

Imagine what would happen to your program if in a future release, one of those type changes the floats for doubles, ....



James Montgomerie wrote:

Try (untested, from the top of my head):

CGRect coreGraphicsRect = *((CGRect*)&foundationRect);

C doesn't allow you to cast structs, but you can cast pointers.

Jamie.,

On Thursday, January 17, 2002, at 05:09 pm, Pete Carss wrote:

But I get:

'conversion to a non-scalar type requested'?

Pete

On Friday, January 18, 2002, at 12:39 , John C. Randolph wrote:

On Thursday, January 17, 2002, at 04:22 PM, Pete Carss wrote:

I have a DrawRect method in a custom view - which takes an NSRect - as it should. I want to use this data in a CG call that expects a CGRect - I delved into the docs and the structs that define them are the same - is there an easy way to get from one to the other?


Just cast it. They're the same thing:

NSRect foundationRect;
CGRect coreGraphicsRect = (CGRect) foundationRect;

_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Casting NSRect to CGRect? (From: James Montgomerie <email@hidden>)

  • Prev by Date: best way to launch an application with an NSArray argument
  • Next by Date: Re: opening an open document
  • Previous by thread: Re: Casting NSRect to CGRect?
  • Next by thread: Re: Casting NSRect to CGRect?
  • Index(es):
    • Date
    • Thread