-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some categories found on projects #4
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// CLLocation+S2MAdditions.h | ||
// MoreMobile | ||
// | ||
// Created by Andreas Buff on 12/09/14. | ||
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved. | ||
// | ||
|
||
#import <CoreLocation/CoreLocation.h> | ||
|
||
@interface CLLocation (S2MAdditions) | ||
/** | ||
* Checks if a location is valid | ||
* | ||
* @return Yes if valid | ||
*/ | ||
- (BOOL)s2m_isValid; | ||
|
||
/** | ||
* Get the location with the most accurracy from given locations | ||
* | ||
* @param locations locations to be evaluated | ||
* | ||
* @return best location | ||
*/ | ||
+ (CLLocation *)bestLocationOfLocations:(NSArray *)locations; | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// CLLocation+S2MAdditions.m | ||
// MoreMobile | ||
// | ||
// Created by Andreas Buff on 12/09/14. | ||
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved. | ||
// | ||
|
||
#import "CLLocation+S2MAdditions.h" | ||
|
||
@implementation CLLocation (S2MAdditions) | ||
|
||
- (BOOL)s2m_isValid | ||
{ | ||
return self.horizontalAccuracy >= 0; | ||
} | ||
|
||
+ (CLLocation *)bestLocationOfLocations:(NSArray *)locations | ||
{ | ||
CLLocation *bestLocation = nil; | ||
for (int i = 0; i < locations.count; ++i) { | ||
CLLocation *currentLocation = [locations objectAtIndex:i]; | ||
if(i == 0) { | ||
bestLocation = currentLocation; | ||
} else if(abs([currentLocation.timestamp timeIntervalSinceNow]) < abs([bestLocation.timestamp timeIntervalSinceNow])) { | ||
bestLocation = currentLocation; | ||
} else if ((abs([currentLocation.timestamp timeIntervalSinceNow]) == abs([bestLocation.timestamp timeIntervalSinceNow])) | ||
&& currentLocation.horizontalAccuracy < bestLocation.horizontalAccuracy) { | ||
bestLocation = currentLocation; | ||
} | ||
} | ||
|
||
return bestLocation; | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// NSBundle+S2MAdditions.h | ||
// S2MToolbox | ||
// | ||
// Created by Andreas Buff on 28/05/14. | ||
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface NSBundle (S2MAdditions) | ||
|
||
/** | ||
* Convenience methode to get the first UIView of the content of a nib (xib) file. | ||
* | ||
* @param xibName Name of the xib file without extension | ||
* @param owner The object to assign as the nib’s File's Owner object. | ||
* | ||
* @return First view in the xib file | ||
*/ | ||
+ (UIView *)s2m_loadXibNamed:(NSString *)xibName | ||
owner:(id)owner; | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// NSBundle+S2MAdditions.m | ||
// MoreMobile | ||
// | ||
// Created by Andreas Buff on 28/05/14. | ||
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved. | ||
// | ||
|
||
#import "NSBundle+S2MAdditions.h" | ||
|
||
@implementation NSBundle (S2MAdditions) | ||
|
||
+ (UIView *)s2m_loadXibNamed:(NSString *)xibName | ||
owner:(id)owner | ||
{ | ||
return (UIView *)[[[NSBundle mainBundle] loadNibNamed:xibName | ||
owner:owner | ||
options:nil] | ||
objectAtIndex:0]; | ||
} | ||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// NSDate+S2MAdditions.h | ||
// MoreMobile | ||
// | ||
// Created by Andreas Buff on 26/06/14. | ||
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface NSDate (S2MAdditions) | ||
|
||
+ (instancetype)s2m_dateFromString:(NSString *)dateString | ||
dateFormat:(NSString *)format; | ||
|
||
/** | ||
* Whether or not the date is before now. | ||
* | ||
* @return YES, if timeinterval since now is negative; | ||
NO, otherwize | ||
*/ | ||
- (BOOL)s2m_inPast; | ||
|
||
/** | ||
* Whether or not the date is after now. | ||
* | ||
* @return YES, if timeinterval since now is positive, but not zero; | ||
NO, otherwize | ||
*/ | ||
- (BOOL)s2m_inFuture; | ||
|
||
/** | ||
* Returns the string representation of the date in a given format. * | ||
* Example format: "dd.MM.yyyy" | ||
* Output: "23.12.1972" | ||
* | ||
* @param aFormat format to format the string in | ||
* | ||
* @return string representation | ||
* @note The format must meet Apple's Data Formatting Criteria: | ||
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/DataFormatting/DataFormatting.html#//apple_ref/doc/uid/10000029i | ||
|
||
*/ | ||
- (NSString *)s2m_toStringWithFormat:(NSString *)aFormat; | ||
|
||
- (NSDate *)s2m_beginningOfDay; | ||
- (NSDate *)s2m_beginningOfMonth; | ||
- (NSDate *)s2m_endOfMonth; | ||
- (NSDate *)s2m_dateByAddingMonths:(NSInteger)monthsToAdd; | ||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// | ||
// NSDate+S2MAdditions.m | ||
// MoreMobile | ||
// | ||
// Created by Andreas Buff on 26/06/14. | ||
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved. | ||
// | ||
|
||
#import "NSDate+S2MAdditions.h" | ||
|
||
@implementation NSDate (S2MAdditions) | ||
|
||
+ (instancetype)s2m_dateFromString:(NSString *)dateString | ||
dateFormat:(NSString *)format | ||
{ | ||
NSDateFormatter *dateFormatter = [NSDateFormatter new]; | ||
[dateFormatter setDateFormat:format]; | ||
return [dateFormatter dateFromString:dateString]; | ||
} | ||
|
||
- (BOOL)s2m_inPast | ||
{ | ||
return [self timeIntervalSinceNow] < 0; | ||
} | ||
|
||
- (BOOL)s2m_inFuture | ||
{ | ||
return [self timeIntervalSinceNow] > 0; | ||
} | ||
|
||
- (NSString *)s2m_toStringWithFormat:(NSString *)aFormat | ||
{ | ||
NSDateFormatter *dateFormatter = [NSDateFormatter new]; | ||
[dateFormatter setDateFormat:aFormat]; | ||
return [dateFormatter stringFromDate:self]; | ||
} | ||
|
||
- (NSDate *)s2m_beginningOfDay | ||
{ | ||
NSCalendar *calendar = [NSCalendar currentCalendar]; | ||
// Get the weekday component of the current date | ||
NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) | ||
fromDate:self]; | ||
return [calendar dateFromComponents:components]; | ||
} | ||
|
||
- (NSDate *)s2m_beginningOfMonth | ||
{ | ||
NSCalendar * calendar = [NSCalendar currentCalendar]; | ||
|
||
NSDateComponents * currentDateComponents = [calendar components: NSYearCalendarUnit | NSMonthCalendarUnit fromDate:self]; | ||
NSDate * startOfMonth = [calendar dateFromComponents: currentDateComponents]; | ||
|
||
return startOfMonth; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NSYearCalendarUnit, NSMonthCalendarUnit, NSDayCalendarUnit are deprecated. Let's use new NSCalender.. enums instead |
||
} | ||
|
||
- (NSDate *)s2m_endOfMonth | ||
{ | ||
NSCalendar * calendar = [NSCalendar currentCalendar]; | ||
|
||
NSDate* plusOneMonthDate = [self s2m_dateByAddingMonths: 1]; | ||
NSDateComponents * plusOneMonthDateComponents = [calendar components: NSYearCalendarUnit | NSMonthCalendarUnit fromDate: plusOneMonthDate]; | ||
NSDate* endOfMonth = [[calendar dateFromComponents: plusOneMonthDateComponents] dateByAddingTimeInterval:-1]; // One second before the start of next month | ||
|
||
return endOfMonth; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NSYearCalendarUnit, NSMonthCalendarUnit, NSDayCalendarUnit are deprecated. Let's use new NSCalender.. enums instead |
||
} | ||
|
||
- (NSDate *)s2m_dateByAddingMonths:(NSInteger)monthsToAdd | ||
{ | ||
NSCalendar* calendar = [NSCalendar currentCalendar]; | ||
|
||
NSDateComponents* months = [[NSDateComponents alloc] init]; | ||
[months setMonth:monthsToAdd]; | ||
|
||
return [calendar dateByAddingComponents:months toDate:self options:0]; | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// NSFileManager+S2MAdditions.h | ||
// MoreMobile | ||
// | ||
// Created by Andreas Buff on 05/07/14. | ||
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface NSFileManager (S2MAdditions) | ||
|
||
+ (NSString *)s2m_documentsDirectoryPath; | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// NSFileManager+S2MAdditions.m | ||
// MoreMobile | ||
// | ||
// Created by Andreas Buff on 05/07/14. | ||
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved. | ||
// | ||
|
||
#import "NSFileManager+S2MAdditions.h" | ||
|
||
@implementation NSFileManager (S2MAdditions) | ||
|
||
+ (NSString *)s2m_documentsDirectoryPath | ||
{ | ||
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; | ||
} | ||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// NSManagedObject+S2MAdditions.h | ||
// MoreMobile | ||
// | ||
// Created by Andreas Buff on 11/06/14. | ||
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved. | ||
// | ||
|
||
#import <CoreData/CoreData.h> | ||
|
||
@interface NSManagedObject (S2MAdditions) | ||
|
||
/** | ||
* Gets the ManagedObject which matches the instance's object ID from a given context if it is already registered. | ||
|
||
Otherwise it creates a fault corresponding to that objectID. It never returns nil, and never performs I/O. The object specified by objectID is assumed to exist, and if that assumption is wrong the fault may throw an exception when used. | ||
* | ||
* @param moc context to get the object from | ||
* | ||
* @return object matching the givens object ID if exists, fault corresponding to that objectID otherwize | ||
*/ | ||
- (instancetype)s2m_fromManagedObjectContext:(NSManagedObjectContext *)moc; | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// NSManagedObject+S2MAdditions.m | ||
// MoreMobile | ||
// | ||
// Created by Andreas Buff on 11/06/14. | ||
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved. | ||
// | ||
|
||
#import "NSManagedObject+S2MAdditions.h" | ||
|
||
@implementation NSManagedObject (S2MAdditions) | ||
|
||
- (instancetype)s2m_fromManagedObjectContext:(NSManagedObjectContext *)moc | ||
{ | ||
return [moc objectWithID:self.objectID]; | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// NSMutableArray+S2MReverse.h | ||
// MoreMobile | ||
// | ||
// Created by Andreas Buff on 26/06/14. | ||
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface NSMutableArray (S2MReverse) | ||
|
||
|
||
/** | ||
* Inverts the order of the contained elements. | ||
|
||
From: http://stackoverflow.com/questions/586370/how-can-i-reverse-a-nsarray-in-objective-c | ||
|
||
Example: | ||
Before: 12345 | ||
After: 54321 | ||
|
||
*/ | ||
- (void)reverse; | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// NSMutableArray+S2MReverse.m | ||
// MoreMobile | ||
// | ||
// Created by Andreas Buff on 26/06/14. | ||
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved. | ||
// | ||
|
||
#import "NSMutableArray+S2MReverse.h" | ||
|
||
@implementation NSMutableArray (S2MReverse) | ||
|
||
- (void)reverse | ||
{ | ||
if ([self count] == 0) { | ||
return; | ||
} | ||
NSUInteger i = 0; | ||
NSUInteger j = [self count] - 1; | ||
while (i < j) { | ||
[self exchangeObjectAtIndex:i | ||
withObjectAtIndex:j]; | ||
i++; | ||
j--; | ||
} | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// UIDevice+S2MAdditions.h | ||
// MoreMobile | ||
// | ||
// Created by Andreas Buff on 03/06/14. | ||
// Copyright (c) 2014 SinnerSchrader Mobile. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface UIDevice (S2MAdditions) | ||
|
||
/** | ||
* Returns the battery charge level for the device. | ||
Battery level ranges from 0.0 to 1.0 (100% charged). | ||
* | ||
* @return battery level | ||
*/ | ||
+ (float)s2m_batteryState; | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NSYearCalendarUnit, NSMonthCalendarUnit, NSDayCalendarUnit are deprecated. Let's use new NSCalender.. enums instead