NSArray+HWDUtil.m 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Tencent is pleased to support the open source community by making vap available.
  2. //
  3. // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
  4. //
  5. // Licensed under the MIT License (the "License"); you may not use this file except in
  6. // compliance with the License. You may obtain a copy of the License at
  7. //
  8. // http://opensource.org/licenses/MIT
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed under the License is
  11. // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  12. // either express or implied. See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "NSArray+HWDUtil.h"
  15. @implementation NSArray (HWDUtil)
  16. - (CGRect)hwd_rectValue {
  17. if (self.count < 4) {
  18. return CGRectZero;
  19. }
  20. for (int i = 0; i < self.count; i++) {
  21. id value = self[i];
  22. if (i >= 4) {
  23. break ;
  24. }
  25. if (![value isKindOfClass:[NSString class]] && ![value isKindOfClass:[NSNumber class]]) {
  26. return CGRectZero;
  27. }
  28. }
  29. return CGRectMake([self[0] floatValue], [self[1] floatValue], [self[2] floatValue], [self[3] floatValue]);
  30. }
  31. @end