iPhone iOS 4 addTimeInterval deprecated

The method has been renamed to -dateByAddingTimeInterval:. localNotif.fireDate = [now dateByAddingTimeInterval:timeInterval]; In Swift 2.2: localNotif.fireDate = now.dateByAddingTimeInterval(timeInterval) In Swift 3: localNotif.fireDate = now.addingTimeInterval(timeInterval) // or simply localNotif.fireDate = now + timeInterval

Can’t pass Date to NSPredicate(format: …) without “as CVarArg”

The %@ format expect a Foundation object as argument, compare “Predicate Format String Syntax” in the “Predicate Programming Guide”. Therefore you have to cast the overlay type Date back to its Foundation counterpart NSDate: let endDate = Date() let pred = NSPredicate(format: “endDate == %@”, endDate as NSDate)

Get current iPhone device timezone date and time from UTC-5 timezone date and time iPhone app?

I have tested your scenario and added some code for your reference. Please test the below and please let me know it is useful for you. NSString *dateStr = @”2012-07-16 07:33:01″; NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init]; [dateFormatter1 setDateFormat:@”yyyy-MM-dd HH:mm:ss”]; NSDate *date = [dateFormatter1 dateFromString:dateStr]; NSLog(@”date : %@”,date); NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone]; NSTimeZone *utcTimeZone … Read more

How to compare two NSDate objects in objective C

Here’s an example using the NSDate method, compare: if([startDate compare: endDate] == NSOrderedDescending) // if start is later in time than end { // do something } From the class reference: If… The receiver and anotherDate are exactly equal to each other, NSOrderedSame. The receiver is later in time than anotherDate, NSOrderedDescending. The receiver is … Read more

How do I get weekday and/or name of month from a NSDate variable?

There is no need to manually convert to the Swedish words. iPhone will do it for you. Try this: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.dateFormat = @”yyyyMMdd”; NSDate *date = [dateFormatter dateFromString:@”20111010″]; // set swedish locale dateFormatter.locale=[[NSLocale alloc] initWithLocaleIdentifier:@”sv_SE”]; dateFormatter.dateFormat=@”MMMM”; NSString *monthString = [[dateFormatter stringFromDate:date] capitalizedString]; NSLog(@”month: %@”, monthString); dateFormatter.dateFormat=@”EEEE”; NSString *dayString = [[dateFormatter … Read more

NSString to NSDate

You can’t invent format string syntax and expect it to work; you need to actually use a documented format. (Seriously, “MM” meaning “month”, “minute” and “GMT offset minutes” all at the same time?) As the documentation points out, the 10.4 formatters use Unicode format strings. Try “yyyy-MM-dd HH:mm:ss ZZZ” instead. Also, Objective-C source is ASCII. … Read more

Swift 3: Date vs NSDate?

Swift 3 introduced some new overlay value types for existing Foundation class types, such as Date for NSDate, Data for NSData and some more. The full list and details can be found in SE-0069 Mutability and Foundation Value Types Some of the reasons were Provide proper value semantics, let and var instead of mutable and … Read more