ios - using pointer to set property rather than sending object message -


here sample scenario:

you have view controller "itemsviewcontroller" lists "items" in uitableview. set in navigation controller let change title of uinavigationitem title property. going through book remain nameless accesses property 2 ways on same page , i'm not sure why;

using pointer

uinavigationitem *n = [self navigationitem]; [n settitle: @"title"];

sending object message directly

[[self navigationitem] settitle:[item itemname]]; 

i understand how both of these work (correct me if i'm wrong) pointer points navigationitem , when change property changes in navigationitem

otherwise send navigationitem settitle message updated string.

my real question why 1 way vs other way in situation? there time 1 of these ways has advantage?

when second, compiler generates hidden temporary variable. in first case define temporary variable compiler.

it's best break "daisy chained" operations down sequential temp assignments (on separate lines, please!) make sequence clearer , make easier debug.

with operations broken apart (and on separate lines!) becomes easy set breakpoints, examine intermediate results, etc. , there no "downside" in terms of performance.

(it justified place multiple statements on same line, , there many reasons not that.)


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -