请参阅Assign a variable inside a Block to a variable outside a Block
它说应该将__block添加到变量中,但是我在这里看到了objt在Google Youtube示例代码中的一些代码
从279行到290行:

_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;
}

为什么可以在不先添加_myPlaylists的情况下分配__blocks变量?

最佳答案

为什么可以在不先添加_myPlaylists的情况下分配__block变量?

因为它不是函数中的局部变量。仅您计划分配的本地人需要__block名称。实例变量*通过self引用;他们永远不需要用__block标记。

*在链接的示例代码_myPlaylists中,是在第49行的实现块中声明的实例变量。

10-08 07:53
查看更多