Slide 1

Slide 1 text

Lifebit  iOS   WTF  just  happened.  And  some  9ps.  

Slide 2

Slide 2 text

KUSANAGI  

Slide 3

Slide 3 text

AFNetworking  2.0   •  AFHTTPRequestOpera9onManager   – requestSerializer   – responseSerializer   •  AFNetworkReachabilityManager   •  AFNetworkAc9vityIndicatorManager  

Slide 4

Slide 4 text

Kusanagi  -­‐  KSAPI   •  BDBOAuth1RequestOpera9onManager   – requestSerializer   •  KSRequestOpera9onManager   –  HTTPRequestOpera9onWithRequest:success:failure   –  POSTJSON   •  AFNetworking  handles  401s  differently   –     

Slide 5

Slide 5 text

Mantle   •  Parsing  of  JSON  responses  and  conver9ng   them  to  MTLModel   •  Saving  of  MTLModel  to  CoreData   •  MTLModel  <-­‐-­‐-­‐-­‐>  NSManagedObject   •  We  work  with  MTLModel,  not  with   NSManagedObject  

Slide 6

Slide 6 text

Y  U  NO  USE  NSManagedObject?   •  Because  CoreData  objects  are  generally  not   thread  safe.     •  Different  contexts  (NSManagedObjectContext)   for  different  threads   •  It’s  safer  to  pass  around  pure  NSObjects   (MTLModel)  along  different  threads  

Slide 7

Slide 7 text

Mantle    -­‐-­‐>  Core  Data   •  Uniquing  (if  there’s  such  a  word)   •  Some  `meta`  fields  can  just  be  Transformable  

Slide 8

Slide 8 text

Reverse  Mantle   •  NSManagedObject  -­‐-­‐>  MTLModel   •  MTLModel  -­‐-­‐>  NSDic9onary  or  NSArray  

Slide 9

Slide 9 text

MagicalRecord   •  Cleans  up  all  the  shit  we  do  with  Core  Data   •  Manage  contexts   –  NSManagedObjectContext+MR_rootSavingContext   – MagicalRecord+saveWithBlock:comple9on   •  Easy  queries   –  NSManagedObject-­‐MR_findFirstByAeribute:withValue:inContext  

Slide 10

Slide 10 text

MagicalRecord   •  When  doing  queries,  use  the  context  from   [NSManagedObjectContext+MR_contextForCurrentThread]   •  Remember  that  queries  return   NSManagedObject  instances,  not  MTLModel   •  Use:   – MTLModel+modelsFromManagedObjects   – MTLModel+modelFromManagedObject  

Slide 11

Slide 11 text

Kusanagi  -­‐  KSDataStore   •  Has  no  other  purpose  but  to  ini9alize   MagicalRecord   •  We  might  move  some  Core  Data  stuffs  here   later  to  abstract  MagicalRecord.  

Slide 12

Slide 12 text

Kusanagi   •  Separate  project.  Added  to  Lifebit  as  local   Pod.   •  Kusanagi.xcdatamodel   – Remember  that  object  dele9on  rules  are  in   reverse   •  95%  of  the  9me,  JSON  responses  are  saved  to   Core  Data.   •  JSON  “.me”  responses  are  saved  as  “facts”  

Slide 13

Slide 13 text

Kusanagi  -­‐  some  rules   •  KSAPI  methods  should  map  to  the  real  API   endpoints.   •  When  adding  new  files   1.  Add  them  to  Kusanagi.xcodeproj     2.  Update  version  of  Kusanagi.podspec   3.  Run  `pod  update`  in  Lifebit  workspace   •         

Slide 14

Slide 14 text

Kusanagi  -­‐  some  rules   •  JSON  transforma9ons  and  saving  should  be  in   their  specific  classes   •  Use  a  single  NSManagedObjectContext  as   much  as  possible.   •  Enclose  JSON  transformers  in   +JSONDic9onaryTransformer  or   +JSONArrayTransformer  

Slide 15

