non-ARC의 Objective-C 포인트

1484 단어 Objective-C
  • 프로그램에서 @property를 사용하는 곳에 대응하는 instance variable
  • 을 만들었습니다
  • 하나의class가person이retain인 경우
  • //viewDidLoad    
    
    self.person = [Person alloc] initWithArray:sbs]
    
    //           ,  person retain ,  setter  ( [self setPerson])     1 。         (alloc)    ,    self person      2 。    ?
    
         ,            autorelease,    self  person   setter  ,    alloc         。     :
    
    
    
    self.person =[[Person alloc] initWithArray:sbs]autorelease];
    
    

      3. 줄 규칙은 "init/dealloc에서 setter/getter가 적용되지 않습니다"
  •  
    자신이 나중에 코코스2D를 할 수도 있고,
     
    그래서property가cocos2D에서의 규칙, 고수 총결산, 원문 주소http://www.raywenderlich.com/2712/using-properties-in-objective-c-tutorial
     
    So to avoid making unnecessary properties for everything, here’s what I like to use for Cocos2D:
  • Don’t use properties at all.
  • Set instance variables directly to your created sprites, etc.
  • Since they’ll be children of the current layer, Cocos2D will keep the retain count up as long as they’re there.
  • When you remove the object from the layer, set the instance variable to nil.

  • I just personally find it simpler and faster to develop this way.
    Note this strategy doesn’t work if you want to keep track of an object not currently in the layer – you’ll have to use an alternative strategy there.

    좋은 웹페이지 즐겨찾기