Latest 0.1.0
Homepage https://github.com/Nextdoor/NDPhraseParser
License Apache 2.0
Platforms ios 7.0, requires ARC
Authors

NDPhraseParser – iOS string formatting

license | Build Status | CocoaPods

This is an Objective-C port of (some of) Square’s Android Phrase library. It allows you to format a string with named keys and context, like Python:

'There are {num_neighborhoods} in {city_name}'.format(num_neighborhoods='200', city_name='San Francisco')

Example:

let pattern : String = "{user_name} lives in {neighborhood_name}"
let context : [String:String] = ["user_name": "Sean McQueen", "neighborhood_name": "Lower Nob Hill"]
do {
    let formattedString : String = try NDPhraseParser.formatStringWithPattern(pattern, context: context)
    // use formattedString
} catch let error as NSError {
    // handle error
}
NSError *error;
NSString *pattern = @"View {num_replies} replies to your recent post!";
NSDictionary *context = @{@"num_replies": @"6"};
NSString *formattedString = [NDPhraseParser formatStringWithPattern:pattern context:context errorPtr:&error];
if (!error) {
  // use formattedString
}

Download

pod install NDPhraseParser

License

Copyright 2015 Nextdoor.com, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Latest podspec

{
    "name": "NDPhraseParser",
    "version": "0.1.0",
    "summary": "A library that allows for formatting strings with context, like Python.",
    "description": "                       A library that allows for formatting strings with context, like Python.n                       We wrote this library to allow us to pass strings with missing contextn                       to our mobile applications. This library is _almost_ a direct portn                       of Square's awesome Android library Phrase: https://github.com/square/phrasen                       which we use in production at Nextdoor.n",
    "homepage": "https://github.com/Nextdoor/NDPhraseParser",
    "license": "Apache 2.0",
    "authors": {
        "Sean McQueen": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Nextdoor/NDPhraseParser.git",
        "tag": "0.1.0"
    },
    "social_media_url": "https://twitter.com/NextdoorEng",
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "NDPhraseParser": [
            "Pod/Assets/*.png"
        ]
    }
}

Pin It on Pinterest

Share This