Search code examples
iosswiftrestkit

Restkit addFetchRequestBlock crashes


So I've got the following code:

RKObjectManager.sharedManager().addFetchRequestBlock({
  url in

  // let pathMatcher = RKPathMatcher(path: "/v1/groups/")
  // var dict = NSDictionary?()
  // let match = pathMatcher.matchesPath(url.relativePath, tokenizeQueryStrings: false, parsedArguments: &dict)

  // if match {
  if let path = url.relativePath where path == "/v1/groups" {
    let fetchRequest = NSFetchRequest(entityName: String(self))
    fetchRequest.predicate = NSPredicate(format: "ANY member == %@", activeUser)
    return fetchRequest
  }

  return nil
})

It works, but as you can see it's not using the RKPathMatcher.

If I comment in the outcommented code, I get:

*** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: 
'*** -[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: nil argument'

Solution

  • I haven't tried it, but the dict part should be:

    var dict: NSDictionary?
    

    Though it doesn't look like you're using it so you can just set it to nil.