title: How to get response from static library in ios
body: <p>In my application I am using one static library. In that library I implemented code for establish a connection with the server. For server interaction I used <code>NSURLSession</code> but it's delaying the UI response to avoid it I have started using <code>NSURLConnection</code> delegate methods now I am getting the response from server but here I don't know how to send the response back to actual code from did finish loading method.</p>
  
  <p>In my team I want to distribute this library to both iphone and ipad development engineers. They don't have any control on server related code everything I implemented in static library. So please show me the solution for my problem thanks in advance.</p>
  
  <p>The below is the code which I used in one class of static library:</p>
  
  <p>StaticClass:</p>
  
  <p>.h File</p>
  
  <pre><code>@interface StaticClass : NSObject&lt;NSURLConnectionDelegate,NSURLSessionDelegate&gt;
  
  {
  NSMutableDictionary  *responseDictionary;
  NSUserDefaults *serviceURlInUserDefaults;
  NSData *responseData;
  
  }
  @property (nonatomic, weak) id &lt;DataReciverDelegate&gt;delegate;
  @property(strong,nonatomic)NSData *responseData;
  
  
  -(void)loginWithUsername:(NSString *)name password:(NSString*)password serviceUrl:(NSString*)serviceUrl domainName:(NSString*)domainName ;
  
  
  @end
  </code></pre>
  
  <h1>import "StaticClass.h"</h1>
  
  <pre><code>@protocol DataReciverDelegate &lt;NSObject&gt;
  
  @required
  - (void)responseDictionary:(NSDictionary *)response;
  
  @end
  
  
  @implementation StaticClass
  @synthesize responseData;
  
  
  -(void)loginWithUsername:(NSString *)name password:(NSString*)password serviceUrl:(NSString*)serviceUrl domainName:(NSString*)domainName 
  {
  
   NSString *ApiStr=[NSString stringWithFormat:@“http://login.com”];
  
      NSURL *Url=[[NSURL alloc]initWithString:[loginApiStr stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
  
     NSURLRequest *ApiRequest=[NSURLRequest requestWithURL:loginUrl];
  
      NSURLConnection *connection=[[NSURLConnection alloc]initWithRequest:ApiRequest delegate:self];
      [connection start];
  
  }
  
  -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
  {
  
  }
  
  - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
  {
  
  }
  
  - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
  {
  
      self.responseData=data;
  
  }
  - (void)connectionDidFinishLoading:(NSURLConnection *)connection
  {
  
  
      responseDictionary=[NSJSONSerialization JSONObjectWithData:self.responseData options:0 error:nil];
  
      [_delegate responseDictionary:responseDictionary];
  
  }
  
  @end
  </code></pre>
  
  <p>Response where I want to use is in class1 :</p>
  
  <p>Here please let me know how can i include that delegate which i created in static library class</p>
  
  <pre><code>@interface Class1 : NSObject&lt;NSURLConnectionDelegate,NSURLSessionDelegate&gt;
  
  {
  
  }
  
  @end
  
  @implementation Class1
  
  
  -(void)login
  {
  StaticClass *object1=[[StaticClass alloc]init];
  
  [object loginWithUsername:@“AAA” password:@“BBB” serviceUrl:url domainName:dname];
  
  }
  </code></pre>