Our DNA is written in Swift

DTFoundation 1.4.2

The update was necessary because I had forgotten to add DTSidePanelController to any static library. Without that you could only compile it directly into your app, instead of being able to link in the lib and use it from there.

When I added it to the iOS Static Library and Static Framework targets I found out that I had already coded the delegate to use weak references. The general deployment target (minimum OS version) is still iOS 4.3 which did not support zeroing weak references.

So I also added zeroing weak references support in DTFoundation, via DTWeakSupport.h.



  • ADDED: DTWeakSupport.h for tagging variables and properties to use weak refs if supported
  • FIXED: [DTSidePanel] classes missing from static library target
  • CHANGED: Implemented conditional weak support in DTSidePanelController, DTActionSheet, DTAlertView, DTSmartPagingScrollView, DTHTMLParser, DTASN1Parser

When researching how to best do that I found an article on Touch Code Magazine and also Nick Lockwood’s ARC Helper. Those inspired my general approach, though I prefer to have preprocessor macros which you can clearly distinguish from other language elements.

Nick requires OS X 10.8 for allowing weak on Mac, since before this version several key AppKit classes would not like if you made weak references to them. According to the release notes, “Starting in 10.8, instances of NSWindow, NSWindowController, and NSViewController can be pointed to by ARC weak references.”

I don’t have not encountered any situation yet where this would have posed a problem and so I opted to go with the simpler  #ifdefs.

The weak support header checks if the current deployment target supports weak and defines to preprocessor macros to use: DT_WEAK_VARIABLE for use with variables (e.g. instance variables backing a delegate) and DT_WEAK_PROPERTY for use in property definitions. For example:

// definition of a property
@property (nonatomic, DT_WEAK_PROPERTY) id sidePanelDelegate;
// the ivar backing that
DT_WEAK_VARIABLE id  _sidePanelDelegate;

You’ll be seeing these also in all my other projects where we still have a iOS 4.3 or OS X 10.6 deployment target. Next up to get this is DTCoreText.

The new version is tagged on the master branch on GitHub and also available via CocoaPods.

Tagged as:

Categories: Updates