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?













3















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?










share|improve this question

















  • 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















3















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?










share|improve this question

















  • 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













3












3








3








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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












  • 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












1 Answer
1






active

oldest

votes


















5














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.






share|improve this answer
























    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
    );



    );













    draft saved

    draft discarded


















    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









    5














    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.






    share|improve this answer





























      5














      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.






      share|improve this answer



























        5












        5








        5







        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.






        share|improve this answer















        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 7 at 13:26

























        answered Mar 7 at 13:11









        Rob NapierRob Napier

        206k28303431




        206k28303431





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved