ban*_*ndw 1 objective-c ios objective-c-blocks
请参阅将块内的变量分配给块外部的变量
它说它应该添加__block到变量中,但是我在这里看到了objc的Google Youtube示例代码中的一些代码https://code.google.com/p/google-
第279到290行的api-objectivec-client/source/browse/trunk/Examples/YouTubeSample/YouTubeSampleWindowController.m:
_channelListTicket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLYouTubeChannelListResponse *channelList,
NSError *error) {
// Callback
// The contentDetails of the response has the playlists available for
// "my channel".
if ([[channelList items] count] > 0) {
GTLYouTubeChannel *channel = channelList[0];
_myPlaylists = channel.contentDetails.relatedPlaylists;
}
Run Code Online (Sandbox Code Playgroud)
为什么在_myPlaylists不__blocks先添加变量的情况下分配变量?
为什么在
_myPlaylists不__block先添加变量的情况下分配变量?
因为它不是函数中的局部变量.只有您计划分配的本地人才需要__block指定.实例变量*通过引用self; 他们永远不需要标记__block.
*在链接的示例代码中,_myPlaylists是第49行的实现块中声明的实例变量.