Easily Bind an NSProgress Object to an NSProgressIndicator in Objective-C [Open Source]

In UIKit UIProgressView has an observedProgress property. If you set the observedProgress property on a UIProgressView, it will automatically update its appearance when you make changes to the NSProgress object. On macOS (in AppKit at least) NSProgressIndicator does not have an equivalent API. I created a simple category on NSProgressIndicator that adds an observedProgress property on NSProgressIndicator. The source code is available on Github here.

Adding Force Touch Features to macOS Apps with a Custom Gesture Recognizer [Open Source]

I created a simple subclass of NSGestureRecognizer, ATForceTouchGesture, to simplify the process of adding Force Touch features to macOS apps. You can use this gesture recognizer to add a feature like force clicking to start editing a label (see the screenshot below).

Image captures 'force click' to edit using ATForceTouchGesture.

There is a sample project available on Github here.

Exporting NSTableView to HTML [Open Source]

I needed to export the contents of a NSTableView to HTML, so I wrote a little NSTableView subclass in Objective-C to do this.

ATHyperTextTableView is a simple NSTableView subclass that makes exporting a table view to HTML easy. You can customize the look of the exported HTML table with your own CSS too.

Screenshots Below:
Screenshot of NSTableView.
Screenshot of exported HTML from a the tableView, loaded into a WebView.
Screenshot of the exported HTML loaded into a WebView.

Screenshot of exported HTML from a the tableView, loaded into a WebView with custom CSS set.
Screenshot of the exported HTML loaded into a WebView, styled with custom CSS.

There is a sample project available on Github here.

Mac Tutorial: How To Enable an App Extension

Starting with OS X 10.10 (Yosemite), Mac applications can include embedded app extensions. App extensions add custom functionality to your Mac. How you can use an app extension depends on what kind of extension it is.

At the time of this writing, there are four different kinds of app extensions available on the Mac:

Action: Action extensions can manipulate content in another supporting app. Action extensions often work in text editing applications like Text Edit.

Finder: Finder extensions add functionality to the Finder.

Share Menu: Share extensions allow you to share content with other

Today: These are widgets that can be added to the Today view in the Notification Center.

While there are several different kinds of app extensions available, every app extensions requires the user to enable them in System Preferences before they can be used. If you recently purchased an app and cannot figure out why you are unable to use a feature advertised in the app description, there is a chance that the feature you are looking for requires you to enable an app extension.

How to Enable an App Extension

To enable an app extension, open the System Preferences app on your Mac. In the System Preferences window, click on “Extensions.”

Screenshot of System Preferences on OS X El Capitan annotated instructions 'Go to extensions pane.'

Once you are in the “Extensions” section of System Preferences, you will see a list of all the app extensions you have on your Mac. To enable or disable an app extension, simply check or uncheck the box next to each extension in the list. That’s all there is to it.

App extensions pane in System Preferences on Mac.

How to Disable NSScrollView Scrolling

Unlike UIScrollView on iOS, NSScrollView on Mac does not have a handy scrollEnabled property for you to set to NO if you need to temporarily disable scrolling in your app.

If you Google around, you can find several posts on websites like stackoverflow that ask questions like How can I disable the vertical scrolling of a NSScrollView? Some have suggested setting the hasVerticalScroller property to NO as the answer. However, the hasVerticalScroller property only effects the visibility of the scroller, a value of NO does not actually prevent scrolling.

There are also ways to constrain scrolling from an NSView subclass, as described in Apple’s documentation here. Constraining scrolling from a view subclass can be useful, but what if you want to just temporarily disable scrolling?

The easiest way to disable scrolling it seems is to subclass NSScrollView and add a BOOL property with a name like scrollingEnabled. Then you can simply override the designated initializers (initWithFrame: and initWithCoder:) and set the ivar of the property to YES as the default value:

-(instancetype)initWithFrame:(NSRect)frameRect 
{ 
   self = [super initWithFrame:frameRect]; 
   if (self) 
   { 
       [self setUpOnInit]; 
   } 
   return self; 
}
 
- (instancetype)initWithCoder:(NSCoder *)coder 
{ 
    self = [super initWithCoder:coder]; 
    if (self) 
    { 
         [self setUpOnInit]; 
    } 
    return self; 
}
 
-(void)setUpOnInit
{
   //Set all default values. 
   _scrollingEnabled = YES; 
}

Now you can just override the scrollWheel: method and check the property:

-(void)scrollWheel:(NSEvent *)theEvent 
{ 
    if (self.scrollingEnabled) {  
      [super scrollWheel:theEvent];  
     } 
    else {  
       //scrolling is disabled. 
    } 
}

This technique will work in most cases, but there may be times when a view inside of a scroll view implements autoscrolling behavior (perhaps if the view is a dragging destination). If you need to temporarily disable scrolling in such a case, you should also subclass NSClipView and block scrolling by overriding the -constrainBoundsRect: method like this:

-(NSRect)constrainBoundsRect:(NSRect)proposedBounds
{
    MyScrollViewSubclass *mainScrollView = (MyScrollViewSubclass*)self.superview;
 
    if (mainScrollView.scrollingEnabled)
    {
        return [super constrainBoundsRect:proposedBounds];
    }
    else
    {
        //Disabled
        return self.documentVisibleRect;
    }
}

Tutorial: How to Redeem a Promo Code for a Free Download on the Mac App Store

Sometimes, Mac developers are kind enough to give promo codes out so people can download a copy of their paid applications for free. A promo code is simply a combination of characters you can use on the Mac App Store to get the app for free, but how do you use them? It’s easy. First, open up the Mac App Store application. After the window has finished loading, you will see to your right a link that says Redeem. Click it.

Screenshot of the Mac App Store  window, annotated  with an arrow pointing to the 'redeem link'.

After you click the link a sheet will pop up asking you to log in with your Apple ID to redeem your code, so go ahead and log in!

Mac App Store screenshot of login sheet.

After you log in, you will be brought to a screen with a title that says “Redeem Code”. At the bottom, you will see a text field where you can enter your redeem code. Enter it and the application will start downloading! That’s it!

Mac App Store screenshot of the "Redeem Code"  window.