Get current NSDate in timestamp format

Here’s what I use: NSString * timestamp = [NSString stringWithFormat:@”%f”,[[NSDate date] timeIntervalSince1970] * 1000]; (times 1000 for milliseconds, otherwise, take that out) If You’re using it all the time, it might be nice to declare a macro #define TimeStamp [NSString stringWithFormat:@”%f”,[[NSDate date] timeIntervalSince1970] * 1000] Then Call it like this: NSString * timestamp = TimeStamp; … Read more

Are “EXC_BREAKPOINT (SIGTRAP)” exceptions caused by debugging breakpoints?

Are “EXC_BREAKPOINT (SIGTRAP)” exceptions caused by debugging breakpoints? No. Other way around, actually: A SIGTRAP (trace trap) will cause the debugger to break (interrupt) your program, the same way an actual breakpoint would. But that’s because the debugger always breaks on a crash, and a SIGTRAP (like several other signals) is one type of crash. … Read more

Get App Name in Swift

This should work: NSBundle.mainBundle().infoDictionary![“CFBundleName”] as! String infoDictionary is declared as a var infoDictionary: [NSObject : AnyObject]! so you have to unwrap it, access it as a Swift dictionary (rather than use objectForKey), and, as the result is an AnyObject, cast it. Update Swift 3 (Xcode 8 beta 2) Always better to use constants (and optionals) … Read more

Formatting NSDate into particular styles for both year, month, day, and hour, minute, seconds

this is what i used: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@”yyyy-MM-dd”]; NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init]; [timeFormat setDateFormat:@”HH:mm:ss”]; NSDate *now = [[NSDate alloc] init]; NSString *theDate = [dateFormat stringFromDate:now]; NSString *theTime = [timeFormat stringFromDate:now]; NSLog(@”\n” “theDate: |%@| \n” “theTime: |%@| \n” , theDate, theTime); [dateFormat release]; [timeFormat release]; [now release];

How to convert CFStringRef to NSString?

NSString and CFStringRef are “Toll free bridged”, meaning that you can simply typecast between them. For example: CFStringRef aCFString = (CFStringRef)aNSString; works perfectly and transparently. Likewise: NSString *aNSString = (NSString *)aCFString; The previous syntax was for MRC. If you’re using ARC, the new casting syntax is as follows: NSString *aNSString = (__bridge NSString *)aCFString; works … Read more

What’s the optimum way of storing an NSDate in NSUserDefaults?

You are needlessly complicating things. Why are you converting the date to a time interval (then the time interval to a different primitive)? Just [sharedDefaults setObject:theDate forKey:@”theDateKey”] and be done with it. NSDate is one of the “main types” supported by the PLIST format (dates, numbers, strings, data, dictionaries, and arrays), so you can just … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)