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
// Generates alpha-numeric-random string | |
- (NSString *)genRandStringLength:(int)len { | |
static NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | |
NSMutableString *randomString = [NSMutableString stringWithCapacity: len]; | |
for (int i=0; i<len; i++) { | |
[randomString appendFormat: @"%C", [letters characterAtIndex: arc4random() % [letters length]]]; | |
} | |
return randomString; | |
} |
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
// get the IP address of current-device | |
- (NSString *)getIPAddress { | |
NSString *address = @"error"; | |
struct ifaddrs *interfaces = NULL; | |
struct ifaddrs *temp_addr = NULL; | |
int success = 0; | |
// retrieve the current interfaces - returns 0 on success | |
success = getifaddrs(&interfaces); | |
if (success == 0) { | |
// Loop through linked list of interfaces |
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
- (NSString*)current_DateTimeStamp { | |
NSTimeInterval interval = [[NSDate date] timeIntervalSince1970]; | |
NSNumber *number = [NSNumber numberWithDouble:interval]; | |
return [number stringValue]; | |
} |
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
- (NSDate*)twoMonthspastDate { | |
NSCalendar *cal = [NSCalendar currentCalendar]; | |
NSDate *now = [NSDate date]; | |
NSDateComponents *comp = [cal components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:now]; | |
comp.timeZone=[NSTimeZone defaultTimeZone]; | |
comp.month = comp.month-2; | |
comp.year = comp.year; | |
comp.day = 1; | |
[comp setHour:0]; | |
[comp setMinute:0]; |
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
- (NSDate*) currentDate_midnightTime { | |
NSCalendar *cal = [NSCalendar currentCalendar]; | |
NSDate *now = [NSDate date]; | |
NSDateComponents *comp = [cal components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:now]; | |
comp.timeZone=[NSTimeZone defaultTimeZone]; | |
comp.month = comp.month; | |
comp.year = comp.year; | |
comp.day = comp.day; | |
[comp setHour:0]; | |
[comp setMinute:0]; |
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
// add 23:59:59 hours to - (assume today is 30-Jul-2013) example range yesterday = 29-Jul-2013 12:00:00 AM + "to" + 30-Jul-2013 23:59:59 PM | |
- (NSDate*)add24HoursToDate:(NSDate*)date { | |
NSCalendar *cal = [NSCalendar currentCalendar]; | |
NSDateComponents *comp = [cal components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:date]; | |
comp.timeZone=[NSTimeZone defaultTimeZone]; | |
comp.month = comp.month; | |
comp.year = comp.year; | |
comp.day = comp.day; | |
[comp setHour:23]; | |
[comp setMinute:59]; |
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
- (NSDate*)remove24HoursToDate:(NSDate*)date { | |
NSCalendar *cal = [NSCalendar currentCalendar]; | |
NSDateComponents *comp = [cal components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:date]; | |
comp.timeZone=[NSTimeZone defaultTimeZone]; | |
comp.month = comp.month; | |
comp.year = comp.year; | |
comp.day = comp.day; | |
[comp setHour:0]; | |
[comp setMinute:0]; | |
[comp setSecond:0]; |
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
-(NSDate *)firstDateForLastMonth { | |
NSCalendar *cal = [NSCalendar currentCalendar]; | |
NSDate *now = [NSDate date]; | |
NSDateComponents *comp = [cal components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:now]; | |
comp.timeZone=[NSTimeZone defaultTimeZone]; | |
comp.month = comp.month-1; | |
comp.year = comp.year; | |
comp.day = 1; | |
[comp setHour:0]; | |
[comp setMinute:0]; |
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
-(NSDate *)yesterday { | |
NSCalendar *cal = [NSCalendar currentCalendar]; | |
NSDate *now = [NSDate date]; | |
NSDateComponents *comp = [cal components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:now]; | |
comp.timeZone=[NSTimeZone defaultTimeZone]; | |
comp.month = comp.month; | |
comp.year = comp.year; | |
comp.day = comp.day-1; | |
[comp setHour:0]; | |
[comp setMinute:0]; |
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
- (NSDate *)lastWeek { | |
NSCalendar *cal = [NSCalendar currentCalendar]; | |
NSDate *now = [NSDate date]; | |
NSDateComponents *comp = [cal components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:now]; | |
comp.timeZone=[NSTimeZone defaultTimeZone]; | |
comp.month = comp.month; | |
comp.year = comp.year; | |
comp.day = comp.day-7; | |
[comp setHour:0]; | |
[comp setMinute:0]; |
OlderNewer