Tagged: Xcode RSS Toggle Comment Threads | Keyboard Shortcuts

  • toto 18:50 on 1. February 2012 Permalink | Reply
    Tags: , , Xcode   

    Debug broken code highlighting in Xcode 4 

    If you use Xcode 4 a lot this might have happened to you, too: Coloring and code completion fail and do not come back. Which makes working with Xcode almost impossible

    This happens when Xcode’s indexing process fails for some reason. This can be a header file is missing to code highlighting (which can be different from the compiler in some cases) or in some cases a bad #define. The problem is that it fails silently so you cannot fix it.

    After having this problem with a big project I stumbled onto the magic hint on Stack Overflow.  After you quit Xcode enter this into a shell:

    defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3

    After this you should open the project and see messages like this:

    Xcode: IDEIndexingClangInvocation: Failed to save PCH file: /Users/user/Library/Developer/Xcode/DerivedData/Project-drsrrgaenperjadmqslqfxyqcqyt/Index/PrecompiledHeaders/Some-Prefix-cgepzuvkwimbsvcmqrbbpeoyhdpz_ast/Some-Prefix.pch.pth

    Looking through these messages will show you what goes on and might help you finding the problem.

    For me it was just copying header files from a framework on the place the Clang parser was looking for them.

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

    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:57 on 1. September 2010 Permalink | Reply
    Tags: , Framework, Mac, , Xcode   

    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 11:21 on 10. May 2010 Permalink | Reply
    Tags: Coding Style, Xcode   

    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: , Xcode   

    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: , Xcode   

    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: , Xcode   

    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

  • Ullrich 18:01 on 23. November 2009 Permalink | Reply
    Tags: , Xcode   

    Optimize your Autorelease pools with the following environment variables

    NSAutoreleaseHighWaterMark
    Default: 0
    If set to X, autorelease pools will print a message if more than X objects accumulate in the pool

    NSAutoreleaseHighWaterResolution
    Default: 0
    If set to Y, a message is logged for every Y objects that accumulate in the pool beyond the high-water mark (X)

     
  • Ullrich 16:56 on 23. November 2009 Permalink | Reply
    Tags: Xcode   

    Comes in handy… A build Script that wraps up the app and builds an ipa archive from it.
    You should put it in a separate target (I use “Aggregate”) that depends on your main target. Name the Target “myProduct.ipa”:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    
    if ( [ ${CONFIGURATION} != "Beta" ] || [ ${EFFECTIVE_PLATFORM_NAME} != "-iphoneos" ] ) ; then
      echo "error: Not building ipa. Select Beta configuration and Device as platform"
      exit 0
    fi
     
    export TMP_PATH=/tmp/ipa.$RANDOM
     
    mkdir -p "$TMP_PATH/Payload"
     
    # copy app
    cp -R "${BUILD_DIR}/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/${CONTENTS_FOLDER_PATH}" "$TMP_PATH/Payload/${CONTENTS_FOLDER_PATH}"
     
    # copy artwork
    if [ -e "${PROJECT_DIR}/iTunesArtwork" ] ; then
      cp "${PROJECT_DIR}/iTunesArtwork" "$TMP_PATH"
    elif [ -e "${PROJECT_DIR}/Resources/iTunesArtwork" ] ; then
      cp "${PROJECT_DIR}/Resources/iTunesArtwork" "$TMP_PATH"
    fi
     
    pushd $TMP_PATH
    if test -e iTunesArtwork; then
    	zip -r "${PRODUCT_NAME}.zip" Payload/ iTunesArtwork
    else
    	zip -r "${PRODUCT_NAME}.zip" Payload/
    fi
    popd
     
    rm -f "${BUILD_DIR}/${PRODUCT_NAME}"
    mv "$TMP_PATH/${PRODUCT_NAME}.zip" "${BUILD_DIR}/${PRODUCT_NAME}"
     
    rm -rf "$TMP_PATH"
     
  • Ullrich 13:14 on 20. November 2009 Permalink | Reply
    Tags: Xcode   

    Use conditional build settings. 

    For a couple of build settings the use of conditions come quite handy.

    To create a condition select the specific build setting and choose “Add Build Setting Condition” from the menu on the bottom left of your build settings dialog.

    create build settings condition

    A good example is the setting for the Thumb instruction set on ARM processors. This brings performance increase on ARM7 but not on ARM6. Thats why you want to have it switched on only on ARM7 architectures.

    Thumb build setting with conditions

     
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