2

I get a strange error message from Swift

Partial application of protocol method is not allowed

I try to pass a function into a class. My code looks like follow

Condition.swift

public protocol Condition {
  var type: String { get set }

  init(conditionJson: JSON)

  func getExpression() -> NSPredicate
  func getConditionAction(actionHandler: () -> Void)
}

TimerCondition.swift

public class TimerCondition: Condition {
  public var type: String
  public var seconds: Int

  required public init(conditionJson: JSON) {
      self.type = conditionJson["conditionType"].stringValue
      self.seconds = conditionJson["conditionType"].intValue
  }

  public func getExpression() -> NSPredicate {
      return NSPredicate(format: "1 == 1")
  }

  public func getConditionAction(actionHandler: () -> Void){
      actionHandler()
  }

}

Now in here im getting the error

public class ConditionHandler {
  var test:((actionHandler: () -> Void) -> Void)

  public init(eventResponse:JSON) {
      //error happens here
      test = condition.getConditionAction
}

If I do the whole thing without a protocol it works.

Can some help me out here?

EDIT

The solution described in Partial application of protocol method is not allowed can't be applied to my problem, as I want to use a parameter

Community
  • 1
  • 1
gabac
  • 2,062
  • 6
  • 21
  • 30

0 Answers0