title: Append a string inside loop in iOS
body: <p>I'm using below code to append a string received from server in for loop. I'm not able to figure it out what is going wrong. I'm receiving an empty string after appending.</p>
  
  <p><strong>FileName.h</strong></p>
  
  <pre><code>    @interface Communicator : NSObject &lt;NSStreamDelegate&gt; 
      {
        ...
       NSMutableString *strServerResponse;
  
      }
  
      ...
      @property (nonatomic,strong)  NSMutableString *strServerResponse;
      @end
  </code></pre>
  
  <p>FileName.m</p>
  
  <pre><code>       @implementation Communicator
  
          @synthesize strServerResponse;
  
          ...
  
          -(void) setUp {
  
           strServerResponse = [NSMutableString string];
           ...
          }
  
          - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)event {
  
              uint8_t buffer[1024];
              int len;
  
              while ([inputStream hasBytesAvailable]) {
                  len = [inputStream read:buffer maxLength:sizeof(buffer)];
                  if (len &gt; 0) {
  
                   NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];
  
                      if (nil != output) {
                        NSlog(@"output : ",output);
                        [strServerResponse appendString:output];
                      }
                  }
               }
  
  
            NSLog(@"strServerResponse : %@", strServerResponse);
          } 
  
           ..
  </code></pre>
  
  <p>Log for strServerResponse is always empty. Where I'm going wrong? The 'Setup' methods in this file is invoked from other file. I have used debug and seen the flow is correct. Here 'Output' string prints correct Log. Below is screenshot for log.</p>
  
  <p><img src="https://i.stack.imgur.com/j6nx0.png" alt="Edited server log"></p>