Skip to content

Commit

Permalink
Allow IGListKit to be used without -ObjC
Browse files Browse the repository at this point in the history
The `-ObjC` linker flag is used to work around a mismatch between how Mach-O
files are linked, and how the Objective-C runtime operates.

With this change, IGListKit can be used without require the `-ObjC` linker flag.

Related, see: "What causes those exceptions?" in https://developer.apple.com/library/content/qa/qa1490/_index.html
  • Loading branch information
Dave Lee committed Oct 5, 2017
1 parent 0f04a07 commit 53ab2a3
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Source/Common/IGListMacros.h
Expand Up @@ -7,6 +7,8 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#include <os/base.h>

#ifndef IGLK_SUBCLASSING_RESTRICTED
#if defined(__has_attribute) && __has_attribute(objc_subclassing_restricted)
#define IGLK_SUBCLASSING_RESTRICTED __attribute__((objc_subclassing_restricted))
Expand All @@ -19,6 +21,18 @@
#define IGLK_UNAVAILABLE(message) __attribute__((unavailable(message)))
#endif // #ifndef IGLK_UNAVAILABLE

// IGLK_LINKABLE and IGLK_LINK_REQUIRE macros allow categories to be used without requiring -ObjC.

// Annotate category @implementation definitions with this macro.
#define IGLK_LINKABLE(NAME) \
const char IGLKLinkable_ ## NAME = 'L';

// Annotate category @interface declarations with this macro.
#define IGLK_LINK_REQUIRE(NAME) \
extern const char IGLKLinkable_ ## NAME; \
extern const void *const OS_WEAK IGLKLink_ ## NAME; \
const void *const OS_WEAK IGLKLink_ ## NAME = &IGLKLinkable_ ## NAME;

#if IGLK_LOGGING_ENABLED
#define IGLKLog( s, ... ) do { NSLog( @"IGListKit: %@", [NSString stringWithFormat: (s), ##__VA_ARGS__] ); } while(0)
#else
Expand Down
2 changes: 2 additions & 0 deletions Source/Common/NSNumber+IGListDiffable.h
Expand Up @@ -10,10 +10,12 @@
#import <Foundation/Foundation.h>

#import <IGListKit/IGListDiffable.h>
#import <IGListKit/IGListMacros.h>

/**
This category provides default `IGListDiffable` conformance for `NSNumber`.
*/
IGLK_LINK_REQUIRE(NSNumber_IGListDiffable)
@interface NSNumber (IGListDiffable) <IGListDiffable>

@end
1 change: 1 addition & 0 deletions Source/Common/NSNumber+IGListDiffable.m
Expand Up @@ -9,6 +9,7 @@

#import "NSNumber+IGListDiffable.h"

IGLK_LINKABLE(NSNumber_IGListDiffable)
@implementation NSNumber (IGListDiffable)

