You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.8 KiB

  1. //
  2. // FLEXArgumentInputNumberView.m
  3. // Flipboard
  4. //
  5. // Created by Ryan Olson on 6/15/14.
  6. // Copyright (c) 2014 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXArgumentInputNumberView.h"
  9. #import "FLEXRuntimeUtility.h"
  10. @implementation FLEXArgumentInputNumberView
  11. - (instancetype)initWithArgumentTypeEncoding:(const char *)typeEncoding
  12. {
  13. self = [super initWithArgumentTypeEncoding:typeEncoding];
  14. if (self) {
  15. self.inputTextView.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
  16. self.targetSize = FLEXArgumentInputViewSizeSmall;
  17. }
  18. return self;
  19. }
  20. - (void)setInputValue:(id)inputValue
  21. {
  22. if ([inputValue respondsToSelector:@selector(stringValue)]) {
  23. self.inputTextView.text = [inputValue stringValue];
  24. }
  25. }
  26. - (id)inputValue
  27. {
  28. return [FLEXRuntimeUtility valueForNumberWithObjCType:self.typeEncoding.UTF8String fromInputString:self.inputTextView.text];
  29. }
  30. + (BOOL)supportsObjCType:(const char *)type withCurrentValue:(id)value
  31. {
  32. static NSArray<NSString *> *primitiveTypes = nil;
  33. static dispatch_once_t onceToken;
  34. dispatch_once(&onceToken, ^{
  35. primitiveTypes = @[@(@encode(char)),
  36. @(@encode(int)),
  37. @(@encode(short)),
  38. @(@encode(long)),
  39. @(@encode(long long)),
  40. @(@encode(unsigned char)),
  41. @(@encode(unsigned int)),
  42. @(@encode(unsigned short)),
  43. @(@encode(unsigned long)),
  44. @(@encode(unsigned long long)),
  45. @(@encode(float)),
  46. @(@encode(double)),
  47. @(@encode(long double))];
  48. });
  49. return type && [primitiveTypes containsObject:@(type)];
  50. }
  51. @end