From 24c53bde2e9a23581f7e855626e75257e1d6b741 Mon Sep 17 00:00:00 2001 From: Kim Wittenburg Date: Wed, 23 Apr 2014 03:09:26 +0200 Subject: [PATCH] Added Helper Categories Added Documentation --- MathPad/NSIndexPath+MPRemoveFirstIndex.h | 21 ++++++++++++++++++ MathPad/NSIndexPath+MPRemoveFirstIndex.m | 27 ++++++++++++++++++++++++ MathPad/NSObject+MPStringTest.h | 6 ++++++ MathPad/NSTextStorage+MPSetContents.h | 21 ++++++++++++++++++ MathPad/NSTextStorage+MPSetContents.m | 19 +++++++++++++++++ 5 files changed, 94 insertions(+) create mode 100644 MathPad/NSIndexPath+MPRemoveFirstIndex.h create mode 100644 MathPad/NSIndexPath+MPRemoveFirstIndex.m create mode 100644 MathPad/NSTextStorage+MPSetContents.h create mode 100644 MathPad/NSTextStorage+MPSetContents.m diff --git a/MathPad/NSIndexPath+MPRemoveFirstIndex.h b/MathPad/NSIndexPath+MPRemoveFirstIndex.h new file mode 100644 index 0000000..5cdb721 --- /dev/null +++ b/MathPad/NSIndexPath+MPRemoveFirstIndex.h @@ -0,0 +1,21 @@ +// +// NSIndexPath+MPRemoveFirstIndex.h +// MathPad +// +// Created by Kim Wittenburg on 23.04.14. +// Copyright (c) 2014 Kim Wittenburg. All rights reserved. +// + +#import + +@interface NSIndexPath (MPRemoveFirstIndex) + +/*! + @method indexPathByRemovingFirstIndex + @brief Provides an index path with the indexes in the receiving index path, excluding the first one. + @discussion Returns an empty NSIndexPath instance if the receiving index path’s length is 1 or less. + @return New index path with the receiving index path’s indexes, excluding the first one. + */ +- (NSIndexPath *)indexPathByRemovingFirstIndex; + +@end diff --git a/MathPad/NSIndexPath+MPRemoveFirstIndex.m b/MathPad/NSIndexPath+MPRemoveFirstIndex.m new file mode 100644 index 0000000..99997af --- /dev/null +++ b/MathPad/NSIndexPath+MPRemoveFirstIndex.m @@ -0,0 +1,27 @@ +// +// NSIndexPath+MPRemoveFirstIndex.m +// MathPad +// +// Created by Kim Wittenburg on 23.04.14. +// Copyright (c) 2014 Kim Wittenburg. All rights reserved. +// + +#import "NSIndexPath+MPRemoveFirstIndex.h" + +@implementation NSIndexPath (MPRemoveFirstIndex) + +- (NSIndexPath *)indexPathByRemovingFirstIndex +{ + if (self.length <= 1) { + return [[NSIndexPath alloc] init]; + } + NSUInteger indexes[self.length]; + [self getIndexes:indexes]; + NSUInteger newIndexes[self.length-1]; + for (NSUInteger i = 0; i < self.length-1; i++) { + newIndexes[i] = indexes[i+1]; + } + return [[NSIndexPath alloc] initWithIndexes:newIndexes length:self.length-1]; +} + +@end diff --git a/MathPad/NSObject+MPStringTest.h b/MathPad/NSObject+MPStringTest.h index 73081d5..8e6a32b 100644 --- a/MathPad/NSObject+MPStringTest.h +++ b/MathPad/NSObject+MPStringTest.h @@ -10,6 +10,12 @@ @interface NSObject (MPStringTest) +/*! + @method isString + @brief Returns wether the receiver is a string object. + @discussion A string object is an instance of the @c NSString class or any of its subclasses (for example @c NSMutableString). For an @c NSAttributedString this method returns @c NO. + @return @c YES if the receiver is an instance of @c NSString or a subclass, @c NO otherwise. + */ - (BOOL)isString; @end diff --git a/MathPad/NSTextStorage+MPSetContents.h b/MathPad/NSTextStorage+MPSetContents.h new file mode 100644 index 0000000..ff1a798 --- /dev/null +++ b/MathPad/NSTextStorage+MPSetContents.h @@ -0,0 +1,21 @@ +// +// NSTextStorage+MPSetContents.h +// MathPad +// +// Created by Kim Wittenburg on 21.04.14. +// Copyright (c) 2014 Kim Wittenburg. All rights reserved. +// + +#import + +@interface NSTextStorage (MPSetContents) + +/*! + @method setString: + @brief Replaces the contents of the receiver with @c aString. + @discussion This method sends the receiver a @c replaceCharactersInRange:withString: with a range including all characters of the receiver and @c aString. See @c replaceCharactersInRange:withString: for details. + @param aString A string specifying the characters to replace the receiver's current contents. + */ +- (void)setString:(NSString *)aString; + +@end diff --git a/MathPad/NSTextStorage+MPSetContents.m b/MathPad/NSTextStorage+MPSetContents.m new file mode 100644 index 0000000..c1f2b4d --- /dev/null +++ b/MathPad/NSTextStorage+MPSetContents.m @@ -0,0 +1,19 @@ +// +// NSTextStorage+MPSetContents.m +// MathPad +// +// Created by Kim Wittenburg on 21.04.14. +// Copyright (c) 2014 Kim Wittenburg. All rights reserved. +// + +#import "NSTextStorage+MPSetContents.h" + +@implementation NSTextStorage (MPSetContents) + +- (void)setString:(NSString *)string +{ + NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:string]; + [self setAttributedString:attributedString]; +} + +@end