目标C中符号^的含义

可能重复:
目标C中的插入符号
Objective-C中这个^语法是什么意思?

在Objective C中search符号^的含义让我感到厌倦,尤其是在后台运行的任务中,我已经看到了很多项目。 我会把一个链接http://developer.apple.com/library/ios/#samplecode/StitchedStreamPlayer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010092和MyStreamingMovieViewController.m你可以find以下内- (IBAction)endScrubbing:(id)sender method

 timeObserver = [[player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(tolerance, NSEC_PER_SEC) queue:dispatch_get_main_queue() usingBlock: ^(CMTime time) { [self syncScrubber]; }] retain]; } 

另外http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

 - (void)applicationDidEnterBackground:(UIApplication *)application { UIApplication* app = [UIApplication sharedApplication]; bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ // Clean up any unfinished task business by marking where you. // stopped or ending the task outright. [app endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; }]; // Start the long-running task and return immediately. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // Do the work associated with the task, preferably in chunks. [app endBackgroundTask:bgTask]; bgTask = UIBackgroundTaskInvalid; }); } 

请让我知道答案。

该符号用于声明块。

欲了解更多信息,请阅读块编程主题

一些更多信息:

块对象是一个C级语法和运行时function。 它们与标准C函数类似,但除了可执行代码之外,它们还可以包含对自动(堆栈)或托pipe(堆)内存的variables绑定。 因此,块可以维护一组状态(数据),可以用来在执行时影响行为。

您可以使用块来组合可传递给API的函数expression式,可以select存储,并由多个线程使用。 块作为callback特别有用,因为块带有要在callback中执行的代码和执行期间需要的数据。

从Apple的Blocks Programming Topic的第二页开始:

您可以使用^运算符来声明块variables并指示块字面的开始。 块的主体本身包含在{}中,如本例所示(与C通常一样;;表示语句的结尾):

该符号用于声明block.Blocks是内联(在其他函数内)实现的代码的可寻址部分。 内联可以很方便,但是块与常规函数和函数指针不同的真正原因是它们可以从围绕它们实现的函数的范围引用局部variables,而不需要块的调用者需要知道周围范围variables的存在。
如何实施块(和后果)