NSString(RKAdditions) Category Reference
Declared in | NSString+RKAdditions.h NSString+RKAdditions.m |
Overview
A library of helpful additions to the NSString class to simplify common tasks within RestKit
Tasks
-
– stringByAppendingQueryParameters:
Returns a resource path from a dictionary of query parameters URL encoded and appended This is a convenience method for constructing a new resource path that includes a query. For example, when given a resourcePath of /contacts and a dictionary of parameters containing foo=bar and color=red, will return /contacts?foo=bar&color=red
-
– interpolateWithObject:
Convenience method for generating a path against the properties of an object. Takes a string with property names prefixed with a colon and interpolates the values of the properties specified and returns the generated path.
-
– queryParameters
Returns a dictionary of parameter keys and values using UTF-8 encoding given a URL-style query string on the receiving object. For example, when given the string /contacts?foo=bar&color=red, this will return a dictionary of parameters containing foo=bar and color=red, excluding the path “/contacts?”
-
– queryParametersUsingEncoding:
Returns a dictionary of parameter keys and values given a URL-style query string on the receiving object. For example, when given the string /contacts?foo=bar&color=red, this will return a dictionary of parameters containing foo=bar and color=red, excludes the path “/contacts?”
-
– queryParametersUsingArrays:encoding:
Returns a dictionary of parameter keys and values arrays (if requested) given a URL-style query string on the receiving object. For example, when given the string /contacts?foo=bar&color=red, this will return a dictionary of parameters containing foo=[bar] and color=[red], excludes the path “/contacts?”
-
– stringByAddingURLEncoding
Returns a URL encoded representation of self.
-
– stringByReplacingURLEncoding
Returns a representation of self with percent URL encoded characters replaced with their literal values.
-
– stringByAppendingPathComponent:isDirectory:
Returns a new string made by appending a path component to the original string, along with a trailing slash if the component is designated a directory.
-
– MIMETypeForPathExtension
Interprets the receiver as a path and returns the MIME Type for the path extension using Core Services.
-
– isIPAddress
Returns YES if the receiver contains a valid IP address
-
– MD5
Returns a string of the MD5 sum of the receiver.
Instance Methods
MD5
Returns a string of the MD5 sum of the receiver.
- (NSString *)MD5
Return Value
A new string containing the MD5 sum of the receiver.
Declared In
NSString+RKAdditions.h
MIMETypeForPathExtension
Interprets the receiver as a path and returns the MIME Type for the path extension using Core Services.
- (NSString *)MIMETypeForPathExtension
Return Value
The expected MIME Type of the resource identified by the path or nil if unknown
Discussion
For example, given a string with the path /Users/blake/Documents/monkey.json we would get @“application/json” as the MIME Type.
Declared In
NSString+RKAdditions.h
interpolateWithObject:
Convenience method for generating a path against the properties of an object. Takes a string with property names prefixed with a colon and interpolates the values of the properties specified and returns the generated path.
- (NSString *)interpolateWithObject:(id)object
Parameters
- object
The object to interpolate the properties against
Discussion
For example, given an ‘article’ object with an ‘articleID’ property of 12345 [@“articles/:articleID” interpolateWithObject:article] would generate @“articles/12345” This functionality is the basis for resource path generation in the Router.
See Also
Declared In
NSString+RKAdditions.h
isIPAddress
Returns YES if the receiver contains a valid IP address
- (BOOL)isIPAddress
Discussion
For example, @“127.0.0.1” and @“10.0.1.35” would return YES while @“restkit.org” would return NO
Declared In
NSString+RKAdditions.h
queryParameters
Returns a dictionary of parameter keys and values using UTF-8 encoding given a URL-style query string on the receiving object. For example, when given the string /contacts?foo=bar&color=red, this will return a dictionary of parameters containing foo=bar and color=red, excluding the path “/contacts?”
- (NSDictionary *)queryParameters
Parameters
- receiver
A string in the form of @“/object/?sortBy=name”, or @“/object/?sortBy=name&color=red”
Return Value
A new dictionary of query parameters, with keys like ‘sortBy’ and values like ‘name’.
Declared In
NSString+RKAdditions.h
queryParametersUsingArrays:encoding:
Returns a dictionary of parameter keys and values arrays (if requested) given a URL-style query string on the receiving object. For example, when given the string /contacts?foo=bar&color=red, this will return a dictionary of parameters containing foo=[bar] and color=[red], excludes the path “/contacts?”
- (NSDictionary *)queryParametersUsingArrays:(BOOL)shouldUseArrays encoding:(NSStringEncoding)encoding
Parameters
- shouldUseArrays
If NO, it yields the same results as queryParametersUsingEncoding:, otherwise it creates value arrays instead of value strings.
- encoding
The encoding for to use while parsing the query string.
- receiver
A string in the form of @“/object?sortBy=name”, or @“/object?sortBy=name&color=red”
Return Value
A new dictionary of query parameters, with keys like ‘sortBy’ and value arrays (if requested) like [‘name’].
Discussion
This method originally appeared as queryContentsUsingEncoding: in the Three20 project: https://github.com/facebook/three20/blob/master/src/Three20Core/Sources/NSStringAdditions.m
See Also
Declared In
NSString+RKAdditions.h
queryParametersUsingEncoding:
Returns a dictionary of parameter keys and values given a URL-style query string on the receiving object. For example, when given the string /contacts?foo=bar&color=red, this will return a dictionary of parameters containing foo=bar and color=red, excludes the path “/contacts?”
- (NSDictionary *)queryParametersUsingEncoding:(NSStringEncoding)encoding
Parameters
- receiver
A string in the form of @“/object/?sortBy=name”, or @“/object/?sortBy=name&color=red”
- encoding
The encoding for to use while parsing the query string.
Return Value
A new dictionary of query parameters, with keys like ‘sortBy’ and values like ‘name’.
Discussion
This method originally appeared as queryContentsUsingEncoding: in the Three20 project: https://github.com/facebook/three20/blob/master/src/Three20Core/Sources/NSStringAdditions.m
Declared In
NSString+RKAdditions.h
stringByAddingURLEncoding
Returns a URL encoded representation of self.
- (NSString *)stringByAddingURLEncoding
Declared In
NSString+RKAdditions.h
stringByAppendingPathComponent:isDirectory:
Returns a new string made by appending a path component to the original string, along with a trailing slash if the component is designated a directory.
- (NSString *)stringByAppendingPathComponent:(NSString *)pathComponent isDirectory:(BOOL)isDirectory
Parameters
- pathComponent
The path component to add to the URL.
- isDirectory:
If TRUE, a trailing slash is appended after pathComponent.
Return Value
A new string with pathComponent appended.
Declared In
NSString+RKAdditions.h
stringByAppendingQueryParameters:
Returns a resource path from a dictionary of query parameters URL encoded and appended This is a convenience method for constructing a new resource path that includes a query. For example, when given a resourcePath of /contacts and a dictionary of parameters containing foo=bar and color=red, will return /contacts?foo=bar&color=red
- (NSString *)stringByAppendingQueryParameters:(NSDictionary *)queryParameters
Parameters
- queryParameters
A dictionary of query parameters to be URL encoded and appended to the resource path
Return Value
A new resource path with the query parameters appended
Discussion
NOTE – Assumes that the resource path does not already contain any query parameters.
Declared In
NSString+RKAdditions.h