LookinDisplayItem.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. //
  2. // LookinDisplayItem.m
  3. // qmuidemo
  4. //
  5. // Created by Li Kai on 2018/11/15.
  6. // Copyright © 2018 QMUI Team. All rights reserved.
  7. //
  8. #import "LookinDisplayItem.h"
  9. #import "LookinAttributesGroup.h"
  10. #import "LookinAttributesSection.h"
  11. #import "LookinAttribute.h"
  12. #import "LookinEventHandler.h"
  13. #import "LookinIvarTrace.h"
  14. #import "NSArray+Lookin.h"
  15. #import "NSObject+Lookin.h"
  16. #if TARGET_OS_IPHONE
  17. #import "UIColor+LookinServer.h"
  18. #import "UIImage+LookinServer.h"
  19. #elif TARGET_OS_MAC
  20. #ifdef DEBUG
  21. #import "LKEfficiencyMonitor.h"
  22. #endif
  23. #endif
  24. @interface LookinDisplayItem ()
  25. @property(nonatomic, assign, readwrite) CGRect frameToRoot;
  26. @property(nonatomic, assign, readwrite) BOOL inNoPreviewHierarchy;
  27. @property(nonatomic, assign) NSInteger indentLevel;
  28. @property(nonatomic, assign, readwrite) BOOL isExpandable;
  29. @property(nonatomic, assign, readwrite) BOOL inHiddenHierarchy;
  30. @property(nonatomic, assign, readwrite) BOOL displayingInHierarchy;
  31. @end
  32. @implementation LookinDisplayItem
  33. #pragma mark - <NSCopying>
  34. - (id)copyWithZone:(NSZone *)zone {
  35. LookinDisplayItem *newDisplayItem = [[LookinDisplayItem allocWithZone:zone] init];
  36. newDisplayItem.subitems = [self.subitems lookin_map:^id(NSUInteger idx, LookinDisplayItem *value) {
  37. return value.copy;
  38. }];
  39. newDisplayItem.isHidden = self.isHidden;
  40. newDisplayItem.alpha = self.alpha;
  41. newDisplayItem.frame = self.frame;
  42. newDisplayItem.bounds = self.bounds;
  43. newDisplayItem.soloScreenshot = self.soloScreenshot;
  44. newDisplayItem.groupScreenshot = self.groupScreenshot;
  45. newDisplayItem.viewObject = self.viewObject.copy;
  46. newDisplayItem.layerObject = self.layerObject.copy;
  47. newDisplayItem.hostViewControllerObject = self.hostViewControllerObject.copy;
  48. newDisplayItem.attributesGroupList = [self.attributesGroupList lookin_map:^id(NSUInteger idx, LookinAttributesGroup *value) {
  49. return value.copy;
  50. }];
  51. newDisplayItem.eventHandlers = [self.eventHandlers lookin_map:^id(NSUInteger idx, LookinEventHandler *value) {
  52. return value.copy;
  53. }];
  54. newDisplayItem.representedAsKeyWindow = self.representedAsKeyWindow;
  55. [newDisplayItem _updateDisplayingInHierarchyProperty];
  56. return newDisplayItem;
  57. }
  58. #pragma mark - <NSCoding>
  59. - (void)encodeWithCoder:(NSCoder *)aCoder {
  60. [aCoder encodeObject:self.subitems forKey:@"subitems"];
  61. [aCoder encodeBool:self.isHidden forKey:@"hidden"];
  62. [aCoder encodeFloat:self.alpha forKey:@"alpha"];
  63. [aCoder encodeObject:self.viewObject forKey:@"viewObject"];
  64. [aCoder encodeObject:self.layerObject forKey:@"layerObject"];
  65. [aCoder encodeObject:self.hostViewControllerObject forKey:@"hostViewControllerObject"];
  66. [aCoder encodeObject:self.attributesGroupList forKey:@"attributesGroupList"];
  67. [aCoder encodeBool:self.representedAsKeyWindow forKey:@"representedAsKeyWindow"];
  68. [aCoder encodeObject:self.eventHandlers forKey:@"eventHandlers"];
  69. if (self.screenshotEncodeType == LookinDisplayItemImageEncodeTypeNSData) {
  70. [aCoder encodeObject:[self.soloScreenshot lookin_encodedObjectWithType:LookinCodingValueTypeImage] forKey:@"soloScreenshot"];
  71. [aCoder encodeObject:[self.groupScreenshot lookin_encodedObjectWithType:LookinCodingValueTypeImage] forKey:@"groupScreenshot"];
  72. } else if (self.screenshotEncodeType == LookinDisplayItemImageEncodeTypeImage) {
  73. [aCoder encodeObject:self.soloScreenshot forKey:@"soloScreenshot"];
  74. [aCoder encodeObject:self.groupScreenshot forKey:@"groupScreenshot"];
  75. }
  76. #if TARGET_OS_IPHONE
  77. [aCoder encodeCGRect:self.frame forKey:@"frame"];
  78. [aCoder encodeCGRect:self.bounds forKey:@"bounds"];
  79. [aCoder encodeObject:self.backgroundColor.lks_rgbaComponents forKey:@"backgroundColor"];
  80. #elif TARGET_OS_MAC
  81. [aCoder encodeRect:self.frame forKey:@"frame"];
  82. [aCoder encodeRect:self.bounds forKey:@"bounds"];
  83. [aCoder encodeObject:self.backgroundColor.lk_rgbaComponents forKey:@"backgroundColor"];
  84. #endif
  85. }
  86. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  87. if (self = [super init]) {
  88. self.subitems = [aDecoder decodeObjectForKey:@"subitems"];
  89. self.isHidden = [aDecoder decodeBoolForKey:@"hidden"];
  90. self.alpha = [aDecoder decodeFloatForKey:@"alpha"];
  91. self.viewObject = [aDecoder decodeObjectForKey:@"viewObject"];
  92. self.layerObject = [aDecoder decodeObjectForKey:@"layerObject"];
  93. self.hostViewControllerObject = [aDecoder decodeObjectForKey:@"hostViewControllerObject"];
  94. self.attributesGroupList = [aDecoder decodeObjectForKey:@"attributesGroupList"];
  95. self.representedAsKeyWindow = [aDecoder decodeBoolForKey:@"representedAsKeyWindow"];
  96. id soloScreenshotObj = [aDecoder decodeObjectForKey:@"soloScreenshot"];
  97. if (soloScreenshotObj) {
  98. if ([soloScreenshotObj isKindOfClass:[NSData class]]) {
  99. self.soloScreenshot = [soloScreenshotObj lookin_decodedObjectWithType:LookinCodingValueTypeImage];
  100. } else if ([soloScreenshotObj isKindOfClass:[LookinImage class]]) {
  101. self.soloScreenshot = soloScreenshotObj;
  102. } else {
  103. NSAssert(NO, @"");
  104. }
  105. }
  106. id groupScreenshotObj = [aDecoder decodeObjectForKey:@"groupScreenshot"];
  107. if (groupScreenshotObj) {
  108. if ([groupScreenshotObj isKindOfClass:[NSData class]]) {
  109. self.groupScreenshot = [groupScreenshotObj lookin_decodedObjectWithType:LookinCodingValueTypeImage];
  110. } else if ([groupScreenshotObj isKindOfClass:[LookinImage class]]) {
  111. self.groupScreenshot = groupScreenshotObj;
  112. } else {
  113. NSAssert(NO, @"");
  114. }
  115. }
  116. self.eventHandlers = [aDecoder decodeObjectForKey:@"eventHandlers"];
  117. #if TARGET_OS_IPHONE
  118. self.frame = [aDecoder decodeCGRectForKey:@"frame"];
  119. self.bounds = [aDecoder decodeCGRectForKey:@"bounds"];
  120. self.backgroundColor = [UIColor lks_colorFromRGBAComponents:[aDecoder decodeObjectForKey:@"backgroundColor"]];
  121. #elif TARGET_OS_MAC
  122. self.frame = [aDecoder decodeRectForKey:@"frame"];
  123. self.bounds = [aDecoder decodeRectForKey:@"bounds"];
  124. self.backgroundColor = [NSColor lk_colorFromRGBAComponents:[aDecoder decodeObjectForKey:@"backgroundColor"]];
  125. #ifdef DEBUG
  126. [[LKEfficiencyMonitor sharedInstance] displayItemDidInit];
  127. #endif
  128. #endif
  129. [self _updateDisplayingInHierarchyProperty];
  130. }
  131. return self;
  132. }
  133. + (BOOL)supportsSecureCoding {
  134. return YES;
  135. }
  136. - (instancetype)init {
  137. if (self = [super init]) {
  138. /// 在手机端,displayItem 被创建时会调用这个方法
  139. [self _updateDisplayingInHierarchyProperty];
  140. #ifdef DEBUG
  141. #if TARGET_OS_IPHONE
  142. #elif TARGET_OS_MAC
  143. [[LKEfficiencyMonitor sharedInstance] displayItemDidInit];
  144. #endif
  145. #endif
  146. }
  147. return self;
  148. }
  149. - (LookinObject *)displayingObject {
  150. return self.viewObject ? : self.layerObject;
  151. }
  152. - (void)setAttributesGroupList:(NSSet<LookinAttributesGroup *> *)attributesGroupList {
  153. _attributesGroupList = [attributesGroupList copy];
  154. [attributesGroupList enumerateObjectsUsingBlock:^(LookinAttributesGroup * _Nonnull group, BOOL * _Nonnull stop) {
  155. [group.attrSections enumerateObjectsUsingBlock:^(LookinAttributesSection * _Nonnull section, NSUInteger idx, BOOL * _Nonnull stop) {
  156. [section.attributes enumerateObjectsUsingBlock:^(LookinAttribute * _Nonnull attr, NSUInteger idx, BOOL * _Nonnull stop) {
  157. attr.targetDisplayItem = self;
  158. }];
  159. }];
  160. }];
  161. }
  162. - (BOOL)representedForSystemClass {
  163. return [self.title hasPrefix:@"UI"] || [self.title hasPrefix:@"CA"] || [self.title hasPrefix:@"_"];
  164. }
  165. - (BOOL)itemIsKindOfClassWithName:(NSString *)className {
  166. if (!className) {
  167. NSAssert(NO, @"");
  168. return NO;
  169. }
  170. return [self itemIsKindOfClassesWithNames:[NSSet setWithObject:className]];
  171. }
  172. - (BOOL)itemIsKindOfClassesWithNames:(NSSet<NSString *> *)targetClassNames {
  173. if (!targetClassNames.count) {
  174. return NO;
  175. }
  176. LookinObject *selfObj = self.viewObject ? : self.layerObject;
  177. if (!selfObj) {
  178. return NO;
  179. }
  180. __block BOOL boolValue = NO;
  181. [targetClassNames enumerateObjectsUsingBlock:^(NSString * _Nonnull targetClassName, BOOL * _Nonnull stop_outer) {
  182. [selfObj.classChainList enumerateObjectsUsingBlock:^(NSString * _Nonnull selfClass, NSUInteger idx, BOOL * _Nonnull stop_inner) {
  183. NSString *nonPrefixSelfClass = [selfClass componentsSeparatedByString:@"."].lastObject;
  184. if ([nonPrefixSelfClass isEqualToString:targetClassName]) {
  185. boolValue = YES;
  186. *stop_inner = YES;
  187. }
  188. }];
  189. if (boolValue) {
  190. *stop_outer = YES;
  191. }
  192. }];
  193. return boolValue;
  194. }
  195. - (void)setSubitems:(NSArray<LookinDisplayItem *> *)subitems {
  196. [_subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  197. obj.superItem = nil;
  198. }];
  199. _subitems = subitems;
  200. self.isExpandable = (subitems.count > 0);
  201. [subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  202. NSAssert(!obj.superItem, @"");
  203. obj.superItem = self;
  204. [obj _updateInHiddenHierarchyProperty];
  205. [obj _updateDisplayingInHierarchyProperty];
  206. [obj _updateFrameToRoot];
  207. }];
  208. }
  209. - (void)setIsExpandable:(BOOL)isExpandable {
  210. if (_isExpandable == isExpandable) {
  211. return;
  212. }
  213. _isExpandable = isExpandable;
  214. [self _notifyDelegatesWith:LookinDisplayItemProperty_IsExpandable];
  215. }
  216. - (void)setIsExpanded:(BOOL)isExpanded {
  217. if (_isExpanded == isExpanded) {
  218. return;
  219. }
  220. _isExpanded = isExpanded;
  221. [self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  222. [obj _updateDisplayingInHierarchyProperty];
  223. }];
  224. [self _notifyDelegatesWith:LookinDisplayItemProperty_IsExpanded];
  225. }
  226. - (void)setSoloScreenshot:(LookinImage *)soloScreenshot {
  227. if (_soloScreenshot == soloScreenshot) {
  228. return;
  229. }
  230. _soloScreenshot = soloScreenshot;
  231. [self _notifyDelegatesWith:LookinDisplayItemProperty_SoloScreenshot];
  232. }
  233. - (void)setIsSelected:(BOOL)isSelected {
  234. if (_isSelected == isSelected) {
  235. return;
  236. }
  237. _isSelected = isSelected;
  238. [self _notifyDelegatesWith:LookinDisplayItemProperty_IsSelected];
  239. }
  240. - (void)setAvoidSyncScreenshot:(BOOL)avoidSyncScreenshot {
  241. if (_avoidSyncScreenshot == avoidSyncScreenshot) {
  242. return;
  243. }
  244. _avoidSyncScreenshot = avoidSyncScreenshot;
  245. [self _notifyDelegatesWith:LookinDisplayItemProperty_AvoidSyncScreenshot];
  246. }
  247. - (void)setIsHovered:(BOOL)isHovered {
  248. if (_isHovered == isHovered) {
  249. return;
  250. }
  251. _isHovered = isHovered;
  252. [self _notifyDelegatesWith:LookinDisplayItemProperty_IsHovered];
  253. }
  254. - (void)setGroupScreenshot:(LookinImage *)groupScreenshot {
  255. if (_groupScreenshot == groupScreenshot) {
  256. return;
  257. }
  258. _groupScreenshot = groupScreenshot;
  259. [self _notifyDelegatesWith:LookinDisplayItemProperty_GroupScreenshot];
  260. }
  261. - (void)setDisplayingInHierarchy:(BOOL)displayingInHierarchy {
  262. if (_displayingInHierarchy == displayingInHierarchy) {
  263. return;
  264. }
  265. _displayingInHierarchy = displayingInHierarchy;
  266. [self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  267. [obj _updateDisplayingInHierarchyProperty];
  268. }];
  269. [self _notifyDelegatesWith:LookinDisplayItemProperty_DisplayingInHierarchy];
  270. }
  271. - (void)_updateDisplayingInHierarchyProperty {
  272. if (self.superItem && (!self.superItem.displayingInHierarchy || !self.superItem.isExpanded)) {
  273. self.displayingInHierarchy = NO;
  274. } else {
  275. self.displayingInHierarchy = YES;
  276. }
  277. }
  278. - (void)setIsHidden:(BOOL)isHidden {
  279. _isHidden = isHidden;
  280. [self _updateInHiddenHierarchyProperty];
  281. }
  282. - (void)setAlpha:(float)alpha {
  283. _alpha = alpha;
  284. [self _updateInHiddenHierarchyProperty];
  285. }
  286. - (void)setInHiddenHierarchy:(BOOL)inHiddenHierarchy {
  287. if (_inHiddenHierarchy == inHiddenHierarchy) {
  288. return;
  289. }
  290. _inHiddenHierarchy = inHiddenHierarchy;
  291. [self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  292. [obj _updateInHiddenHierarchyProperty];
  293. }];
  294. [self _notifyDelegatesWith:LookinDisplayItemProperty_InHiddenHierarchy];
  295. }
  296. - (void)_updateInHiddenHierarchyProperty {
  297. if (self.superItem.inHiddenHierarchy || self.isHidden || self.alpha <= 0) {
  298. self.inHiddenHierarchy = YES;
  299. } else {
  300. self.inHiddenHierarchy = NO;
  301. }
  302. }
  303. - (void)enumerateSelfAndAncestors:(void (^)(LookinDisplayItem *, BOOL *))block {
  304. if (!block) {
  305. return;
  306. }
  307. LookinDisplayItem *item = self;
  308. while (item) {
  309. BOOL shouldStop = NO;
  310. block(item, &shouldStop);
  311. if (shouldStop) {
  312. break;
  313. }
  314. item = item.superItem;
  315. }
  316. }
  317. - (void)enumerateAncestors:(void (^)(LookinDisplayItem *, BOOL *))block {
  318. [self.superItem enumerateSelfAndAncestors:block];
  319. }
  320. - (void)enumerateSelfAndChildren:(void (^)(LookinDisplayItem *item))block {
  321. if (!block) {
  322. return;
  323. }
  324. block(self);
  325. [self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull subitem, NSUInteger idx, BOOL * _Nonnull stop) {
  326. [subitem enumerateSelfAndChildren:block];
  327. }];
  328. }
  329. + (NSArray<LookinDisplayItem *> *)flatItemsFromHierarchicalItems:(NSArray<LookinDisplayItem *> *)items {
  330. NSMutableArray *resultArray = [NSMutableArray array];
  331. [items enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  332. if (obj.superItem) {
  333. obj.indentLevel = obj.superItem.indentLevel + 1;
  334. }
  335. [resultArray addObject:obj];
  336. if (obj.subitems.count) {
  337. [resultArray addObjectsFromArray:[self flatItemsFromHierarchicalItems:obj.subitems]];
  338. }
  339. }];
  340. return resultArray;
  341. }
  342. - (NSString *)description {
  343. return [NSString stringWithFormat:@"%@", self.title];
  344. }
  345. - (void)setFrameToRoot:(CGRect)frameToRoot {
  346. if (CGRectEqualToRect(_frameToRoot, frameToRoot)) {
  347. return;
  348. }
  349. _frameToRoot = frameToRoot;
  350. [(NSArray<LookinDisplayItem *> *)self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  351. [obj _updateFrameToRoot];
  352. [obj _updateInNoPreviewHierarchy];
  353. }];
  354. [self _notifyDelegatesWith:LookinDisplayItemProperty_FrameToRoot];
  355. }
  356. - (void)setPreviewItemDelegate:(id<LookinDisplayItemDelegate>)previewItemDelegate {
  357. _previewItemDelegate = previewItemDelegate;
  358. if (![previewItemDelegate respondsToSelector:@selector(displayItem:propertyDidChange:)]) {
  359. NSAssert(NO, @"");
  360. _previewItemDelegate = nil;
  361. return;
  362. }
  363. [self.previewItemDelegate displayItem:self propertyDidChange:LookinDisplayItemProperty_None];
  364. }
  365. - (void)setRowViewDelegate:(id<LookinDisplayItemDelegate>)rowViewDelegate {
  366. if (_rowViewDelegate == rowViewDelegate) {
  367. return;
  368. }
  369. _rowViewDelegate = rowViewDelegate;
  370. if (![rowViewDelegate respondsToSelector:@selector(displayItem:propertyDidChange:)]) {
  371. NSAssert(NO, @"");
  372. _rowViewDelegate = nil;
  373. return;
  374. }
  375. [self.rowViewDelegate displayItem:self propertyDidChange:LookinDisplayItemProperty_None];
  376. }
  377. - (void)setFrame:(CGRect)frame {
  378. _frame = frame;
  379. [self _updateFrameToRoot];
  380. }
  381. - (void)setBounds:(CGRect)bounds {
  382. _bounds = bounds;
  383. [(NSArray<LookinDisplayItem *> *)self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  384. [obj _updateFrameToRoot];
  385. }];
  386. }
  387. - (void)_updateFrameToRoot {
  388. if (!self.superItem) {
  389. self.frameToRoot = self.frame;
  390. return;
  391. }
  392. CGRect superFrameToRoot = self.superItem.frameToRoot;
  393. CGRect superBounds = self.superItem.bounds;
  394. CGRect selfFrame = self.frame;
  395. CGFloat x = selfFrame.origin.x - superBounds.origin.x + superFrameToRoot.origin.x;
  396. CGFloat y = selfFrame.origin.y - superBounds.origin.y + superFrameToRoot.origin.y;
  397. CGFloat width = selfFrame.size.width;
  398. CGFloat height = selfFrame.size.height;
  399. self.frameToRoot = CGRectMake(x, y, width, height);
  400. }
  401. - (void)setInNoPreviewHierarchy:(BOOL)inNoPreviewHierarchy {
  402. if (_inNoPreviewHierarchy == inNoPreviewHierarchy) {
  403. return;
  404. }
  405. _inNoPreviewHierarchy = inNoPreviewHierarchy;
  406. [self.subitems enumerateObjectsUsingBlock:^(LookinDisplayItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  407. [obj _updateInNoPreviewHierarchy];
  408. }];
  409. [self _notifyDelegatesWith:LookinDisplayItemProperty_InNoPreviewHierarchy];
  410. }
  411. - (void)setNoPreview:(BOOL)noPreview {
  412. _noPreview = noPreview;
  413. [self _updateInNoPreviewHierarchy];
  414. }
  415. - (void)_updateInNoPreviewHierarchy {
  416. if (self.superItem.inNoPreviewHierarchy || self.noPreview) {
  417. self.inNoPreviewHierarchy = YES;
  418. } else {
  419. self.inNoPreviewHierarchy = NO;
  420. }
  421. }
  422. - (LookinImage *)appropriateScreenshot {
  423. if (self.isExpandable && self.isExpanded) {
  424. return self.soloScreenshot;
  425. }
  426. return self.groupScreenshot;
  427. }
  428. - (void)_notifyDelegatesWith:(LookinDisplayItemProperty)property {
  429. [self.previewItemDelegate displayItem:self propertyDidChange:property];
  430. [self.rowViewDelegate displayItem:self propertyDidChange:property];
  431. }
  432. - (BOOL)isMatchedWithSearchString:(NSString *)string {
  433. if (string.length == 0) {
  434. NSAssert(NO, @"");
  435. return NO;
  436. }
  437. if ([self.title.lowercaseString containsString:string.lowercaseString]) {
  438. return YES;
  439. }
  440. if ([self.subtitle.lowercaseString containsString:string.lowercaseString]) {
  441. return YES;
  442. }
  443. return NO;
  444. }
  445. - (void)setIsInSearch:(BOOL)isInSearch {
  446. _isInSearch = isInSearch;
  447. [self _notifyDelegatesWith:LookinDisplayItemProperty_IsInSearch];
  448. }
  449. - (void)setHighlightedSearchString:(NSString *)highlightedSearchString {
  450. _highlightedSearchString = highlightedSearchString;
  451. [self _notifyDelegatesWith:LookinDisplayItemProperty_HighlightedSearchString];
  452. }
  453. - (void)setHostViewControllerObject:(LookinObject *)hostViewControllerObject {
  454. _hostViewControllerObject = hostViewControllerObject;
  455. [self _updateSubtitleProperty];
  456. }
  457. - (void)setViewObject:(LookinObject *)viewObject {
  458. _viewObject = viewObject;
  459. [self _updateSubtitleProperty];
  460. [self _updateTitleProperty];
  461. }
  462. - (void)setLayerObject:(LookinObject *)layerObject {
  463. _layerObject = layerObject;
  464. [self _updateSubtitleProperty];
  465. [self _updateTitleProperty];
  466. }
  467. - (void)_updateTitleProperty {
  468. if (self.viewObject) {
  469. _title = self.viewObject.shortSelfClassName;
  470. } else if (self.layerObject) {
  471. _title = self.layerObject.shortSelfClassName;
  472. } else {
  473. _title = nil;
  474. }
  475. }
  476. - (void)_updateSubtitleProperty {
  477. NSString *subtitle = @"";
  478. if (self.hostViewControllerObject.shortSelfClassName.length) {
  479. subtitle = [NSString stringWithFormat:@"%@.view", self.hostViewControllerObject.shortSelfClassName];
  480. } else {
  481. LookinObject *representedObject = self.viewObject ? : self.layerObject;
  482. if (representedObject.specialTrace.length) {
  483. subtitle = representedObject.specialTrace;
  484. } else if (representedObject.ivarTraces.count) {
  485. NSArray<NSString *> *ivarNameList = [representedObject.ivarTraces lookin_map:^id(NSUInteger idx, LookinIvarTrace *value) {
  486. return value.ivarName;
  487. }];
  488. subtitle = [[[NSSet setWithArray:ivarNameList] allObjects] componentsJoinedByString:@" "];
  489. }
  490. }
  491. _subtitle = subtitle;
  492. }
  493. - (void)dealloc {
  494. #if TARGET_OS_IPHONE
  495. #elif TARGET_OS_MAC
  496. #ifdef DEBUG
  497. [[LKEfficiencyMonitor sharedInstance] displayItemDidDealloc];
  498. #endif
  499. #endif
  500. }
  501. @end