- (id<NSObject>)diffIdentifier {
Expand Down
2 changes: 2 additions & 0 deletions Source/Common/NSString+IGListDiffable.h
Expand Up @@ -10,10 +10,12 @@
#import <Foundation/Foundation.h>

#import <IGListKit/IGListDiffable.h>
#import <IGListKit/IGListMacros.h>

/**
This category provides default `IGListDiffable` conformance for `NSString`.
*/
IGLK_LINK_REQUIRE(NSString_IGListDiffable)
@interface NSString (IGListDiffable) <IGListDiffable>

@end
1 change: 1 addition & 0 deletions Source/Common/NSString+IGListDiffable.m
Expand Up @@ -9,6 +9,7 @@

#import "NSString+IGListDiffable.h"

IGLK_LINKABLE(NSString_IGListDiffable)
@implementation NSString (IGListDiffable)

- (id<NSObject>)diffIdentifier {
Expand Down
2 changes: 2 additions & 0 deletions Source/Internal/IGListAdapter+DebugDescription.h
Expand Up @@ -8,7 +8,9 @@
*/

#import <IGListKit/IGListKit.h>
#import <IGListKit/IGListMacros.h>

IGLK_LINK_REQUIRE(IGListAdapter_DebugDescription)
@interface IGListAdapter (DebugDescription)

- (NSArray<NSString *> *)debugDescriptionLines;
Expand Down
1 change: 1 addition & 0 deletions Source/Internal/IGListAdapter+DebugDescription.m
Expand Up @@ -15,6 +15,7 @@
#import "UICollectionView+DebugDescription.h"
#import "IGListDebuggingUtilities.h"

IGLK_LINKABLE(IGListAdapter_DebugDescription)
@implementation IGListAdapter (DebugDescription)

- (NSString *)debugDescription {
Expand Down
2 changes: 2 additions & 0 deletions Source/Internal/IGListAdapter+UICollectionView.h
Expand Up @@ -10,7 +10,9 @@
#import <UIKit/UIKit.h>

#import <IGListKit/IGListAdapter.h>
#import <IGListKit/IGListMacros.h>

IGLK_LINK_REQUIRE(IGListAdapter_UICollectionView)
@interface IGListAdapter (UICollectionView)
<
UICollectionViewDataSource,
Expand Down
1 change: 1 addition & 0 deletions Source/Internal/IGListAdapter+UICollectionView.m
Expand Up @@ -13,6 +13,7 @@
#import <IGListKit/IGListAssert.h>
#import <IGListKit/IGListSectionController.h>

IGLK_LINKABLE(IGListAdapter_UICollectionView)
@implementation IGListAdapter (UICollectionView)

#pragma mark - UICollectionViewDataSource
Expand Down
2 changes: 2 additions & 0 deletions Source/Internal/IGListAdapterUpdater+DebugDescription.h
Expand Up @@ -8,7 +8,9 @@
*/

#import <IGListKit/IGListKit.h>
#import <IGListKit/IGListMacros.h>

IGLK_LINK_REQUIRE(IGListAdapterUpdater_DebugDescription)
@interface IGListAdapterUpdater (DebugDescription)

- (NSArray<NSString *> *)debugDescriptionLines;
Expand Down
1 change: 1 addition & 0 deletions Source/Internal/IGListAdapterUpdater+DebugDescription.m
Expand Up @@ -24,6 +24,7 @@
}
#endif // #if IGLK_DEBUG_DESCRIPTION_ENABLED

IGLK_LINKABLE(IGListAdapterUpdater_DebugDescription)
@implementation IGListAdapterUpdater (DebugDescription)

- (NSArray<NSString *> *)debugDescriptionLines {
Expand Down
2 changes: 2 additions & 0 deletions Source/Internal/IGListBatchUpdateData+DebugDescription.h
Expand Up @@ -8,7 +8,9 @@
*/

#import <IGListKit/IGListKit.h>
#import <IGListKit/IGListMacros.h>

IGLK_LINK_REQUIRE(IGListBatchUpdateData_DebugDescription)
@interface IGListBatchUpdateData (DebugDescription)

- (NSArray<NSString *> *)debugDescriptionLines;
Expand Down
1 change: 1 addition & 0 deletions Source/Internal/IGListBatchUpdateData+DebugDescription.m
Expand Up @@ -9,6 +9,7 @@

#import "IGListBatchUpdateData+DebugDescription.h"

IGLK_LINKABLE(IGListBatchUpdateData_DebugDescription)
@implementation IGListBatchUpdateData (DebugDescription)

- (NSArray<NSString *> *)debugDescriptionLines {
Expand Down
Expand Up @@ -8,7 +8,9 @@
*/

#import <IGListKit/IGListKit.h>
#import <IGListKit/IGListMacros.h>

IGLK_LINK_REQUIRE(IGListBindingSectionController_DebugDescription)
@interface IGListBindingSectionController (DebugDescription)

- (NSArray<NSString *> *)debugDescriptionLines;
Expand Down
Expand Up @@ -11,6 +11,7 @@

#import "IGListDebuggingUtilities.h"

IGLK_LINKABLE(IGListBindingSectionController_DebugDescription)
@implementation IGListBindingSectionController (DebugDescription)

- (NSString *)debugDescription {
Expand Down
2 changes: 2 additions & 0 deletions Source/Internal/IGListSectionMap+DebugDescription.h
Expand Up @@ -9,8 +9,10 @@

#import <Foundation/Foundation.h>

#import <IGListKit/IGListMacros.h>
#import "IGListSectionMap.h"

IGLK_LINK_REQUIRE(IGListSectionMap_DebugDescription)
@interface IGListSectionMap (DebugDescription)

- (NSArray<NSString *> *)debugDescriptionLines;
Expand Down
1 change: 1 addition & 0 deletions Source/Internal/IGListSectionMap+DebugDescription.m
Expand Up @@ -10,6 +10,7 @@
#import "IGListSectionMap+DebugDescription.h"
#import "IGListBindingSectionController.h"

IGLK_LINKABLE(IGListSectionMap_DebugDescription)
@implementation IGListSectionMap (DebugDescription)

- (NSArray<NSString *> *)debugDescriptionLines {
Expand Down
3 changes: 3 additions & 0 deletions Source/Internal/UICollectionView+DebugDescription.h
Expand Up @@ -9,6 +9,9 @@

#import <UIKit/UIKit.h>

#import <IGListKit/IGListMacros.h>

IGLK_LINK_REQUIRE(UICollectionView_DebugDescription)
@interface UICollectionView (DebugDescription)

- (NSArray<NSString *> *)debugDescriptionLines;
Expand Down
1 change: 1 addition & 0 deletions Source/Internal/UICollectionView+DebugDescription.m
Expand Up @@ -11,6 +11,7 @@

#import <IGListKit/IGListMacros.h>

IGLK_LINKABLE(UICollectionView_DebugDescription)
@implementation UICollectionView (DebugDescription)

- (NSArray<NSString *> *)debugDescriptionLines {
Expand Down
3 changes: 3 additions & 0 deletions Source/Internal/UICollectionView+IGListBatchUpdateData.h
Expand Up @@ -9,8 +9,11 @@

#import <UIKit/UIKit.h>

#import <IGListKit/IGListMacros.h>

@class IGListBatchUpdateData;

IGLK_LINK_REQUIRE(UICollectionView_IGListBatchUpdateData)
@interface UICollectionView (IGListBatchUpdateData)

- (void)ig_applyBatchUpdateData:(IGListBatchUpdateData *)updateData;
Expand Down
1 change: 1 addition & 0 deletions Source/Internal/UICollectionView+IGListBatchUpdateData.m
Expand Up @@ -11,6 +11,7 @@

#import "IGListBatchUpdateData.h"

IGLK_LINKABLE(UICollectionView_IGListBatchUpdateData)
@implementation UICollectionView (IGListBatchUpdateData)

- (void)ig_applyBatchUpdateData:(IGListBatchUpdateData *)updateData {
Expand Down

0 comments on commit 53ab2a3

Please sign in to comment.