URL templates from RFC 6570 in Objective-C and Foundation
Objective-C Ruby
Permalink
Failed to load latest commit information.
Tests
.gitmodules
.travis.yml
LICENSE
NWURLTemplate.h
NWURLTemplate.m
NWURLTemplate.podspec
README.md

README.md

NWURLTemplate

An implementation of RFC 6570 – URI Template Level 4 in Objective-C and Foundation.

Usage

#import "NWURLTemplate.h"

id object = @{ @"tip": @"Talk loudly", @"when": @"today" };
NSURL *URL = [NWURLTemplate URLForTemplate:@"example.org/thinger{?when,tip}" withObject:object error:nil];
NSLog(@"%@", URL); // => example.org/thinger?when=today&tip=Talk%20loudly

Why

URI templates seem useful, and implementing them seemed like a good one-day project.

I chose to call them "URL templates" in this library because they return instances of NSURL.

The alternatives

CSURITemplate seems to be the most mature. There is also URITemplateKit, and part of some code called "CitySDK Tourism Client API in Objective-C".

Installation

One of:

  • Copy NWURLTemplate.h and NWURLTemplate.m into your project.
  • Add the following line to your Podfile:

    pod "NWURLTemplate", :git => "https://github.com/nolanw/NWURLTemplate"

Does it work?

NWURLTemplate continuously runs all URI Template Tests on iOS 7 and OS X version 10.9 and 10.8. NWURLTemplate is continuously built (but not tested, due to XCTest's availability) on iOS versions 6.1 and 5.1. Build Status

The tests are transformed by a script into XCTest test cases, with the resulting test classes included in this repository. The URI Template Tests are included as a submodule but are not necessary for running tests. If you do pull updated tests from the URI Template Tests repository, update the submodule then run the transformation script.

There is a Profiler target in the Xcode project. It builds a command-line application for testing the library's execution speed. The absolute numbers are probably fairly pointless, but comparing numbers before and after changes or running under Instruments may prove fruitful.