Tagged: gotcha RSS Toggle Comment Threads | Keyboard Shortcuts

  • Jorge Bernal 5:37 pm on October 3, 2011 Permalink
    Tags: gotcha   

    Fixed one of 2.9 crashes in [2236]. We were using some constants defined on 4.1, but we still support 4.0

    If you’re unsure in the future check the documentations, or run this:

    ack -h -a '_AVAILABLE_STARTING\(.*, ?__IPHONE_4_[123]' /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/System/Library/Frameworks
    

    After looking at those results, I haven’t found anything else we use unsupported in 4.0

     
  • Jorge Bernal 1:51 pm on February 11, 2011 Permalink
    Tags: , gotcha, memory   

    I got a really hard to debug issue today.

    When finishing up the changes in the post settings I realized that if you saved the post from the settings tab it crashed. Badly.

    -[CALayer release]: message sent to deallocated instance 0x4d3ca40
    

    What made it hard to debug was that the obvious cause was something in the post settings code, since a) that was what I was changing, and b) visiting the post settings view was making the bug appear.

    After long hours trying to find the cause, it turns out visiting the post settings was triggering low memory warnings, so when the post editor was dismissed, the blog view had been unloaded.

    The solution, storing the selected view controller for BlogViewController on viewDidUnload, and restoring it on viewDidLoad. Good thing is that this also fixed the issue when saving a post would take you to the comments list some times.

    So keep that in mind: view controllers can (and will) unload their views when they are hit by a low memory warning, and viewDidLoad should work in that case too.

     
  • Jorge Bernal 12:26 pm on January 26, 2011 Permalink
    Tags: , , gotcha   

    Another gotcha for the future: if you are managing a core data object relationships, don’t do this

    NSSet *categories = [self.blog.categories filteredSetUsingPredicate:predicate];
    if ([categories count] > 0)
        [self.categories addObjectsFromArray:[categories allObjects]];
    

    Do this instead

    NSSet *categories = [self.blog.categories filteredSetUsingPredicate:predicate];
    if ([categories count] > 0) {
        self.categories = [NSMutableSet setWithSet:results];
    

    The first seems to work, but the relationships are not actually stored in the database.
    Explanation from the Core Data Programming Guide

    It is important to understand the difference between the values returned by the dot accessor and by mutableSetValueForKey:. mutableSetValueForKey: returns a mutable proxy object. If you mutate its contents, it will emit the appropriate key-value observing (KVO) change notifications for the relationship. The dot accessor simply returns a set. If you manipulate the set as shown in this code fragment:

    [aDepartment.employees addObject:newEmployee]; // do not do this!

    then KVO change notifications are not emitted and the inverse relationship is not updated correctly.

    Recall that the dot simply invokes the accessor method, so for the same reasons:

    [[aDepartment employees] addObject:newEmployee]; // do not do this, either!

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel
Follow

Get every new post delivered to your Inbox.

Join 47 other followers