0

I am trying to convert this script:

 @interface EventSource : NSObject

 @end

 @protocol EventSourceDelegate <NSObject>

 - (void)eventSource:(EventSource *)eventSource didFailWithError:(NSError *)error;
 - (void)eventSource:(EventSource *)eventSource didReceiveEvent:(NSString *)event withData:(NSString *)data;

 @end

 @interface EventSource ()

 @property id <EventSourceDelegate> delegate;

 - (instancetype)initWithURL:(NSURL *)url delegate:(id      <EventSourceDelegate>)delegate;
 - (void)disconnect;

 @end

...and this is how far I got however I couldn't complete it. I have almost no experience in Objective C. I researched a lot about converting however I couldn't find any good for @interaface EventSource () part and @property id but I am stuck here:

import UIKit

class EventSource: NSObject {
}

//@obj
protocol EventSourceDelegate {

  func eventSource(eventSource: EventSource, didFailWithError: NSError?)
  func eventSource(eventSource: EventSource, didReceiveEvent: NSString, 
       event withData: NSString, data: NSString)

 }
1
  • The signature of didReceiveEvent seems to have lots of extraneous stuff in it. It should be func eventSource(eventSource: EventSource, didReceiveEvent: NSString, withData: NSString) (depending, of course, upon which parameters are nullable and which are not). Commented May 11, 2015 at 4:17

1 Answer 1

3

This converting to Swift like this:

- (instancetype)initWithURL:(NSURL *)url delegate:(id      <EventSourceDelegate>)delegate;

init function in Objective-c.

protocol EventSourceDelegate {

  func eventSource(eventSource: EventSource, didFailWithError: NSError?)
  func eventSource(eventSource: EventSource, didReceiveEvent: NSString,
  event withData: NSString, data: NSString)

}


class EventSource: NSObject {
  var delegate:EventSourceDelegate

  init(url:NSURL,delegate:EventSourceDelegate){
  // TODO:  finish implementation
    self.delegate = delegate
  }
 func disconnect(){
 // TODO:  finish implementation
 }

}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.