Ross Kimes Ross Kimes - 1 year ago 155
iOS Question

Drag and Drop into a `UICollectionView` placeholder in iOS 11 Beta 4

The API for dragging and dropping into a

changed in iOS 11 Beta 4. In beta 1-3, the code looked like:

let placeholderContext = coordinator.drop(
toPlaceholderInsertedAt: indexPath,
withReuseIdentifier: "reuseID",
cellUpdateHandler: { _ in }

In beta 4, the introduced
. My code is

let placeholder = UICollectionViewDropPlaceholder(
insertionIndexPath: indexPath,
reuseIdentifier: "reuseID"

let placeholderContext = coordinator.drop(item.dragItem, to: placeholder)

I am getting this compile error:

Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_UICollectionViewDropPlaceholder", referenced from:
objc-class-ref in StickerLibraryViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
note: symbol(s) not found for architecture arm64
error: linker command failed with exit code 1 (use -v to see invocation)

Other than not using a placeholder until beta 5, anyone have any ideas of how to get this working in beta 4?


Answer Source

Until this is fixed in Beta 5, I ended up solving this issue by dropping down into the Objective-C runtime.

In the Obj-C header…


@interface RKNFactory : NSObject

- (UICollectionViewDropPlaceholder*)placeholderForIndexPath:(NSIndexPath*)indexPath resuseIdentifier:(NSString*)reuseIdentifier;



In the implementation…

@import ObjectiveC.runtime;

@implementation RKNFactory

- (UICollectionViewDropPlaceholder*)placeholderForIndexPath:(NSIndexPath*)indexPath resuseIdentifier:(NSString*)reuseIdentifier {

    SEL initSelector = NSSelectorFromString(@"initWithInsertionIndexPath:reuseIdentifier:");
    Class placeholderClass = NSClassFromString(@"UICollectionViewDropPlaceholder");
    return [[placeholderClass alloc] performSelector:initSelector  withObject:indexPath withObject:reuseIdentifier];


And then from the Swift code…

return RKNFactory().placeholder(for: indexPath, resuseIdentifier: reuseIdentifier)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download