菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
422
0

ios理解 -- Pro Mutlithreading and Memory Management for iOS and OS X with ARC, Grand Central Dispatch, and Blocks

原创
05/13 14:22
阅读数 50954

Capturing automatic variables

Next, you need to learn what the “together with automatic (local) variables” part means.
For Blocks, this can be rephrased as “capturing the value of automatic variables.” The
next example shows how thiscapture is accomplished.             

When automatic variables are captured, the values are read-only in the Block. The
variables can’t be modified.

 

Blocks are “anonymous
functions together with automatic (local) variables.

 

isa 

 

A struct for each class is a class_t struct based on objc_class struct. The class_t struct
is declared at runtime/objc-runtime-new.h in the objc4 runtime library.
struct class_t {
struct class_t *isa;
struct class_t *superclass;
Cache cache;
IMP *vtable;
uintptr_t data_NEVER_USE;
};

 

 

一个block的实现是如下:

Next, let’s see the implementation of the anonymous function that uses the Block. The
original Block literal is as follows.
^{printf(fmt, val);}
This is converted to a function.
static void __main_block_func_0(struct __main_block_impl_0 *__cself)
{
const char *fmt = __cself->fmt;
int val = __cself->val;
printf(fmt,

 

发表评论

0/200
422 点赞
0 评论
收藏
为你推荐 换一批