Updates from Ullrich RSS Toggle Comment Threads | Keyboard Shortcuts

  • Ullrich 09:14 on 14. October 2010 Permalink | Reply
    Tags: , , , ,   

    Colliding Category Methods 

    After multiple years of Objective-C experience yesterday was the first time that we actually ran into problems with colliding methods in categories.

    Here’s the story (you may skip this part): The issue was, that we added a method -setParameters: to NSMutableURLRequest which takes a dictionary and set’s it as query string or multipart form body depending on the HTTP Method used for sending the request. This method sadly conflicted with a category on the same class defined in a library called OAuthConsumer which doesn’t take a dictionary as argument but rather an array of key-value pairs. Both categories we’re linked to our application as static libraries.

    The result was that our -setParameters: was called with an array although a dictionary was expected. We noticed the problem since NSArray is not responding to -allKeys. It could have gone would have not noticed the problem. Just imagine trying to debug a misbehavior when you’re looking at the wrong piece of code.

    The quintessence, and what basically helped us finding the issue is a environment variable named OBJC_PRINT_REPLACED_METHODS. Similar to NSZombieEnabled you set it in the Arguments tab of your executable info as variable set to environment. Just like this:

     
  • Ullrich 15:27 on 27. September 2010 Permalink | Reply
    Tags: , ,   

    Zombies 

    Everyone should know the NSZombieEnabled environment variable. Set it to YES to temporarily disable deallocation of objects which reach a retain count of zero. You then can set breakpoints to common methods such as:

    fb -[_NSZombie init]
    fb -[_NSZombie retainCount]
    fb -[_NSZombie retain]
    fb -[_NSZombie release]
    fb -[_NSZombie autorelease]
    fb -[_NSZombie methodSignatureForSelector:]
    fb -[_NSZombie respondsToSelector:]
    fb -[_NSZombie forwardInvocation:]
    fb -[_NSZombie class]
    fb -[_NSZombie dealloc]

    But you should also know that this only works on NS classes. To have a similar effect on CoreFoundation classes use CFZombieLevel. The value of CFZombieLevel is defined by a bit array. See the following table. A good value is 5 :)

    Bit	Action
    0	scribble deallocated CF memory
    1	when scribbling deallocated CF memory, don't scribble object header (CFRuntimeBase)
    4	never free memory used to hold CF objects
    7	if set, scribble deallocations using bits 8..15, otherwise use 0xFC
    8..15	if bit 7 is set, scribble deallocations using this value
    16	scribble allocated CF memory
    23	if set, scribble allocations using bits 24..31, otherwise use 0xCF
    24..31	if bit 16 is set, scribble allocations using this value
     
  • Ullrich 15:57 on 1. September 2010 Permalink | Reply
    Tags: , Framework, Mac, ,   

    Embedded Frameworks 

    When embedding frameworks to your Mac app there might be problems of finding a header file. There are three things to check for:

    • The framework needs to have @executable_path/../Frameworks as Installation Directory in it’s build settings.
    • The app should include the following in its framework search path: “$(CONFIGURATION_BUILD_DIR)/$(CONTENTS_FOLDER_PATH)/Frameworks” (including the quotes!)
    • Also make sure to have a Copy Frameworks build phase and that your famework is added to it.
     
    • Ullrich 16:24 on 13. September 2010 Permalink

      When you’re importing the header files make sure to import them “framework style”:

      #import <TheFramework/TheHeader.h>

      If you still can’t find your framework headers make sure your target is actually linked against them.

  • Ullrich 14:31 on 3. June 2010 Permalink | Reply
    Tags:   

    Finder Toolbar Items 

    Did you know that you can add applications to your Finder toolbar? This comes in as a very handy shortcut because you can add context aware action scripts that do common stuff for you. Today I’m sharing 3 of them that help me through my days. :)

    • OpenInGitX  - This opens GitX with the currently opened folder. (Also make sure to check out brotherbard’s experimental GitX fork)
    • OpenInTextMate – As it says, it opens the currently selected files (or if non selected the currently opened folders) in TextMate.
    • OpenTerminalHere – This is the most useful. It opens Terminal.app with the current folder.

    You can download them here. It’s a good idea to extract them into your applications folder like so:

    To add them to your toolbar simple drag them there. That’s how my toolbar looks:

    The scripts/applications are based on this post but have been modified slightly. Let me know if you like’em :)

     
    • Emmanuel Paraskakis 14:32 on 7. August 2010 Permalink

      Just what I was looking for – Thanks!

    • Kim Thostrup 23:40 on 11. January 2011 Permalink

      Perfect, thanks.

    • Miro 17:50 on 12. May 2011 Permalink

      Hello,
      thank you for the great scripts, I found a little bug in the OpenGitX here script, when you try to apply it to the folder with a spaces in the name, so I fixed it by changing this line to:
      do shell script “screen -dmS git-gui-droplet bash -c \”cd ” & listOfAliases & “; /usr/local/bin/gitx\”"

      Hope this will help lots of people :)

  • Ullrich 17:17 on 20. May 2010 Permalink | Reply
    Tags: , ,   

    Finishing & canceling concurrent NSOpera… 

    Finishing & canceling concurrent NSOperations requires to trigger KVO for isFinished and isCancelled.

     
  • Ullrich 13:31 on 19. May 2010 Permalink | Reply
    Tags: ,   

    Prevent UIWebView from horizontal scrolling.

    HTML meta:

    <meta name = "viewport"
          content = "initial-scale = 1.0, user-scalable = no, width = 320"/>

    CSS:

    text-overflow: ellipsis;
    overflow: hidden;
     
    • Andrews 11:28 on 25. September 2011 Permalink

      the meta does not work for me.

  • Ullrich 11:21 on 10. May 2010 Permalink | Reply
    Tags: ,   

    No 1 in (serious) series of coding style posts: Private methods

    Declaring private methods in a class extension (like an anonymous category) rather than a named category makes the compiler warn you when those methods aren’t implemented.

    # MyClass.h
     
    @interface MyClass : NSObject {
    }
    - (void)publicMethod;
    @end
     
     
    # MyClass.m
     
    #include "MyClass.h"
     
    @interface MyClass ()
    - (void)privateMethod;
    @end
     
     
    @implementation MyClass
     
    - (void)publicMethod;
    {
        NSLog(@"public");
    }
     
    - (void)privateMethod;
    {
        NSLog(@"very private");
    }
     
    @end
     
    • Gernot 12:55 on 20. July 2010 Permalink

      Also: With the new Runtime, you can declare private ivars in a class extension. The new Runtime is available on the iPhone since 3.0 (might be 3.1 I’m not sure now) and on the Simulator of XCode 4.

  • Ullrich 13:02 on 26. April 2010 Permalink | Reply
    Tags: ,   

    If you want your subviews rendered before the alpha value is applied you can use the UIViewGroupOpacity Info Plist setting.

     
  • Ullrich 15:34 on 16. April 2010 Permalink | Reply
    Tags: ,   

    My list of breakpoints. Add them to your ~/.gdbinit

    fb -[NSException raise]
    fb -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:]
    fb -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
     
    fb NSKVODeallocateBreak
     
    fb _NSAutoreleaseNoPool
     
    fb -[_NSZombie init]
    fb -[_NSZombie retainCount]
    fb -[_NSZombie retain]
    fb -[_NSZombie release]
    fb -[_NSZombie autorelease]
    fb -[_NSZombie methodSignatureForSelector:]
    fb -[_NSZombie respondsToSelector:]
    fb -[_NSZombie forwardInvocation:]
    fb -[_NSZombie class]
    fb -[_NSZombie dealloc]
     
    fb szone_error
     
    fb objc_exception_throw
    fb malloc_error_break
     
    fb CGPostError
    fb malloc_printf
    fb _objc_error
    fb objc_exception_during_finalize_error
    fb auto_zone_resurrection_error
    fb auto_refcount_underflow_error

    UPDATE: added _NSAutoreleaseNoPool breakpoint to stop when there’s no autorelease pool but one is expected.

     
  • Ullrich 11:53 on 27. November 2009 Permalink | Reply
    Tags: ,   

    Use NSAssert(…) during development.
    But set NS_BLOCK_ASSERTIONS pre compiler flag for release.

     
    • toto 15:23 on 17. May 2010 Permalink

      NS_BLOCK_ASSERTIONS=1 Seems to be default in XCode 3.2

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