New free video lectures from Stanford University

Stanford University releases new free video lectures

Stanford University improves its already incredibly generous display of free video lectures. After  Paul Hegarty’s iOS Programming Course and Peter Norvig’s (sic!) Artificial Intelligence, Stanford releases the following free video lectures:

Besides the instant classics:

iOS & Python Training in English, Spanish, Portuguese and French

On the shoulders of such giants as Paul Hegarty and Peter Norvig there’s life too.
Leer mas

Tutorial programación iPhone iPad: Stanford publica la nueva versión de su curso de desarrollo iOS

Tutorial programación iPhone iPad de la Universidad de Stanford

La Universidad de Stanford acaba de publicar la última versión de su curso de desarrollo iOS, se trata de un completo tutorial programación iPhone iPad.

El curso de otoño del 2011, una vez más impartido por Paul Hegarty cubre temas como:

  1. Herramientas y API necesarias para construir aplicaciones iOS.
Leer mas

State Machines in Cocoa / Objective C

State Machines

State Machines model systems that can be in any of a limited number of «conditions» (states) and moves from one to another according to a fixed set of rules. An example would be an object that represents an http connection.… Leer mas


RotatingViewController: Display a different UIViewController depending on the orientation of the device


Sometimes you may want to display a different view in landscape and portrait mode. A good example is Apple’s Calculator: it switches from normal in portrait mode to scientific in landscape mode.

There are several reasons you may want to do so:

  1. Your view is very complex and it’s impossible or very difficult to reuse it in landscape mode.
Leer mas
El Lenguaje de Programación C

Variadic methods in Objective C

Methods that accept a variable number of parameters

It’s very common in Cocoa to find methods that take a variable number of parameters (ending in nil). For example, see NSArray’s arrayWithObjects: or dictionaryWithObjectsAndKeys: in NSDictionary.

In both cases, the method will loop through our list processing each element until it reaches the nil.… Leer mas


How to avoid a circular import error in Objective C

Circular import error in Objective C

This morning I was treacherously bitten in the butt by a circular import error. In order to help you avoid this same kind of error I am summarizing my findings.

#import best practices to avoid circular errors in Objective C

An #import in your header causes that header to be imported into every file which imports your header, causing slower compiles, possibly unwanted namespace pollution, and  a circular import error.… Leer mas


Los Tres Mandamientos de La Gestión de Memoria en Objective C y Cocoa

Los 3 mandamientos de la gestión de memoria en Objective C y Cocoa.

  1. : Para las variables de instancia, usa SIEMPRE propiedades autogeneradas (@property y @synthesize). Esto es todo lo que tienes que recordar para las variables de instancia.
  2. : Para los objetos temporales, si los has creado llamando a alloc o a copy, eres responsable de llamar a release o autorelease al final del método en el que los has creado.
Leer mas
Building Mobile Applications

Free video lectures for Harvard’s «Mobile Applications in html 5, iOS and Android»

Mobile applications in html 5, iOS and Android

Harvard has made its Computer Science E-76: Building Mobile Applications course free online. It includes video lectures and source code samples in PDF.

The course covers today’s  3 main technologies: Html 5 , iOS and  Android free lectures, the iOS section includes iPhone and iPad programming, and the instructors are Dan Armendariz and David Malan.… Leer mas


Map, reduce y filter en Cocoa.

Map, Reduce, Filter: iteración de alto nivel

Después de trabajar con Smalltalk, Lisp o Python, todos ellos lenguajes que poseen en mayor o menor grado estructuras de iteración avanzadas, se hace muy difícil utilizar mecanismos más primitivos.

Dado que Objective C posee bloques, condición sine qua non para implementar funciones (métodos en nuestro caso) similares a map, reduce, filter, daba por hecho que Cocoa traía «de serie» una implementación de dichos métodos.… Leer mas


Comparing Objects in Cocoa / Objective C

Comparing Objects in Cocoa: Object Equality in Cocoa & Objective C

Cocoa defines several methods for comparing objects in Cocoa:

  • isEqual:
  •  isEqualToClassName

isEqual: compares the receiver to an object and will return NO if the object doesn’t belong to the same class as the receiver.… Leer mas


How to change the highlighted background color of a UITableView’s cell

Changing the background color of the selected cell in a UITableView

The default value for selectedBackgroundView is nil for cells in plain-style tables (UITableViewStylePlain) and non-nil for section-group tables (UITableViewStyleGrouped).

If you’re using a plain-style table, you must alloc an init a new UIView with the desired background color, and then assign it to selectedBackgroundView.… Leer mas


NSDate: Working with dates in Cocoa, creating and decomposing.

Create a NSDate from its components (day, month, year)

You don’t use a init method in NSDate, instead, you use a method of NSCalendar (dateFromComponents:):

Method that initializes a NSDate form an ISO 8601 date representation (YYYYMMDD):

-(id) initWithISO8601Date: (NSString *) iso8601Date{
    // Takes a date in the YYYYMMDD form
    if ([iso8601Date length] == 8 ) {
        int year = [[iso8601Date substringWithRange:NSMakeRange(0, 4)] integerValue];
        int month = [[iso8601Date substringWithRange:NSMakeRange(4, 2)] integerValue];
        int day = [[iso8601Date substringWithRange:NSMakeRange(6,2)] integerValue];

        NSDateComponents *comps = [[NSDateComponents alloc] init];
        [comps setYear:year];
        [comps setMonth:month];
        [comps setDay:day];

        NSCalendar *cal = [NSCalendar currentCalendar];
        [cal setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
        self = [cal dateFromComponents:comps];

        [comps release];
        self = nil;
        [NSException raise:@"Wrong ISO8601 format"
                    format:@"Should be in YYYYMMDD format, instead got %@", iso8601Date];

    return self;


Tokenize a NSDate into its components (day, month, year, etc…)

You also use a method form NSCalendar(components:fromDate):

    NSDate *today = [[[NSDatealloc] init] autorelease];
    NSDateComponents *tokens = [[NSCalendarcurrentCalendar]
                                components:(NSYearCalendarUnit |
                                            NSMonthCalendarUnit |
                                            NSDayCalendarUnit |
                                            NSHourCalendarUnit |
                                            NSMinuteCalendarUnit |

    NSLog(@"%d %d %d", [tokens year], [tokens month], [tokens day]);

Tokenize the difference between 2 dates into its components (day, month, year, etc…)

Use a similar method from NSCalendar: components:fromDate:toDate:options:

    NSDate *today = [[[NSDatealloc] init] autorelease];
    NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease];
    [comps setYear:1970];
    [comps setMonth:1];
    [comps setDay:7];

    NSCalendar *cal = [NSCalendarcurrentCalendar];
    [cal setTimeZone: [NSTimeZonetimeZoneWithAbbreviation:@"GMT"]];

    NSDate *daysOfOld = [cal dateFromComponents:comps];

    comps = [cal components:(NSYearCalendarUnit |
                             NSMonthCalendarUnit |
                             NSDayCalendarUnit |
                             NSHourCalendarUnit |
                             NSMinuteCalendarUnit |
                   fromDate:daysOfOld toDate:today
                    options:0];    NSLog(@"You are a %d years %d months %d days %d hours %d minutes and %d seconds old fart!",
Leer mas