Category archive: English

youtube

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
State-Machines-in-Cocoa

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

Landscape

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

RotatingViewController

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

import

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

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

object_comparison

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

proper

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

NSDatePickerPalette

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];      }else{          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 |                                              NSSecondCalendarUnit)                                  fromDate:today];        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 |                               NSSecondCalendarUnit)                     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
alloc

Two staged creation in Cocoa and Objective C and why we need it

Two Staged Creation of objects in Cocoa and Objective C

Unlike other OO languages such as Smalltalk or Java, Cocoa separates memory allocation from instance initialization. The very first versions of NextStep had single creation methods, as in Smalltalk.

This was changed, because of the need of several different allocation strategies to cup with the stringent memory limitations of that time.… Leer mas

McsIQ

Sorting objects in Cocoa

Sorting objects in Cocoa: Sorting using selector (in ascending order)

This is the most common sorting method for sorting objects in Cocoa. It uses a selector that must return an NSComparisonResult (either NSOrderedAscending, NSOrderedSame, or NSOrderedDescending).
The most common selector is compare:.
Leer mas
libr

How to add a static library to iOS project in Xcode 4

Static library to iOS

After struggling for a while to include CHDataStructures to my iOS project, here’s a step by step guide that will allow you to add any static library without losing your mind.

STEP 1: Add the static library sources to a Source Tree
Go to XCode preferences and select the Source Trees tab, add a new source tree whereas the name and display name are WHATEVER_LIB_SRC and the path is the full path to the source code.
Leer mas
Copland_open_file_dialog_screenshot

Reducing the «syntactic castor-oil» in Objective C

Reducing the «syntactic castor-oil» in Objective C with explicit collections

I just finished reading «Regarding Objective-C & Copland 2010», where the author discusses if Objective C can be considered a «modern language». The provided description for a «modern language» is arguable (and I certainly don’t agree with all the points), but Objective C seems to do pretty well:

Automatic memory management.

Leer mas