With ODStringify, you can create strings from classes, properties, defines, and functions using one function—safely.
And everything is done at compile time.
No more runtime overhead and calls like NSStringFromClass
(although for this function, it was very small).
First of all, you can create strings from defined values. It's amazing. For example:
#define MAX_NUMBER_OF_SOMETHING 10
#define DEFAULT_HI_STRING @"hello"
NSLog(@"Hi string:%@", ODStringify(DEFAULT_HI_STRING)); // > @"hello" (@"@\"hello\"")
NSLog(@"Max number:%@", ODStringify(MAX_NUMBER_OF_SOMETHING)); // > 10 (@"10")
Class name string with compile-time type checking.
NSLog(@"Valid class:%@", ODStringifyClass(AppDelegate)); // AppDelegate
NSLog(@"Invalid class:%@", ODStringifyClass(App_Delegate)); // Error
Protocol name string with compile-time type checking.
NSLog(@"Valid protocol:%@", ODStringifyProtocol(NSCopying)); // NSCopying
NSLog(@"Invalid protocol:%@", ODStringifyProtocol(NSCopiing)); // Error
Pretty much the same thing for properties.
Note: You need to be inside a class implementation (and have access to self
).
// AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"Valid property:%@", ODStringifyProperty(window)); // window
NSLog(@"Invalid property:%@", ODStringifyProperty(window_)); // Error
return YES;
}
ODStringify supports multiple methods for installing the library in a project.
CocoaPods is a dependency manager for Objective-C and Swift, which automates and simplifies the process of using third-party libraries like ODStringify in your projects. You can install it with the following command:
$ gem install cocoapods
To integrate ODStringify into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '12.0'
target 'TargetName' do
pod 'ODStringify'
end
Then, run the following command:
$ pod install
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following commands:
$ brew update
$ brew install carthage
To integrate ODStringify into your Xcode project using Carthage, specify it in your Cartfile
:
github "nzrsky/ODStringify" ~> 1.1
Run carthage
to build the framework and drag the built ODStringify.framework
into your Xcode project.
Alexey Nazarov, alexx.nazaroff@gmail.com
ODStringify is available under the MIT license. See the LICENSE file for more info.