-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from twotoasters/subclass-responsibility
Subclass responsibility
- Loading branch information
Showing
6 changed files
with
252 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// TWTErrorUtilities.h | ||
// TWTToast | ||
// | ||
// Created by Prachi Gauriar on 12/6/2012. | ||
// Copyright (c) 2013–2014 Prachi Gauriar. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
|
||
/*! | ||
@header TWTErrorUtilities | ||
@abstract Defines utility functions and categories for use when creating assertions and exceptions. | ||
@discussion The utility functions allow for easily formatting selectors, method names, and exception reasons. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
/*! | ||
@abstract Returns an NSString representation of the selector. | ||
@discussion This simply returns the result of NSStringFromSelector(selector), prefixed with a '+' if receiver is | ||
a class and '-' otherwise. | ||
@param receiver The object responding to the selector. | ||
@param selector The selector to which the receiver will be responding. | ||
@result A pretty-printed NSString representation of the selector. | ||
*/ | ||
extern NSString *TWTPrettySelector(id receiver, SEL selector); | ||
|
||
/*! | ||
@abstract Returns an NSString representation of the selector. | ||
@discussion The string is of the form \@"+[receiver selector]" for class methods and \@"-[receiverClassName selector]" | ||
for instance methods. | ||
@param receiver The object responding to the selector. | ||
@param selector The selector to which the receiver will be responding. | ||
@result A pretty-printed NSString representation of the method name, including the receiving class. | ||
*/ | ||
extern NSString *TWTPrettyMethodName(id receiver, SEL selector); | ||
|
||
/*! | ||
@abstract Returns an NSString that is formatted suitably for use as an exception message. | ||
@discussion Formatting is consistent with Apple's own exception messages. | ||
@param receiver The object responding to the selector. This is typically self. | ||
@param selector The selector to which the receiver will be responding. This is typically _cmd. | ||
@param format A format string describing the reason for the exception. | ||
@result An NSString formatted suitable for use as an exception message. | ||
*/ | ||
extern NSString *TWTExceptionString(id receiver, SEL selector, NSString *format, ...) NS_FORMAT_FUNCTION(3, 4); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// TWTErrorUtilities.m | ||
// TWTToast | ||
// | ||
// Created by Prachi Gauriar on 12/6/2012. | ||
// Copyright (c) 2013–2014 Prachi Gauriar. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
|
||
#import "TWTErrorUtilities.h" | ||
|
||
NSString *TWTPrettySelector(id receiver, SEL selector) | ||
{ | ||
char methodType = [receiver isMemberOfClass:[receiver class]] ? '-' : '+'; | ||
return [NSString stringWithFormat:@"%c%@", methodType, NSStringFromSelector(selector)]; | ||
} | ||
|
||
|
||
NSString *TWTPrettyMethodName(id receiver, SEL selector) | ||
{ | ||
char methodType = [receiver isMemberOfClass:[receiver class]] ? '-' : '+'; | ||
return [NSString stringWithFormat:@"%c[%@ %@]", methodType, NSStringFromClass([receiver class]), NSStringFromSelector(selector)]; | ||
} | ||
|
||
|
||
NSString *TWTExceptionString(id receiver, SEL selector, NSString *format, ...) | ||
{ | ||
va_list arguments; | ||
va_start(arguments, format); | ||
NSString *messageString = [[NSString alloc] initWithFormat:format arguments:arguments]; | ||
va_end(arguments); | ||
|
||
return [NSString stringWithFormat:@"*** %@: %@", TWTPrettyMethodName(receiver, selector), messageString]; | ||
} |
45 changes: 45 additions & 0 deletions
45
Foundation/Subclass Responsibility/NSException+TWTSubclassResponsibility.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// NSException+TWTSubclassResponsibility.h | ||
// TWTToast | ||
// | ||
// Created by Prachi Gauriar on 1/5/2014. | ||
// Copyright (c) 2014 Prachi Gauriar. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
/*! | ||
The TWTSubclassResponsibility category of NSException provides a convenience factory method for creating | ||
exceptions when implementing a given method is a subclass's responsibility. | ||
*/ | ||
@interface NSException (TWTSubclassResponsibility) | ||
|
||
/*! | ||
@abstract Creates and returns a new NSInternalInconsistencyException indicating that implementing | ||
the method specified by the given receiver-selector pair is a subclass's responsibility. | ||
@param receiver The object responding to the selector. This is typically self. | ||
@param selector The selector to which the receiver will be responding. This is typically _cmd. | ||
@result A new NSInternalInconsistencyException | ||
*/ | ||
+ (instancetype)twt_subclassResponsibilityExceptionWithReceiver:(id)receiver selector:(SEL)selector; | ||
|
||
@end | ||
|
40 changes: 40 additions & 0 deletions
40
Foundation/Subclass Responsibility/NSException+TWTSubclassResponsibility.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// NSException+TWTSubclassResponsibility.m | ||
// TWTToast | ||
// | ||
// Created by Prachi Gauriar on 1/5/2014. | ||
// Copyright (c) 2014 Prachi Gauriar. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
|
||
#import "NSException+TWTSubclassResponsibility.h" | ||
|
||
#import "TWTErrorUtilities.h" | ||
|
||
@implementation NSException (TWTSubclassResponsibility) | ||
|
||
+ (instancetype)twt_subclassResponsibilityExceptionWithReceiver:(id)receiver selector:(SEL)selector | ||
{ | ||
return [NSException exceptionWithName:NSInternalInconsistencyException | ||
reason:TWTExceptionString(receiver, selector, @"subclasses must provide an implementation of this method") | ||
userInfo:nil]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,34 @@ | ||
Pod::Spec.new do |s| | ||
s.name = "TWTToast" | ||
s.version = "0.1" | ||
s.version = "0.2" | ||
s.summary = "Tools and Utilities for Cocoa Development" | ||
s.homepage = "https://github.com/twotoasters/Toast" | ||
s.license = { :type => 'MIT', :file => 'LICENSE' } | ||
s.author = { "Two Toasters" => "[email protected]" } | ||
s.social_media_url = "http://twitter.com/twotoasters" | ||
s.platform = :ios, '7.0' | ||
s.source = { :git => "https://github.com/twotoasters/Toast.git", :tag => "0.1" } | ||
s.source = { :git => "https://github.com/twotoasters/Toast.git", :tag => "0.2" } | ||
s.requires_arc = true | ||
|
||
## Subspec for Core files. Files that extend Foundation is an example | ||
## Subspec for Core files | ||
s.subspec 'Core' do |sp| | ||
sp.source_files = "Core/**/*.{h,m}" | ||
end | ||
|
||
## Subspec for files related to Foundation | ||
s.subspec 'Foundation' do |sp| | ||
sp.source_files = "UIKit/**/*.{h,m}" | ||
|
||
sp.subspec 'ErrorUtilities' do |ss| | ||
ss.source_files = "Foundation/Error Utilities/*.{h,m}" | ||
end | ||
|
||
sp.subspec 'SubclassResponsibility' do |ss| | ||
ss.dependency 'TWTToast/Foundation/ErrorUtilities' | ||
ss.source_files = "Foundation/Subclass Responsibility/*.{h,m}" | ||
end | ||
end | ||
|
||
## Subspec for Files Related to UIKit | ||
s.subspec 'UIKit' do |sp| | ||
sp.source_files = "UIKit/**/*.{h,m}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters