Cocoa – Trim all leading whitespace from NSString

This creates an NSString category to do what you need. With this, you can call NSString *newString = [mystring stringByTrimmingLeadingWhitespace]; to get a copy minus leading whitespace. (Code is untested, may require some minor debugging.) @interface NSString (trimLeadingWhitespace) -(NSString*)stringByTrimmingLeadingWhitespace; @end @implementation NSString (trimLeadingWhitespace) -(NSString*)stringByTrimmingLeadingWhitespace { NSInteger i = 0; while ((i < [self length]) && … Read more

How do you make the Application window open when the dock icon is clicked?

Implement – (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag in your app delegate. Check the documentation for the details of the return value. Document based apps and non-document based apps behave slightly differently. If there are no open windows when the dock icon of a document based app is clicked then it will create a new document. If there … Read more

How can i convert NSBezierPath to CGPath

Right from Apple documentation: Creating a CGPathRef From an NSBezierPath Object Here is the relevant code. @implementation NSBezierPath (BezierPathQuartzUtilities) // This method works only in OS X v10.2 and later. – (CGPathRef)quartzPath { int i, numElements; // Need to begin a path here. CGPathRef immutablePath = NULL; // Then draw the path elements. numElements = … Read more

What’s the difference between a CoreAnimation Layer Backed View and a Layer Hosting View?

A layer backed view contains Cocoa or Cocoa Touch UI controls and can be animated using the animator proxy. Layer backed views allow you to animate your UI and help to reduce the overhead of drawing by caching the views contents on a core animation layer. Create a Layer backed view by setting the wants … Read more

How to use NSDecimalNumber?

Do NOT use NSNumber‘s +numberWith… methods to create NSDecimalNumber objects. They are declared to return NSNumber objects and are not guaranteed to function as NSDecimalNumber instances. This is explained in this thread by Bill Bumgarner, a developer at Apple. I would encourage you to file a bug against this behavior, referencing bug rdar://6487304. As an … Read more

Implementing a 30 day time trial [closed]

This issue comes up repeatedly on the cocoa-dev mailing list and the consensus answer is always do the simplest thing possible. Determined hackers will break all but the most over-engineered solution. And they’re unlikely to pay for the software anyways. Go for the 80/20 solution: the easy solution that gets 80% effect for 20% effort. … Read more

Xcode 6 iOS Creating a Cocoa Touch Framework – Architectures issues

Based on all the responses, the post on raywenderlich.com and the gist created by Chris Conway I came up with this. Executing the following steps I was able to build a Cocoa Touch framework (including Swift and Objective-C files) that contains all architectures for both simulator and device: Create a new (Aggregate) target in your … Read more

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