title: Objective-c How to define a MACRO with weak self
body: <p>I have a debug macro which prints the pointer of the object calling the log as well as other information pertinent to the code that it is called from.</p>
  
  <pre><code>#define Dlog [Log .... formatArgs:ARGS(f,##__VA_ARGS__)]
  
  #define ARGS @{@"self" : [NSString stringWithFormat:@"%p",self],@"file" : [NSString stringWithFormat:@"%@",[@__FILE__ lastPathComponent]],@"line" : @(__LINE__),@"function" : [NSString stringWithFormat:@"%s",__FUNCTION__],@"fmt" :[NSString stringWithFormat:(f), ##__VA_ARGS__]}
  </code></pre>
  
  <p>Problem is that self is strongly retained when <code>DLog</code> is called from within a dispatch_block_t</p>
  
  <p>for instance </p>
  
  <pre><code>// someObject is kind of SomeClass
  [someObject retainBlockAndThenCallItInTheLateFuture:^{
     Dlog("Great"); // self is strongly retained inside the block and causes a memory cycle
  }];
  </code></pre>
  
  <p>What I would like to have is a way to implicitly "weakify" self inside this macro so that it would appear to be like:</p>
  
  <pre><code>__weak __type__of(self) weakSelf = self;
  someSortOfBlock = ^ {
  /// using only "weak self"
  Dlog(@"Some message with weak self")
  }
  </code></pre>
  
  <p>How can I assure that "self" is weak inside the macro?</p>