How dangerous is it to compare floating point values?

First of all, floating point values are not “random” in their behavior. Exact comparison can and does make sense in plenty of real-world usages. But if you’re going to use floating point you need to be aware of how it works. Erring on the side of assuming floating point works like real numbers will get … Read more

How to print out the method name and line number and conditionally disable NSLog?

Here are some useful macros around NSLog I use a lot: #ifdef DEBUG # define DLog(fmt, …) NSLog((@”%s [Line %d] ” fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) #else # define DLog(…) #endif // ALog always displays output regardless of the DEBUG setting #define ALog(fmt, …) NSLog((@”%s [Line %d] ” fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) The DLog macro is … Read more

How do I set up NSZombieEnabled in Xcode 4?

In Xcode 4.x press ⌥⌘R (or click Menubar > Product > Scheme > Edit Scheme) select the “Diagnostics” tab and click “Enable Zombie Objects”: This turns released objects into NSZombie instances that print console warnings when used again. This is a debugging aid that increases memory use (no object is really released) but improves error … Read more

What is the difference between class and instance methods?

Like most of the other answers have said, instance methods use an instance of a class, whereas a class method can be used with just the class name. In Objective-C they are defined thusly: @interface MyClass : NSObject + (void)aClassMethod; – (void)anInstanceMethod; @end They could then be used like so: [MyClass aClassMethod]; MyClass *object = … Read more

How do I iterate over an NSArray?

The generally-preferred code for 10.5+/iOS. for (id object in array) { // do something with object } This construct is used to enumerate objects in a collection which conforms to the NSFastEnumeration protocol. This approach has a speed advantage because it stores pointers to several objects (obtained via a single method call) in a buffer … Read more

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