Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyflores committed Mar 28, 2014
0 parents commit e53d383
Show file tree
Hide file tree
Showing 38 changed files with 1,235 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
xcuserdata

Build
DerivedData

.sass-cache

.DS_Store
Pods
Podfile.lock
*.xcworkspace
93 changes: 93 additions & 0 deletions DECategories.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Pod::Spec.new do |s|
s.name = 'DECategories'
s.version = '0.0.1'

s.homepage = 'https://github.com/dreamengine/DECategories'
s.author = { 'Dream Engine Interactive, Inc.' => 'contact@dreamengine.com' }
s.social_media_url = 'https://twitter.com/dreamengine'

s.summary = 'A collection of useful categories for the modern iOS developer.'
s.description = "DECategories is a collection of Foundation and UIKit categories that simplify some of the monotonous code patterns in iOS development. It also provides various bells and whistles to streamline small tasks."

s.platform = :ios, '6.0'
s.requires_arc = true
s.frameworks = ['Foundation', 'UIKit']
s.source = { :git => 'https://github.com/dreamengine/DECategories.git', :tag => s.version.to_s }

s.license = {
:type => 'MIT',
:file => 'LICENSE'
}

s.subspec 'NSData+DEImageMimeType' do |cs|
cs.source_files = 'src/NSData+DEImageMimeType.{h,m}'
end

s.subspec 'NSMutableArray+DEWeakReferences' do |cs|
cs.source_files = 'src/NSMutableArray+DEWeakReferences.{h,m}'
end

s.subspec 'NSMutableDictionary+DENonNil' do |cs|
cs.source_files = 'src/NSMutableDictionary+DENonNil.{h,m}'
end

s.subspec 'NSMutableSet+DEWeakReferences' do |cs|
cs.source_files = 'src/NSMutableSet+DEWeakReferences.{h,m}'
end

s.subspec 'NSNotification+DEConveniences' do |cs|
cs.source_files = 'src/NSNotification+DEConveniences.{h,m}'
end

s.subspec 'NSString+DERelativePaths' do |cs|
cs.source_files = 'src/NSString+DERelativePaths.{h,m}'
end

s.subspec 'UIButton+DEBackgroundColor' do |cs|
cs.source_files = 'src/UIButton+DEBackgroundColor.{h,m}'
cs.dependency 'DECategories/UIImage+DEColorRect'
end

s.subspec 'UIColor+DEConveniences' do |cs|
cs.source_files = 'src/UIColor+DEConveniences.{h,m}'
end

s.subspec 'UIGestureRecognizer+DECancel' do |cs|
cs.source_files = 'src/UIGestureRecognizer+DECancel.{h,m}'
end

s.subspec 'UIImage+DEColorRect' do |cs|
cs.source_files = 'src/UIImage+DEColorRect.{h,m}'
cs.frameworks = ['QuartzCore']
end

s.subspec 'UIImage+DEResize' do |cs|
cs.source_files = 'src/UIImage+DEResize.{h,m}'
end

s.subspec 'UIImage+DETintColor' do |cs|
cs.source_files = 'src/UIImage+DETintColor.{h,m}'
end

s.subspec 'UINib+DEConveniences' do |cs|
cs.source_files = 'src/UINib+DEConveniences.{h,m}'
end

s.subspec 'UITableView+DEHideEmptyCells' do |cs|
cs.source_files = 'src/UITableView+DEHideEmptyCells.{h,m}'
end

s.subspec 'UIView+DEConveniences' do |cs|
cs.source_files = 'src/UIView+DEConveniences.{h,m}'
cs.dependency 'DECategories/UINib+DEConveniences'
end

s.subspec 'UIView+DEFirstResponder' do |cs|
cs.source_files = 'src/UIView+DEFirstResponder.{h,m}'
end

s.subspec 'UIViewController+DEConveniences' do |cs|
cs.source_files = 'src/.{h,m}'
end

end
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2014 Dream Engine Interactive, Inc.

http://dreamengine.com

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.
125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# DECategories

