title: Swift array of handler blocks
body: <p>In objective-c I have a code in .h file:</p>
  
  <pre><code>typedef void(^SocketConnectionLost)();
  typedef void(^SocketIOCallback)(id argsData);
  
  @interface SocketConnection
  
  @property (strong, nonatomic) SocketIO *socketIO;
  
  @property (strong, nonatomic) NSMutableArray *socketConnectionLosts;
  
  -(void)sendEventWithName:(NSString*)eventName
                  withData:(id)data
          onConnectionLost:(SocketConnectionLost)connectionLost
                  onAnswer:(SocketIOCallback)answer;
  
  @end
  </code></pre>
  
  <p>And I have a code in .m file:</p>
  
  <pre><code>@implementation SocketConnection
  
  - (void)init {
      self.socketIO = [[SocketIO alloc] initWithDelegate:self];
      [self.socketIO setReturnAllDataFromAck: YES];
      [self.socketIO connectToHost:kSocketHost onPort:kSocketPort withParams:params];
  }
  
  - (void) socketIODidDisconnect:(SocketIO *)socket
           disconnectedWithError:(NSError *)error {
      for(ServerRequestConnectionLost connectionLost in self.socketConnectionLosts)
          if(connectionLost)
              connectionLost();
      [self.socketConnectionLosts removeAllObjects];
  }
  
  -(void)sendEventWithName:(NSString*)eventName
                  withData:(id)data
          onConnectionLost:(SocketConnectionLost)connectionLost
                  onAnswer:(SocketIOCallback)answer {
      [self.socketConnectionLosts addObject:connectionLost];
      [self.socketIO sendEvent:eventName withData:data andAcknowledge:^(id argsData) {
          if(connectionLost)
              [self.socketConnectionLosts removeObject:connectionLost];
          if(answer)
              answer(argsData);
      }];
  }
  
  @end
  </code></pre>
  
  <p>Please help me reproduce this code in Swift, I don't understand how to create, add and remove Swift blocks with Array on NSArray</p>
  
  <p>This is how I try to create some block in Swift:</p>
  
  <pre><code>var someBlock: ()-&gt;()
  var connectionLosts = NSMutableArray()
  connectionLosts.append(someBlock)
  </code></pre>
  
  <p>Compiler show me the error: Type '()->()' doesn't confirm to protocol 'AnyObject'</p>
  
  <p>Then I need to remove someBlock from the array, like [self.socketConnectionLosts removeObject:connectionLost] in obj-c and I don't understand how to do it with Swift array. </p>