3

The problem is simple. I have a Swift class that subclasses an Objective-C class:

class CJGADSearchBannerView: GADSearchBannerView {
    ...
}

Then I initialize my class as:

let searchBanner = CJGADSearchBannerView(adSize: kGADAdSizeFluid)

The inherited Objective-C class comes from the GoogleMobileAdsSDK pod.

It all compiles fine and I can trace the initializer back to its original class in the code:

@interface GADSearchBannerView : GADBannerView

Then:

GAD_SUBCLASSING_RESTRICTED
@interface GADBannerView : UIView

#pragma mark Initialization

/// Initializes and returns a banner view with the specified ad size and origin relative to the
/// banner's superview.
- (instancetype)initWithAdSize:(GADAdSize)adSize origin:(CGPoint)origin;

/// Initializes and returns a banner view with the specified ad size placed at its superview's
/// origin.
- (instancetype)initWithAdSize:(GADAdSize)adSize;

But at runtime I get:

-[CJGADSearchBannerView initWithAdSize:]: unrecognized selector sent to instance 0x7f87cbe88710

It used to work, then at some point I built in Xcode 10 and it just broke.

I tried adding @ObjcMembers to the new class in case it was an inference issue, I tried deleting DerivedData in case it was linking to old code, I deleted Pods and ran pod install again, I tried switching between Swift 3 and Swift 4, I tried building in Xcode 9.4 and Xcode 10, but nothing worked.

ratsimihah
  • 1,010
  • 1
  • 11
  • 22
  • I think `GAD_SUBCLASSING_RESTRICTED` is the problem, its a macro that restricts subclassing, although I am not sure how it works – Aris Oct 23 '18 at 11:33
  • It does: `#define GAD_SUBCLASSING_RESTRICTED __attribute__((objc_subclassing_restricted))`. I'd say this is a no go. – Alper Oct 23 '18 at 12:13
  • Maybe you could achieve the same with a `category` – Kamil.S Nov 29 '18 at 12:59
  • That's weird, it used to work and then broke out of nowhere. I don't see why GAD_SUBCLASSING_RESTRICTED would've changed. – ratsimihah Jan 15 '19 at 16:33

0 Answers0