Don't call [UIDevice currentDevice] in +load

Summary: sysctl should be faster.

Reviewed By: timonus

Differential Revision: D13981833

fbshipit-source-id: ae7a67d4eb69595441a4a66e0ef0a271762f77ce
This commit is contained in:
Scott Wolchok 2019-02-08 13:36:43 -08:00 committed by Facebook Github Bot
parent 46a124ddfe
commit 035808e750
4 changed files with 28 additions and 2 deletions

View file

@ -10,6 +10,7 @@
#import <IGListKit/IGListAssert.h>
#import <IGListKit/IGListAdapterUpdater.h>
#import <IGListKit/IGListSupplementaryViewSource.h>
#import <IGListKit/IGSystemVersion.h>
#import "IGListSectionControllerInternal.h"
#import "IGListDebugger.h"
@ -26,7 +27,7 @@
- (void)dealloc {
// on iOS 9 setting the dataSource has side effects that can invalidate the layout and seg fault
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 9.0) {
if (!IGSystemVersionIsIOS9OrNewer()) {
// properties are assign for <iOS 9
_collectionView.dataSource = nil;
_collectionView.delegate = nil;

View file

@ -0,0 +1,8 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
bool IGSystemVersionIsIOS9OrNewer(void);

View file

@ -0,0 +1,16 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "IGSystemVersion.h"
bool IGSystemVersionIsIOS9OrNewer(void) {
if (@available(iOS 9.0, *)) {
return true;
} else {
return false;
}
}

View file

@ -11,6 +11,7 @@
#import <IGListKit/IGListAdapterInternal.h>
#import <IGListKit/IGListAssert.h>
#import <IGListKit/IGListSectionController.h>
#import <IGListKit/IGSystemVersion.h>
#import <objc/runtime.h>
@ -23,7 +24,7 @@ static void * kIGListAdapterKey = &kIGListAdapterKey;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// interactive reordering does not exist prior to iOS 9
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 9.0) {
if (!IGSystemVersionIsIOS9OrNewer()) {
return;
}