Block didn’t capture self in typeof,why?How do you trigger a block after a delay, like -performSelector:withObject:afterDelay:?How do I avoid capturing self in blocks when implementing an API?Disappearing reference to self in a block under ARCPossible to pass [self anyFunction] in blocks without __weak object (iOS 5 + ARC)Generic typeof for weak self referencesobj-c weak self in a block: why the 2nd one doesn't need a weak self inside in two similar casesAFNetworking, UITableView and BlocksDoes declaring strongSelf from weakSelf before a block cause retain cycleDo methods called from within a block need to use weakSelf?Do we need to use weak self in blocks in Objective-C?
Opposite of a diet
Tiptoe or tiphoof? Adjusting words to better fit fantasy races
How to write papers efficiently when English isn't my first language?
Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?
Where does the Z80 processor start executing from?
How does buying out courses with grant money work?
Roman Numeral Treatment of Suspensions
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
How does it work when somebody invests in my business?
Why, precisely, is argon used in neutrino experiments?
What does "I’d sit this one out, Cap," imply or mean in the context?
How to run a prison with the smallest amount of guards?
System.debug(JSON.Serialize(o)) Not longer shows full string
Applicability of Single Responsibility Principle
How to check is there any negative term in a large list?
Class Action - which options I have?
How does Loki do this?
How do we know the LHC results are robust?
Sequence of Tenses: Translating the subjunctive
when is out of tune ok?
How long to clear the 'suck zone' of a turbofan after start is initiated?
How do I go from 300 unfinished/half written blog posts, to published posts?
Detecting if an element is found inside a container
Term for the "extreme-extension" version of a straw man fallacy?
Block didn’t capture self in typeof,why?
How do you trigger a block after a delay, like -performSelector:withObject:afterDelay:?How do I avoid capturing self in blocks when implementing an API?Disappearing reference to self in a block under ARCPossible to pass [self anyFunction] in blocks without __weak object (iOS 5 + ARC)Generic typeof for weak self referencesobj-c weak self in a block: why the 2nd one doesn't need a weak self inside in two similar casesAFNetworking, UITableView and BlocksDoes declaring strongSelf from weakSelf before a block cause retain cycleDo methods called from within a block need to use weakSelf?Do we need to use weak self in blocks in Objective-C?
For this:
self.block = ^
self.view.backgroundColor = [UIColor greenColor];
;
There is a retain cycle obviously.
However,there is no retain cycle if the self
is in the typeof
:
__weak typeof(self) weakSelf = self;
self.block = ^
__strong typeof(self) strongSelf = weakSelf;
strongSelf.view.backgroundColor = [UIColor greenColor];
;
The self's dealloc
is called even though the self
is in the block.That means the block didn't capture self
here.
Why?
objective-c objective-c-blocks
add a comment |
For this:
self.block = ^
self.view.backgroundColor = [UIColor greenColor];
;
There is a retain cycle obviously.
However,there is no retain cycle if the self
is in the typeof
:
__weak typeof(self) weakSelf = self;
self.block = ^
__strong typeof(self) strongSelf = weakSelf;
strongSelf.view.backgroundColor = [UIColor greenColor];
;
The self's dealloc
is called even though the self
is in the block.That means the block didn't capture self
here.
Why?
objective-c objective-c-blocks
1
Another thing you can also do if you want it to be "less confusing" is do__strong typeof(weakSelf) strongSelf = weakSelf;
. I do this for added clarity.
– Mobile Ben
Mar 7 at 23:30
add a comment |
For this:
self.block = ^
self.view.backgroundColor = [UIColor greenColor];
;
There is a retain cycle obviously.
However,there is no retain cycle if the self
is in the typeof
:
__weak typeof(self) weakSelf = self;
self.block = ^
__strong typeof(self) strongSelf = weakSelf;
strongSelf.view.backgroundColor = [UIColor greenColor];
;
The self's dealloc
is called even though the self
is in the block.That means the block didn't capture self
here.
Why?
objective-c objective-c-blocks
For this:
self.block = ^
self.view.backgroundColor = [UIColor greenColor];
;
There is a retain cycle obviously.
However,there is no retain cycle if the self
is in the typeof
:
__weak typeof(self) weakSelf = self;
self.block = ^
__strong typeof(self) strongSelf = weakSelf;
strongSelf.view.backgroundColor = [UIColor greenColor];
;
The self's dealloc
is called even though the self
is in the block.That means the block didn't capture self
here.
Why?
objective-c objective-c-blocks
objective-c objective-c-blocks
asked Mar 7 at 12:54
无夜之星辰无夜之星辰
8141720
8141720
1
Another thing you can also do if you want it to be "less confusing" is do__strong typeof(weakSelf) strongSelf = weakSelf;
. I do this for added clarity.
– Mobile Ben
Mar 7 at 23:30
add a comment |
1
Another thing you can also do if you want it to be "less confusing" is do__strong typeof(weakSelf) strongSelf = weakSelf;
. I do this for added clarity.
– Mobile Ben
Mar 7 at 23:30
1
1
Another thing you can also do if you want it to be "less confusing" is do
__strong typeof(weakSelf) strongSelf = weakSelf;
. I do this for added clarity.– Mobile Ben
Mar 7 at 23:30
Another thing you can also do if you want it to be "less confusing" is do
__strong typeof(weakSelf) strongSelf = weakSelf;
. I do this for added clarity.– Mobile Ben
Mar 7 at 23:30
add a comment |
1 Answer
1
active
oldest
votes
typeof
is not a function, it's a keyword and isn't used at runtime at all. All __strong typeof(self)
is doing here is telling the compiler how to evaluate the symbol strongSelf
. It doesn't cause any runtime code to be generated, because it doesn't matter at runtime what that type actually is. All those decisions are made at compile-time.
This is the same as defining something as int x;
The runtime does not in any way have a reference to "int". It's just a C type.
typeof
is technically a C extension, but Clang supports it as a keyword when in a gcc compatibility mode, which is the default. For more on the extension, see the GCC documentation.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044299%2fblock-didn-t-capture-self-in-typeof-why%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
typeof
is not a function, it's a keyword and isn't used at runtime at all. All __strong typeof(self)
is doing here is telling the compiler how to evaluate the symbol strongSelf
. It doesn't cause any runtime code to be generated, because it doesn't matter at runtime what that type actually is. All those decisions are made at compile-time.
This is the same as defining something as int x;
The runtime does not in any way have a reference to "int". It's just a C type.
typeof
is technically a C extension, but Clang supports it as a keyword when in a gcc compatibility mode, which is the default. For more on the extension, see the GCC documentation.
add a comment |
typeof
is not a function, it's a keyword and isn't used at runtime at all. All __strong typeof(self)
is doing here is telling the compiler how to evaluate the symbol strongSelf
. It doesn't cause any runtime code to be generated, because it doesn't matter at runtime what that type actually is. All those decisions are made at compile-time.
This is the same as defining something as int x;
The runtime does not in any way have a reference to "int". It's just a C type.
typeof
is technically a C extension, but Clang supports it as a keyword when in a gcc compatibility mode, which is the default. For more on the extension, see the GCC documentation.
add a comment |
typeof
is not a function, it's a keyword and isn't used at runtime at all. All __strong typeof(self)
is doing here is telling the compiler how to evaluate the symbol strongSelf
. It doesn't cause any runtime code to be generated, because it doesn't matter at runtime what that type actually is. All those decisions are made at compile-time.
This is the same as defining something as int x;
The runtime does not in any way have a reference to "int". It's just a C type.
typeof
is technically a C extension, but Clang supports it as a keyword when in a gcc compatibility mode, which is the default. For more on the extension, see the GCC documentation.
typeof
is not a function, it's a keyword and isn't used at runtime at all. All __strong typeof(self)
is doing here is telling the compiler how to evaluate the symbol strongSelf
. It doesn't cause any runtime code to be generated, because it doesn't matter at runtime what that type actually is. All those decisions are made at compile-time.
This is the same as defining something as int x;
The runtime does not in any way have a reference to "int". It's just a C type.
typeof
is technically a C extension, but Clang supports it as a keyword when in a gcc compatibility mode, which is the default. For more on the extension, see the GCC documentation.
edited Mar 7 at 13:26
answered Mar 7 at 13:11
Rob NapierRob Napier
206k28303431
206k28303431
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044299%2fblock-didn-t-capture-self-in-typeof-why%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Another thing you can also do if you want it to be "less confusing" is do
__strong typeof(weakSelf) strongSelf = weakSelf;
. I do this for added clarity.– Mobile Ben
Mar 7 at 23:30