Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks #13

Open
Saadnajmi opened this issue Oct 22, 2020 · 1 comment
Open

Blocks #13

Saadnajmi opened this issue Oct 22, 2020 · 1 comment
Labels
proposed convention A new convention for the guidelines

Comments

@Saadnajmi
Copy link
Contributor

I was asked if we had anything about blocks in here. We should probably add this?
No idea what the convention should be :D I always go here to remind myself how to use em

Convention

Rationale

Example

@Saadnajmi Saadnajmi added the proposed convention A new convention for the guidelines label Oct 22, 2020
@anandrajeswaran
Copy link

Really good question and topic. Thanks for bringing it up!

Some initial thoughts:

  • We don't want to get into the territory of making recommendations here that the compiler already enforces by default. The link you provided only deals with that and is excellent and profane at doing so, but I don't think we don't need to replace, mimic, or even link to it since it is compiler enforced.
  • When to pass weak objects into blocks to avoid retain cycles is probably very necessary as that comes up frequently
  • There should also be a convention on passing the minimal amount of needed context into the block - don't refer to self in the block if all you need is a known property of self that you can fetch to the heap before declaring the block.
  • Possibly contradictory to the first thought, but I wonder if this is the place where we should be proposing compiler flags. My main guidance around blocks would be to use these settings to enforce the above
    CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES
    CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES
  • Whether to use typedefs for complex blocks may be interesting as well, though I haven't yet seen an opinion to sway me in one way or the other. It adds some convenience but also some obfuscation.
  • When to use blocks vs delegate/dataSource style is definitely something worthy of discussion here. I'm increasingly of the opinion that we should avoid new delegates for the most part in favor of block params that don't enforce the client to be an ObjC class and thus allow for slimmer, more declarative consuming code. But I don't think we're anywhere close to a consensus on that yet.
  • Any other frequent questions come up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposed convention A new convention for the guidelines
Projects
None yet
Development

No branches or pull requests

2 participants