Cocoa Faculty

iOS and Mac OS X programming

CocoaPods Errors and Solutions

| Comments

  • [!] Unable to satisfy the following requirements: ......

Solution:

$ sudo rm -fr ~/.cocoapods/repos/master
$ pod setup

Ref: http://blog.cocoapods.org/Repairing-Our-Broken-Specs-Repository/

  • [!] /usr/local/bin/git remote update error: cannot open FETCH_HEAD: Permission denied.....

Solution:

$ sudo chown -R username:groupname ~/Library/Caches/CocoaPods
$ sudo chown -R username:groupname ~/.cocoapods

Note: Replace username and groupname with your Mac login username/groupname. If you don't have groupname, just enter username.

Ref: http://stackoverflow.com/questions/16049335/cocoapods-pod-install-permission-denied

Install Homebrew + RVM

| Comments

Homebrew + RVM Setup

Jotting down the setup of Homebrew + RVM for new machine.

Install Homebrew

  1. Install Homebrew

  2. Add the following to ~/.bash_profile

# Put /usr/local/bin/ before /usr/bin/ to ensure the programs provided by
# Homebrew will be used instead of those system-provided.
export PATH="/usr/local/bin:$PATH"

Save changes to ~/.bash_profile and then restart Terminal.

Try out Homebrew

brew doctor // run this everytime before/after installing any new formula
brew install git
brew install wget
brew list
brew update
brew search <formula>
brew upgrade <formula>
brew info <formula>
brew uninstall <formula>
brew help

Install RVM

  1. Install RVM

  2. Add the following to ~/.bash_profile

# Add RVM to PATH for scripting
export PATH="$PATH:$HOME/.rvm/bin"

# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]]; then
  source "$HOME/.rvm/scripts/rvm";
fi

Try out RVM

rvm install 2.0.0
rvm --default 2.0.0
rvm use 2.0.0
rvm update --head # update rvm itself
gem install rails
gem install nomad-cli

Install specific version of Homebrew formula

See https://gist.github.com/gcatlin/1847248

Handling NSError Recovery With Block

| Comments

There are several scenarios where we have to provide users recovery options while the application encountered an error. However, creating a recoverable NSError is not a very pleasant experience. It's just tedious, so I wrapped up the creation process into one single API with block support.

This NSError category changed the process of creating a recoverable NSError from

   // Assume id recoveryDelegate exists
    NSMutableDictionary *info = [[NSMutableDictionary alloc] initWithCapacity:0];
    [info setObject:@"title" forKey:NSLocalizedDescriptionKey];
    [info setObject:@"suggestion" forKey:NSLocalizedRecoverySuggestionErrorKey];
    [info setObject:[NSArray arrayWithObjects:@"default", @"alternate", @"other option", nil]  forKey:NSLocalizedRecoveryOptionsErrorKey];
    [info setObject:recoveryDelegate forKey:NSRecoveryAttempterErrorKey];
    
    NSError *error = [NSError errorWithDomain:@"MyErrorDomain" code:0 userInfo:info];
// somewhere in recoveryDelegate's implementation file
#pragma mark NSErrorRecoveryAttempting Protocol

// This will be invoked while the error was presented with -[NSView presentError:modalForWindow:....]
- (void)attemptRecoveryFromError:(NSError *)error optionIndex:(NSUInteger)recoveryOptionIndex delegate:(id)delegate didRecoverSelector:(SEL)didRecoverSelector contextInfo:(void *)contextInfo
{
   // Do something here to recover the error based on the selected option
}

// This will be invoked while the error was presented with -[NSApp presentError:]
- (BOOL)attemptRecoveryFromError:(NSError *)error optionIndex:(NSUInteger)recoveryOptionIndex
{
   // Do something here to recover the error based on the selected option
    return YES;
}

to

   NSError *error = [NSError ot_errorWithTitle:@"title" 
                            recoverySuggestion:@"suggestion" 
                               recoveryOptions:[NSArray arrayWithObjects:@"default", @"alternate", @"other option", nil] 
                               recoveryHandler:^(NSUInteger optionIndex) {
       // Do something here to recover the error based on the selected option
   }];
    

You can obtain the source code here. Happy coding!