FLEXIvarEditorViewController.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // FLEXIvarEditorViewController.m
  3. // Flipboard
  4. //
  5. // Created by Ryan Olson on 5/23/14.
  6. // Copyright (c) 2014 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXIvarEditorViewController.h"
  9. #import "FLEXFieldEditorView.h"
  10. #import "FLEXRuntimeUtility.h"
  11. #import "FLEXArgumentInputView.h"
  12. @interface FLEXIvarEditorViewController ()
  13. @property (nonatomic, assign) Ivar ivar;
  14. @end
  15. @implementation FLEXIvarEditorViewController
  16. - (id)initWithTarget:(id)target ivar:(Ivar)ivar
  17. {
  18. self = [super initWithTarget:target];
  19. if (self) {
  20. self.ivar = ivar;
  21. self.title = @"Instance Variable";
  22. }
  23. return self;
  24. }
  25. - (void)viewDidLoad
  26. {
  27. [super viewDidLoad];
  28. self.fieldEditorView.fieldDescription = [FLEXRuntimeUtility prettyNameForIvar:self.ivar];
  29. [self updateTextFieldString];
  30. // Use the numeric keyboard for primitives and the letter keyboard for strings
  31. NSString *typeEncoding = @(ivar_getTypeEncoding(self.ivar));
  32. if ([typeEncoding isEqual:[[self class] stringTypeEncoding]]) {
  33. self.firstInputView.keyboardType = UIKeyboardTypeAlphabet;
  34. } else {
  35. self.firstInputView.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
  36. }
  37. }
  38. - (void)actionButtonPressed:(id)sender
  39. {
  40. [super actionButtonPressed:sender];
  41. [self updatePropertyFromString:self.firstInputView.inputText];
  42. [self updateTextFieldString];
  43. }
  44. - (void)updateTextFieldString
  45. {
  46. id ivarValue = [FLEXRuntimeUtility valueForIvar:self.ivar onObject:self.target];
  47. self.firstInputView.inputText = [FLEXRuntimeUtility editiableDescriptionForObject:ivarValue];
  48. }
  49. - (void)updatePropertyFromString:(NSString *)string
  50. {
  51. [FLEXRuntimeUtility setIvar:self.ivar onObject:self.target withInputString:self.firstInputView.inputText];
  52. }
  53. + (BOOL)canEditIvar:(Ivar)ivar currentValue:(id)value
  54. {
  55. return [self canEditType:@(ivar_getTypeEncoding(ivar)) currentObjectValue:value];
  56. }
  57. @end