Slide 15 text

Kusanagi  -­‐  some  rules   •  Custom  methods  for  queries  should  be  in   Lifebit  (+FFExtensions):   – KSQBTimelineItem+findForFeedOfRequestorId:   •  Other  app  specific  stuffs  should  be  in   +FFExtensions:   – KSPlace+urlStringForSta9cMapWithSize:  

Slide 16

Slide 16 text

XCODE  TIPS  

Slide 17

Slide 17 text

That  bueon  thingy  

Slide 18

Slide 18 text

Simple  LLDB  commands   •  po   •  Print   •  dot-­‐nota9on  doesn’t  work  

Slide 19

Slide 19 text

Advanced  breakpoints   •  You  don’t  have  to  stop  the  program  just  to   add  logging   •  Condi9ons   •  Ac9ons   – Log  Message   – Debugger  Command   – Sound   •  No  stopping  

Slide 20

Slide 20 text

Keyboard  shortcuts   •  CMD+[1-­‐8]   •  CMD+Opt+[1-­‐2]   •  Others:  Look  at  the  Xcode  menu  

Slide 21

Slide 21 text

Others   •  Reveal  in  Project  Navigator   •  Searching  with  Regex   •  Simulator   – Toggle  Slow  Anima9ons   – Color  Blended  Layers   •  Red:  blending   •  Green:  no  blending  

Slide 22

Slide 22 text

APPCODE  

Slide 23

Slide 23 text

AppCode  FTW   •  Find  Usages   – Includes  XIB  files!     •  Inspect  Code   •  Refactoring   – Rename     – Change  Signature  

Slide 24

Slide 24 text

AppCode  L   •  Code  hin9ng  is  slow     •  No  UI  designer  –  no  biggie  

Slide 25

Slide 25 text

Reveal  

Slide 26

Slide 26 text

CODING  CONVENTIONS  

Slide 27

Slide 27 text

MVVM:  Model-­‐View-­‐ViewModel   •  Assume  that  the  ViewController  is  part  of  the   view  

Slide 28

Slide 28 text

MVVM   •  ViewModels  are  moderately  aware  of  what   the  view  will  look  like  (e.g.  LoginForm)   •  Controllers  should  just  “react”  to  it’s   ViewModel.     •  Cells  can  have  their  own  ViewModels  too.  

Slide 29

Slide 29 text

Classes   •  Header  file   – #import  superclass  and  conformed  protocols   – Forward  declara9on  for  everything  else     •  Implementa9on  file     – #import  everything  you  use   – Use    conven9on  for  impor9ng   3rd-­‐party  libraries  

Slide 30

Slide 30 text

The  thing  with  ivars   •  Stop  directly  using  ivars  (`_property`).  Use   `self.property`.   •  Proper9es  launch  KVO  no9fica9ons   •  Proper9es  are  atomic  (cannot  be  accessed   from  more  than  one  thread)  -­‐  safer  to  read   and  write  in  mul9ple  threads   •  Prevent  accidents  when  overriding  proper9es  

Slide 31

Slide 31 text

Only  use  ivars…   •  Inside  `-­‐init`  constructors   •  Property  overrides  

Slide 32

Slide 32 text

Others   •  @strongify  and  @weakify  all  the  things   –  API  calls   –  RAC  handlers   –  Not  needed  in  UIView-­‐animateWithDura9on:     •  Make  sure  you  are  using  SDWebImage  when   loading  remote  images   •  Avoid  singletons.  Make  app  services  instead.   •  -­‐tableView:es9matedHeightForRowAtIndexPath    

Slide 33

Slide 33 text

Remember   •  AFNetworking  callbacks  are  run  on  the  main   thread.   •  Do  not  repeat  the  nightmare  that  was   `LBUser`  

Slide 34

Slide 34 text

Things  to  think  about   •  Reac9veCocoa   – reac9ve  programming   •  Auto-­‐layout   •  Swiy  

Slide 35

Slide 35 text

@END