How do I add 1 day to an NSDate?

Swift 5.0 : var dayComponent = DateComponents() dayComponent.day = 1 // For removing one day (yesterday): -1 let theCalendar = Calendar.current let nextDate = theCalendar.date(byAdding: dayComponent, to: Date()) print(“nextDate : \(nextDate)”) Objective C : NSDateComponents *dayComponent = [[NSDateComponents alloc] init]; dayComponent.day = 1; NSCalendar *theCalendar = [NSCalendar currentCalendar]; NSDate *nextDate = [theCalendar dateByAddingComponents:dayComponent toDate:[NSDate date] … Read more

How can I reverse a NSArray in Objective-C?

There is a much easier solution, if you take advantage of the built-in reverseObjectEnumerator method on NSArray, and the allObjects method of NSEnumerator: NSArray* reversedArray = [[startArray reverseObjectEnumerator] allObjects]; allObjects is documented as returning an array with the objects that have not yet been traversed with nextObject, in order: This array contains all the remaining … Read more

“sending ‘const NSString *’ to parameter of type ‘NSString *’ discards qualifiers” warning

You should declare your constant string as follows: NSString * const kSomeConstantString = @””; // constant pointer instead of: const NSString * kSomeConstantString = @””; // pointer to constant // equivalent to NSString const * kSomeConstantString = @””; The former is a constant pointer to an NSString object, while the latter is a pointer to … Read more

How to write iOS app purely in C

Damn, it took me a while but I got it: main.c: #include <CoreFoundation/CoreFoundation.h> #include <objc/runtime.h> #include <objc/message.h> // This is a hack. Because we are writing in C, we cannot out and include // <UIKit/UIKit.h>, as that uses Objective-C constructs. // however, neither can we give the full function declaration, like this: // int UIApplicationMain … Read more

How to sort a NSArray alphabetically?

The simplest approach is, to provide a sort selector (Apple’s documentation for details) Objective-C sortedArray = [anArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; Swift let descriptor: NSSortDescriptor = NSSortDescriptor(key: “YourKey”, ascending: true, selector: “localizedCaseInsensitiveCompare:”) let sortedResults: NSArray = temparray.sortedArrayUsingDescriptors([descriptor]) Apple provides several selectors for alphabetic sorting: compare: caseInsensitiveCompare: localizedCompare: localizedCaseInsensitiveCompare: localizedStandardCompare: Swift var students = [“Kofi”, “Abena”, “Peter”, “Kweku”, “Akosua”] … Read more

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