Beny
Beny

Reputation: 13

how to call xxxxWithClass:(class) in swift

I want to call this method in RestKit RKRoute in swift:

+ (instancetype)routeWithClass:(Class)objectClass pathPattern:(NSString *)pathPattern method:(RKRequestMethod)method;

but I find I can't use 'class' as argument label,the compiler deal it as a keyword

var route:RKRoute = RKRoute(class: Article.self, pathPattern: "/categories/:comment.name/articles/:articleID/comments/", method:RKRequestMethod.GET)

how to call it?

Upvotes: 1

Views: 79

Answers (1)

pws5068
pws5068

Reputation: 2194

From the Swift documentation:

To use a reserved word as an identifier, put a backtick (`) before and after it. For example, class is not a valid identifier, but `class` is valid. The backticks are not considered part of the identifier; `x` and x have the same meaning.

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html

Thus:

var route:RKRoute = RKRoute(`class`: Article.self, pathPattern: "/categories/:comment.name/articles/:articleID/comments/", method:RKRequestMethod.GET)

Upvotes: 3

Related Questions