Κυριακή, 20 Μαΐου 2012

JSON format


Today i saw that twitter APIs sends data in JSON format :) 

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming LanguageStandard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.
JSON is built on two structures:
  • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangeable with programming languages also be based on these structures.
In JSON, they take on these forms:
An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma).

An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).

value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.

string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

number is very much like a C or Java number, except that the octal and hexadecimal formats are not used.

Whitespace can be inserted between any pair of tokens. Excepting a few encoding details, that completely describes the language.

Πέμπτη, 10 Μαΐου 2012

Name conventions - conventions


  • Ref, CGContextRef is a pointer to struct CGContext. The suffix Ref makes it easy to distinguish between pointers to C structures and pointers to Objective-C objects. 
  • At saved images you can use the @2x addition to annotate that this file is to be display if retina display exists. Example we save "apple.png" and "apple@2x.png". The first picture, it will be used on Non retina displays and the second will be used if retina display exists. The selection is automatic. example UIImage * i = [[UIImage imageNamed:@"apple.png"];
  • By convention, the reuse identifier  of every cell (from UITableViewCell) is simply the name of the cell class. If you have a table view that uses multiple styles of the same type of cell, you can suffix the reuse identifier with the name of that style, e.g. UITableViewCell-Default


  • NSCoder: Regardless of the type of the encoded value, there is always a key, which is a string that identifies which instance variable is being encoded. By convention, this key is the name of the instance variable being encoded. 
  • The key on NSUserDefaults (is a NSMutableDictionary) that holds the application preferences is the name of the application, the name of the preference, and the words PrefKey. This is the typical pattern for naming preference keys
  • Class meethods come first, followed by initializers, followed by any other methods. This is a convention that makes you header files easier to read. 

Τρίτη, 1 Μαΐου 2012

XCode 4.3.2 - Automatically set a breakpoint on any line that causes your application

Automatically set a breakpoint on any line that causes your application to crash or that causes an exception to be thrown.
To get the debugger to do this, we need to add a breakpoint for all exceptions.

  • Select the debug navigator. 
  • Then at the bottoms of the navigator area, click the + icon and select Add Exception Breakpoint. 
  • then click the Done button on the panel that pops up



#source: Big nerd ranch guide - iOS Programming - 3rd Edition