diff --git a/WordPress/Classes/Services/BlogService.m b/WordPress/Classes/Services/BlogService.m index 8b487978cb32..b2fa70746ff6 100644 --- a/WordPress/Classes/Services/BlogService.m +++ b/WordPress/Classes/Services/BlogService.m @@ -56,6 +56,15 @@ - (void)syncBlog:(Blog *)blog success:(void (^)(void))success failure:(void (^)(NSError *error))failure { + if (!blog) { + // Reuse an existing error type. This branch is an edge case and no caller inspects the error. + NSError *error = [NSError errorWithDomain:WordPressComRestApiErrorDomain + code:WordPressComRestApiErrorCodeInvalidInput + userInfo:@{NSDebugDescriptionErrorKey: @"Cannot sync a nil blog"}]; + failure(error); + return; + } + if ([blog supports:BlogFeatureWpComRESTAPI]) { id remote = [self remoteForBlog:blog]; if ([remote isKindOfClass:[BlogServiceRemoteREST class]]) { diff --git a/WordPress/Classes/ViewRelated/Stats/StatsViewController.h b/WordPress/Classes/ViewRelated/Stats/StatsViewController.h index 833593145927..7871c554749c 100644 --- a/WordPress/Classes/ViewRelated/Stats/StatsViewController.h +++ b/WordPress/Classes/ViewRelated/Stats/StatsViewController.h @@ -4,7 +4,7 @@ @interface StatsViewController : UIViewController -@property (nonatomic, weak, nullable) Blog *blog; +@property (nonatomic, strong, nullable) Blog *blog; @property (nonatomic, copy, nullable) void (^dismissBlock)(void); @end diff --git a/WordPress/Classes/ViewRelated/Stats/StatsViewController.swift b/WordPress/Classes/ViewRelated/Stats/StatsViewController.swift index d9920058fac5..989153f8f160 100644 --- a/WordPress/Classes/ViewRelated/Stats/StatsViewController.swift +++ b/WordPress/Classes/ViewRelated/Stats/StatsViewController.swift @@ -1,7 +1,14 @@ +import WordPressShared + extension StatsViewController { @objc public func showJetpackConnectionView(completion: @escaping () -> Void) { - let controller = UIViewController.jetpackConnection(blog: self.blog!) + // `blog` should be non-nil now that the property is strongly held. Report a + // non-fatal (don't call `completion()` — it re-enters initStats and loops). + guard let blog = self.blog else { + return wpAssertionFailure("showJetpackConnectionView called with a nil blog") + } + let controller = UIViewController.jetpackConnection(blog: blog) controller.completionBlock = { [weak controller] in guard let controller else { return } controller.view?.removeFromSuperview()