The iOS framework that grows only as fast as its documentation
NIFoundationMethods.h
1 //
2 // Copyright 2011-2014 NimbusKit
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #import <Foundation/Foundation.h>
18 #import <UIKit/UIKit.h>
19 
20 #import "NIPreprocessorMacros.h"
21 
22 #if defined __cplusplus
23 extern "C" {
24 #endif
25 
38 #pragma mark - NSInvocation Methods
39 
45 NSInvocation* NIInvocationWithInstanceTarget(NSObject* target, SEL selector);
46 
52 NSInvocation* NIInvocationWithClassTarget(Class targetClass, SEL selector);
53 
54 #pragma mark - CGRect Methods
55 
73 CGRect NIRectContract(CGRect rect, CGFloat dx, CGFloat dy);
74 
82 CGRect NIRectExpand(CGRect rect, CGFloat dx, CGFloat dy);
83 
92 CGRect NIRectShift(CGRect rect, CGFloat dx, CGFloat dy);
93 
100 CGRect NIEdgeInsetsOutsetRect(CGRect rect, UIEdgeInsets outsets);
101 
107 CGFloat NICenterX(CGSize containerSize, CGSize size);
108 
114 CGFloat NICenterY(CGSize containerSize, CGSize size);
115 
121 CGRect NIFrameOfCenteredViewWithinView(UIView* viewToCenter, UIView* containerView);
122 
126 CGSize NISizeOfStringWithLabelProperties(NSString *string, CGSize constrainedToSize, UIFont *font, NSLineBreakMode lineBreakMode, NSInteger numberOfLines);
127 
131 #pragma mark - NSRange Methods
132 
151 NSRange NIMakeNSRangeFromCFRange(CFRange range);
152 
156 #pragma mark - NSData Methods
157 
168 NSString* NIMD5HashFromData(NSData* data);
169 
173 NSString* NISHA1HashFromData(NSData* data);
174 
178 #pragma mark - NSString Methods
179 
192 NSString* NIMD5HashFromString(NSString* string);
193 
199 NSString* NISHA1HashFromString(NSString* string);
200 
205 BOOL NIIsStringWithWhitespaceAndNewlines(NSString* string);
206 
243 NSComparisonResult NICompareVersionStrings(NSString* string1, NSString* string2);
244 
255 NSDictionary* NIQueryDictionaryFromStringUsingEncoding(NSString* string, NSStringEncoding encoding);
256 
260 NSString* NIStringByAddingPercentEscapesForURLParameterString(NSString* parameter);
261 
265 NSString* NIStringByAddingQueryDictionaryToString(NSString* string, NSDictionary* query);
266 
270 #pragma mark - CGFloat Methods
271 
283 #if CGFLOAT_IS_DOUBLE
284  #define NI_CGFLOAT_EPSILON DBL_EPSILON
285 #else
286  #define NI_CGFLOAT_EPSILON FLT_EPSILON
287 #endif
288 
292 CG_INLINE CGFloat NICGFloatAbs(CGFloat x) {
293 #if CGFLOAT_IS_DOUBLE
294  return (CGFloat)fabs(x);
295 #else
296  return (CGFloat)fabsf(x);
297 #endif
298 }
299 
303 CG_INLINE CGFloat NICGFloatFloor(CGFloat x) {
304 #if CGFLOAT_IS_DOUBLE
305  return (CGFloat)floor(x);
306 #else
307  return (CGFloat)floorf(x);
308 #endif
309 }
310 
314 CG_INLINE CGFloat NICGFloatCeil(CGFloat x) {
315 #if CGFLOAT_IS_DOUBLE
316  return (CGFloat)ceil(x);
317 #else
318  return (CGFloat)ceilf(x);
319 #endif
320 }
321 
325 CG_INLINE CGFloat NICGFloatRound(CGFloat x) {
326 #if CGFLOAT_IS_DOUBLE
327  return (CGFloat)round(x);
328 #else
329  return (CGFloat)roundf(x);
330 #endif
331 }
332 
336 CG_INLINE CGFloat NICGFloatSqRt(CGFloat x) {
337 #if CGFLOAT_IS_DOUBLE
338  return (CGFloat)sqrt(x);
339 #else
340  return (CGFloat)sqrtf(x);
341 #endif
342 }
343 
347 CG_INLINE CGFloat NICGFloatCopySign(CGFloat x, CGFloat y) {
348 #if CGFLOAT_IS_DOUBLE
349  return (CGFloat)copysign(x, y);
350 #else
351  return (CGFloat)copysignf(x, y);
352 #endif
353 }
354 
358 CG_INLINE CGFloat NICGFloatPow(CGFloat x, CGFloat y) {
359 #if CGFLOAT_IS_DOUBLE
360  return (CGFloat)pow(x, y);
361 #else
362  return (CGFloat)powf(x, y);
363 #endif
364 }
365 
369 CG_INLINE CGFloat NICGFloatCos(CGFloat x) {
370 #if CGFLOAT_IS_DOUBLE
371  return (CGFloat)cos(x);
372 #else
373  return (CGFloat)cosf(x);
374 #endif
375 }
376 
379 #pragma mark - General Purpose Methods
380 
391 CGFloat boundf(CGFloat value, CGFloat min, CGFloat max) __NI_DEPRECATED_METHOD; // Use NIBoundf instead. MAINTENANCE: Remove by Feb 28, 2014.
392 
396 NSInteger boundi(NSInteger value, NSInteger min, NSInteger max) __NI_DEPRECATED_METHOD; // Use NIBoundi instead. MAINTENANCE: Remove by Feb 28, 2014.
397 
405 CGFloat NIBoundf(CGFloat value, CGFloat min, CGFloat max);
406 
414 NSInteger NIBoundi(NSInteger value, NSInteger min, NSInteger max);
415 
418 #if defined __cplusplus
419 };
420 #endif
421 // End of Foundation Methods ///////////////////////////////////////////////////////////////
NSRange NIMakeNSRangeFromCFRange(CFRange range)
Create an NSRange object from a CFRange object.
#define __NI_DEPRECATED_METHOD
Mark a method or property as deprecated to the compiler.
NSDictionary * NIQueryDictionaryFromStringUsingEncoding(NSString *string, NSStringEncoding encoding)
Parses a URL query string into a dictionary where the values are arrays.
NSString * NIMD5HashFromData(NSData *data)
Calculates an md5 hash of the data using CC_MD5.
CG_INLINE CGFloat NICGFloatSqRt(CGFloat x)
sqrt()/sqrtf() sized for CGFloat
CGRect NIRectContract(CGRect rect, CGFloat dx, CGFloat dy)
Modifies only the right and bottom edges of a CGRect.
CG_INLINE CGFloat NICGFloatCopySign(CGFloat x, CGFloat y)
copysign()/copysignf() sized for CGFloat
CG_INLINE CGFloat NICGFloatPow(CGFloat x, CGFloat y)
pow()/powf() sized for CGFloat
CG_INLINE CGFloat NICGFloatCeil(CGFloat x)
ceil()/ceilf() sized for CGFloat
CG_INLINE CGFloat NICGFloatFloor(CGFloat x)
floor()/floorf() sized for CGFloat
NSString * NIMD5HashFromString(NSString *string)
Calculates an md5 hash of the string using CC_MD5.
BOOL NIIsStringWithWhitespaceAndNewlines(NSString *string)
Returns a Boolean value indicating whether the string is a NSString object that contains only whitesp...
CGRect NIRectExpand(CGRect rect, CGFloat dx, CGFloat dy)
Modifies only the right and bottom edges of a CGRect.
CGFloat boundf(CGFloat value, CGFloat min, CGFloat max)
Deprecated method.
NSInteger boundi(NSInteger value, NSInteger min, NSInteger max)
Deprecated method.
NSString * NISHA1HashFromData(NSData *data)
Calculates a sha1 hash of the data using CC_SHA1.
CG_INLINE CGFloat NICGFloatCos(CGFloat x)
cos()/cosf() sized for CGFloat
NSString * NISHA1HashFromString(NSString *string)
Calculates a sha1 hash of the string using CC_SHA1.
CGSize NISizeOfStringWithLabelProperties(NSString *string, CGSize constrainedToSize, UIFont *font, NSLineBreakMode lineBreakMode, NSInteger numberOfLines)
Returns the size of the string with given UILabel properties.
CGFloat NIBoundf(CGFloat value, CGFloat min, CGFloat max)
Bounds a given value within the min and max values.
NSInteger NIBoundi(NSInteger value, NSInteger min, NSInteger max)
Bounds a given value within the min and max values.
NSComparisonResult NICompareVersionStrings(NSString *string1, NSString *string2)
Compares two strings expressing software versions.
CGRect NIRectShift(CGRect rect, CGFloat dx, CGFloat dy)
Modifies only the top and left edges of a CGRect.
NSInvocation * NIInvocationWithClassTarget(Class targetClass, SEL selector)
Construct an NSInvocation for a class method given a class object and a selector. ...
CG_INLINE CGFloat NICGFloatAbs(CGFloat x)
fabs()/fabsf() sized for CGFloat
CGFloat NICenterX(CGSize containerSize, CGSize size)
Returns the x position that will center size within containerSize.
CGFloat NICenterY(CGSize containerSize, CGSize size)
Returns the y position that will center size within containerSize.
NSString * NIStringByAddingQueryDictionaryToString(NSString *string, NSDictionary *query)
Appends a dictionary of query parameters to a string, adding the ? character if necessary.
NSInvocation * NIInvocationWithInstanceTarget(NSObject *target, SEL selector)
Construct an NSInvocation with an instance of an object and a selector.
CGRect NIFrameOfCenteredViewWithinView(UIView *viewToCenter, UIView *containerView)
Returns a rect that will center viewToCenter within containerView.
CG_INLINE CGFloat NICGFloatRound(CGFloat x)
round()/roundf() sized for CGFloat
NSString * NIStringByAddingPercentEscapesForURLParameterString(NSString *parameter)
Returns a string that has been escaped for use as a URL parameter.
CGRect NIEdgeInsetsOutsetRect(CGRect rect, UIEdgeInsets outsets)
Inverse of UIEdgeInsetsInsetRect.