• 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: NSOpenPanel problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSOpenPanel problem


  • Subject: Re: NSOpenPanel problem
  • From: Conrad Shultz <email@hidden>
  • Date: Mon, 23 Jan 2012 02:37:17 -0800

(Re-post on list.)

On 1/23/12 1:41 AM, Jan E. Schotsman wrote:
> That's great indeed, but I need the block to work with a method
> parameter (an NSString object). Do I need to copy the NSString to an ivar?

No, you just use it directly.  As Ken mentioned, any variable you
reference in a block is automatically captured by the block and remains
available for the duration of its existence - even outside the scope of
the original variable declaration.

(If you need to *write* to an outside variable inside a block, the
variable's declaration must include a __block modifier; this and other
quirks are noted in the documentation.)

You *really* need to read the docs on blocks and GCD since they are the
"modern" way of writing threaded code, implementing callbacks, etc.  I'd
start with the "Short Practical Guide to Blocks" -
http://developer.apple.com/library/ios/#featuredarticles/Short_Practical_Guide_Blocks/_index.html.

There are a plethora of WWDC videos from beginning to advanced on these
topics, too.

> if I try to pass on someString in a C struct (contextInfo) then the
> compiler complains that ARC doesn't like object pointers in C structs.
> I could serialize and unserialize the string. Or is there a better way?

Just use the NSString * right in the block - no need for structs,
serialization, or anything.  That's why blocks are so useful.

--
Conrad Shultz

Synthetiq Solutions
www.synthetiqsolutions.com
_______________________________________________

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: NSOpenPanel problem
      • From: "Jan E. Schotsman" <email@hidden>
References: 
 >NSOpenPanel problem (From: "Jan E. Schotsman" <email@hidden>)
 >Re: NSOpenPanel problem (From: Ken Thomases <email@hidden>)
 >Re: NSOpenPanel problem (From: "Jan E. Schotsman" <email@hidden>)

  • Prev by Date: Re: NSOpenPanel problem
  • Next by Date: Re: Cocoa-dev Digest, Vol 9, Issue 39
  • Previous by thread: Re: NSOpenPanel problem
  • Next by thread: Re: NSOpenPanel problem
  • Index(es):
    • Date
    • Thread