[https://github.com/dreamengine/DECategories](https://github.com/dreamengine/DECategories)

## What It Does

`DECategories` is a collection of useful categories for the modern iOS developer. These categories make the creation process easier and faster by providing a multitude of conveniences.


## How It Works

Below is a list of included categories and what they provide.

### NSData+DEImageMimeType

*Problem:* You have an image but aren't sure if it's a png or gif.

*Solution:* Just use `-imageDataMimeType` on the image's `NSData` representation and get a mime type string (e.g. @"image/png").

### NSMutableArray+DEWeakReferences

*Problem:* You want to store an array of objects but don't want to retain them (e.g. a list of prioritized delegates).

*Solution:* Use `+mutableArrayUsingWeakReferences` and stash away!


### NSMutableDictionary+DENonNil

*Problem:* You are populating a dictionary, but some of the objects are optional and you're tired of safety checking to make sure that each one is non-nil before adding them.

*Solution:* Use `-setObjectIfNonNil:forKey:`, and your object will only be added if it is non-nil.


### NSMutableSet+DEWeakReferences

*Problem:* You want to store a set of objects but don't want to retain them (e.g. an unordered list of delegates).

*Solution:* Use `+mutableSetUsingWeakReferences` and stash away!

### NSNotification+DEConveniences

*Problem:* Your app only ever uses the default notification center `[NSNotificationCenter defaultCenter]` and you are so very tired of always having to reference it. You also tire of having to manually package `NSNotification` objects whenever you want to send data.

*Solution:* Just use `+postNotificationWithName:`, `postNotificationWithName:object:`, and `postNotificationWithName:object:userInfo:`, which will automatically package an `NSNotification` for you and send it out to the default notification center.

### NSString+DERelativePaths

*Problem:* You have an absolute file path, but you only want the file's path relative to some directory. (E.g. your app utilizes user-provided files and folders and you want to store certain paths, but an app update may change where those files are stored and break the absolute paths you saved.)

*Solution:* Use `-stringWithPathRelativeTo:` and get the relative path.

### UIButton+DEBackgroundColor

*Problem:* You want the background color of your `UIButton` to change as the control state changes.

*Solution:* Use `-setBackgroundColor:forState:`.

### UIColor+DEConveniences

*Problem:* You want to create a `UIColor` from a hex string, or you want to make a UIColor without all the verbosity.

*Solution:* For creating a hex string, use `colorWithHexString:`, or you can use the convenience function `UIColorFromHexString(NSString)`.

All convenience functions:

* `UIColorFromValues(float, float, float)`,
* `UIColorFromValuesWithAlpha(float, float, float, float)`,
* `UIColorFromIntValues(int, int, int)` (0-255),
* `UIColorFromIntValuesWithAlpha(int, int, int, int)` (0-255), and
* `UIColorFromHexString(NSString)`.

### UIGestureRecognizer+DECancel

*Problem:* You want to be able to manually cancel a `UIGestureRecognizer`.

*Solution:* Use `-cancel`.

### UIImage+DEColorRect

*Problem:* You want to create a `UIImage` that's filled with a certain color.

*Solution:* Use `+imageWithColor:ofSize:`.

### UIImage+DEResize

*Problem:* You want to resize a UIImage, perhaps to save on memory if the image is too large.

*Solution:* Use `+imageWithImage:scaledToSize:`, or `-resizedImageScaledToSize:`.

### UIImage+DETintColor

*Problem:* You want to add a tint to a `UIImage`.

*Solution:* Use `-imageTintedWithColor:fraction:`.

### UINib+DEConveniences

*Problem:* You want to inflate an object from a nib file without all the hassle.

*Solution:* Use `+firstObjectWithNibName:`, which will automatically create a UINib object and send the first item in that nib back to you.

### UITableView+DEHideEmptyCells

*Problem:* You have a table view with short cell contents, and you don't much care for the empty cells and lines that are drawn underneath your cells.

*Solution:* Use `-applyHideEmptyCellsStyle`.

### UIView+DEConveniences

*Problem:* You want to directly get and set `x`, `y`, `width`, and `height` values without going through the `frame`. Or, you want to inflate a `UIView` from a nib file and wish it was just a little easier.

*Solution:* `x`, `y`, `width`, and `height` properties are provided. To quickly instantiate from a nib file, use `+viewFromNib` (just make sure that your nib file matches the class name).

### UIView+DEFirstResponder

*Problem:* You don't know who the first responder is, but you sure would like to find out.

*Solution:* Use `-findFirstResponder`. (If you want to resign the first responder and don't care who it is, you can just use the built-in `-endEditing:` on your main `UIView` container).


### UIViewController+DEConveniences

*Problem:* You wish there was a factory method for easily constructing `UIViewController` instances.

*Solution:* There is! You can simply use `+controller`, and it will automatically attempt to load a nib file with your class's string representation. If a nib file is not found, it will programmatically instantiate your controller.
14 changes: 14 additions & 0 deletions src/NSData+DEImageMimeType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// NSData+DEImageMimeType.h
//
// Created by Jeremy Flores on 3/8/13.
// Copyright (c) 2013 Dream Engine Interactive, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSData (DEImageMimeType)

-(NSString *)imageDataMimeType;

@end
46 changes: 46 additions & 0 deletions src/NSData+DEImageMimeType.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// NSData+DEImageMimeType.m
//
// Created by Jeremy Flores on 3/8/13.
// Copyright (c) 2013 Dream Engine Interactive, Inc. All rights reserved.
//
// from: http://stackoverflow.com/a/5042365/708798

#import "NSData+DEImageMimeType.h"

@implementation NSData (DEImageMimeType)

-(NSString *)imageDataMimeType {
uint8_t c;
[self getBytes:&c length:1];

switch (c) {
case 0xFF:
return @"image/jpeg";
case 0x89:
return @"image/png";
case 0x47:
return @"image/gif";
case 0x49:
case 0x4D:
return @"image/tiff";
case 0x42:
return @"image/bmp";
case 0x52:
// from: https://github.com/rs/SDWebImage/blob/master/SDWebImage/NSData%2BImageContentType.m
// R as RIFF for WEBP
if ([self length] < 12) {
return nil;
}

NSString *testString = [[NSString alloc] initWithData:[self subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {
return @"image/webp";
}

return nil;
}
return nil;
}

@end
15 changes: 15 additions & 0 deletions src/NSMutableArray+DEWeakReferences.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// NSMutableArray+DEWeakReferences.h
//
// Created by Jeremy Flores on 6/2/13.
// Copyright (c) 2013 Dream Engine Interactive, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSMutableArray (DEWeakReferences)

+ (id)mutableArrayUsingWeakReferences;
+ (id)mutableArrayUsingWeakReferencesWithCapacity:(NSUInteger)capacity;

@end
22 changes: 22 additions & 0 deletions src/NSMutableArray+DEWeakReferences.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// NSMutableArray+DEWeakReferences.m
//
// Created by Jeremy Flores on 6/2/13.
// Copyright (c) 2013 Dream Engine Interactive, Inc. All rights reserved.
//

#import "NSMutableArray+DEWeakReferences.h"

@implementation NSMutableArray (DEWeakReferences)

+ (id)mutableArrayUsingWeakReferences {
return [self mutableArrayUsingWeakReferencesWithCapacity:0];
}

+ (id)mutableArrayUsingWeakReferencesWithCapacity:(NSUInteger)capacity {
CFArrayCallBacks callbacks = {0, NULL, NULL, CFCopyDescription, CFEqual};
// We create a weak reference array
return (id)CFBridgingRelease(CFArrayCreateMutable(0, capacity, &callbacks));
}

@end
15 changes: 15 additions & 0 deletions src/NSMutableDictionary+DENonNil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// NSMutableDictionary+DENonNil.h
//
//
// Created by Jeremy Flores on 3/26/13.
// Copyright (c) 2013 Dream Engine Interactive, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSMutableDictionary (DENonNil)

-(void)setObjectIfNonNil:(id)anObject forKey:(id<NSCopying>)aKey;

@end
19 changes: 19 additions & 0 deletions src/NSMutableDictionary+DENonNil.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// NSMutableDictionary+DENonNil.m
//
//
// Created by Jeremy Flores on 3/26/13.
// Copyright (c) 2013 Dream Engine Interactive, Inc. All rights reserved.
//

#import "NSMutableDictionary+DENonNil.h"

@implementation NSMutableDictionary (DENonNil)

-(void)setObjectIfNonNil:(id)anObject forKey:(id<NSCopying>)aKey {
if (anObject) {
[self setObject:anObject forKey:aKey];
}
}

@end

0 comments on commit e53d383

Please sign in to comment.