• 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
Initializing Structures
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Initializing Structures


  • Subject: Initializing Structures
  • From: Richard Charles <email@hidden>
  • Date: Wed, 05 Nov 2014 15:03:51 -0700

A fast and compact way to initialize a structure is to enclose the values in a pair of braces like this.

     NSRect rect = {{0,0},{80,20}};
     NSView *view = [[NSView alloc] initWithFrame:rect];

However a compiler error occurs if we try to initialize a struct with braces directly within an Objective-C message.

     NSView *view = [[NSView alloc] initWithFrame:{{0,0},{80,20}}];

Why does the compiler accept the first but not the second?

Richard Charles
_______________________________________________

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: Initializing Structures
      • From: Greg Parker <email@hidden>
  • Prev by Date: Re: Editing NSOutlineView Group Item
  • Next by Date: Re: Initializing Structures
  • Previous by thread: Re: dispatch_source does not work
  • Next by thread: Re: Initializing Structures
  • Index(es):
    • Date
    • Thread