CocoaPods trunk is moving to be read-only. Read more on the blog, there are 12 months to go.
| TestsTested | ✓ |
| LangLanguage | Obj-CObjective C |
| License | MIT |
| ReleasedLast Release | Dec 2014 |
Maintained by Daniel L. Alves.
NitroMisc offers a lot of helpful code missing in iOS foundation and uikit classes in addition to utility macros. You will find:
NSBundle utilitiesNSError instantiationNSInvocation instantiation1) NSBundle utilities
Every app tasks at one place:
// Returns the value associated with the `kCFBundleNameKey` key in the main bundle information
// property list
NSString *myAppName = [NSBundle applicationName];
// Returns the value associated with the `kCFBundleVersionKey` key in the main bundle
// information property list
NSString *myAppVersion = [NSBundle applicationVersion];
// Reads a plist as a `NSDictionary`
NSError *error = nil;
[anyNSBundleObject readPropertyListWithName: @"myPlistNameWithOrWithoutExtension"
error: &error];
// Reads any file as a `NSString`
NSString *fileContent = [anyNSBundleObject stringWithEncoding: NSUTF8StringEncoding
fromResourceWithName: @"yourFileName"
type: @"yourFileExtension"];2) Shorter NSError instantiation
Set only the localizedDescription key 90% of the time? There you go:
NSError *muchBetterError = [NSError errorWithDomain: kMyAppNSErrorDomain
code: kMyAppShouldNotHappenErrorCode
localizedDescription: @"A localized description"];3) Shorter NSInvocation instantiation
Boilerplate code to create a NSInvocation object? Please:
NSInvocation *niceInvocation = [NSInvocation invocationForSelector: @selector( invocationSelector )
withTarget: self];4) Logging macros
Macros that log a generic message to the Apple System Log facility using NSLog.
When the DEBUG preprocessor macro is not defined or is false, calls to these macros will be stripped out of your code, generating no compilation, linking or binary overhead. They also come with the bonus of prepending the log message with the method name from which it was called.
// These will vanish if the DEBUG preprocessor macro is false
// or is not defined
NTR_LOG( @"%@ Simpson", @"Margie" ); // Logs "Margie Simpson"
NTR_LOGI( @"%@ Simpson", @"Liza" ); // Logs "INFO: Liza Simpson"
NTR_LOGW( @"%@ Simpson", @"Bart" ); // Logs "WARNING: Bart Simpson"
NTR_LOGE( @"%@ Simpson", @"Homer" ); // Logs "ERROR: Homer Simpson"5) Singleton macros
Tired of copy and pasting singleton generation macros all over your projects? But no more. NitroMisc has all you need and optmized for ARC code.
// .h file
@interface SingletonClass : NSObject
DEFAULT_DECLARE_SINGLETON_FOR_CLASS( SingletonClass )
@end
// .m file
@implementation SingletonClass
DEFAULT_SYNTHESIZE_SINGLETON_FOR_CLASS( SingletonClass )
@end
// Elsewhere: access the singleton
SingletonClass.sharedInstanceDo not like sharedInstance accessor name? No problem:
// .h file
@interface FancySingletonClass : NSObject
DECLARE_SINGLETON_FOR_CLASS( FancySingletonClass, theOne )
@end
// .m file
@implementation FancySingletonClass
SYNTHESIZE_SINGLETON_FOR_CLASS( FancySingletonClass, theOne )
@end
// Elsewhere: access the singleton
FancySingletonClass.theOne6) Silly warnings suppressing macros
Use the SuppressPerformSelectorLeakWarning macro to suppress "performSelector may cause a leak because its selector is unknown" warnings. Remember: This should only be used when you are sure the object responds to the selector.
-( void )letsFireASelectorWhoseNameWeDontKnow:( SEL )aSelector
{
// This code generates no warnings. But if you remove the macro...
if( [object respondsToSelector: aSelector] )
SuppressPerformSelectorLeakWarning( [object performSelector: aSelector] );
}iOS 4.3 or higher, ARC only
NitroMisc is available through CocoaPods, to install it simply add the following line to your Podfile:
pod "NitroMisc"NitroMisc adds the -ObjC linker flag to targets using it. Without it, categories code would be stripped out, resulting in linker errors. For more info about categories inside static libraries, see: Building Objective-C static libraries with categories
NitroMisc is available under the MIT license. See the LICENSE file for more info.