请参阅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行的实现块中声明的实例变量。