regex - Refactor out explicit getters and setters in Objective C -
i refactoring objective-c code remove explicit getters , setters.
so this:
[instance member] [instance setmember:value]
should become this:
instance.member instance.member = value
currently working on regex this, if has solved already, i'd appreciate taking advantage of else's work.
to have [instance setmember:value];
calls translated instance.member = value;
, use xcode's refactoring: edit > refactor > convert modern objective-c syntax. convert getters if applicable, variable = [instance member];
calls variable = instance.member;
syntax.
i might misunderstanding intention, i'd point out use of instance.member;
bad style if you're not assigning value variable. if you're calling method because of it's side-effects, use [instance method];
instead make intention more clear. use dot-syntax read , write properties avoid confusion.
xcode 6.3 warns if you've got method/property returning value , you're calling getter without assigning variable (like viewcontroller.view;
or [viewcontroller view];
) since it's assumed call mistake. rid of warning you're getting, need explicitly tell compiler doing side-effect (for example, make sure xib loaded) casting void
, in (void)[viewcontroller view];
.
to convert setters refactoring missed, you'll need convert hand, i'm afraid. find them, go find navigator (cmd-3), select find > regular expression. use regular expression \[\[\w+\s+\w+\]\s+set
(unfortunately, can't convert calls using regular expression since need transform 1 character: [foo setbar:123]
needs turned foo.bar = 123
means b
need turned lower-case b
). write service context menu necessary transformation (see top answer "sort lines in selection" xcode 4 on how write such service) speed manual task bit.
Comments
Post a Comment