Τρίτη 24 Απριλίου 2012

Chapter 3 - ARC-autorelease-static analyzer


  • Objects never live inside one another: they exist separately on the heap. Instead, objects keep o references to other objects as needed. 
  • Instance variables live in the heap as part of an object.
  • Local variables live in the method's frame. 
  • Dealloc method, is sent to an object when it is about to be destroyed. 
  • A retain cycle occurs when two or more objects have strong references to each other. 
  • To fix the retain cycle use the parent-child relationship. The parent has strong reference to child, and the child has weak reference to the parent. (__weak)
  • An interesting property of weak references is that automatically sets the instance variable to nil. 
  • __unsafe_unretained attribut is not automatically set to nil when the object it points to is destroyed. It exists primarily for backwards compatibility: applications prior to iOS 5. 
  • nonatomic is not the default option, so you will always need to explicitly declare your properties to be nonatomic. 
  • if there is no instance variable that matches the name of a synthesized property, one is automatically created. 
  • when you have a property that points to an instance of a class that has a mutable subclass (like NSString or NSArray), it is safer to make a copy of the object to point to rather than pointing to an existing object that could have other owners. 
  • The copy method (of NSString) returns a new NSString object (not an NSMutableString).
  • Copy gives you a strong reference to the object pointed to. 
  • During the dark days of manual reference counting, Apple was contributing to an open source project known as the Clang static analyzer and integrating it into Xcode. Eventually, the static analyzer got so good that Apple thought, "Why not just let the static analyzer insert all of the retain and release message?" Thus, ARC was born. 
  • An autorelease pool is created by the @autoreleasepool directive followed by curly brackets. Inside those curly brackets, any newly instantiated object returned from a method that doesn't have alloc or copy in its name is placed in that autorelease pool. When the curly bracket closes, any object in the pool loses an owner. 
  • iOS application automatically create an autorelease pool for you, and you really don't have to concern yourself with it. 
#source: Big nerd ranch - iOS Programming 3rd Edition

Δευτέρα 23 Απριλίου 2012

Chapter 2 - notes


  • a method is a chunk of code that can be executed 
  • a message is the act of asking a class or object to execute a method. 
  • reveal the log navigator using Command-7
  • At NSLog the first argument is required and must be an NSString instance. This instance is called the format string and it contains text and a number of tokens. When %@ is encountered in the format string , that argument is sent the message description
  • In objective-C an array does not actually contain the objects that belong to it; instead it holds a pointer to each object. (references). This means primitives and C structures cannot be added to an array. 
  • A single array can contain objects of different types. 
  • If you need to add "holes" to an array, you must use NSNull
  • Stylish Cocoa Touch programmers always follow the naming conventions (and they are a lot of them).
  • importing a file is the same as including a file in the C, except you are ensured that the file will only be included once. 
  • the designated initializer makes sure that every instance variable of an object is valid. 
  • in the designated initializer, the first thing you always do is call the superclass's designated initializer using super. The last thing you do is return a pointer to the successfully initialized object using self.
  • using initializers as a chain, reduces the chance for error and makes maintaining the code easier.  
  • init methods are always declared to return id.
  • We call it the isa pointer because an object "is a" instance of that class.
  • An instance method uses the - character just before the return type
  • a class method uses the + character
  • Class methods come first, followed by initializers. This is a convention that makes your header files easier to read. 
  • NSInteger is not an object but a type definition for "unsigned long"
  • Class methods should use self in convenience methods  instead of their class name so that a subclass can be sent the same message. 
  • Exceptions are also known as run-time errors.
  • unrecognized selector means the message you are sending isn't implemented by the receiver.  
  • If two classes have the same name is known as a namespace collision
  • Objective-C has no notion of namespaces. Instead, we prefix class names with two or three lettres to keep them distinct. For example, instead of call name Item we use the MMRItem, where MMR is the first letters of my mythical company. 
#source: Big Nerd Ranch Guide  - iOS Programming 3rd edition. 

Παρασκευή 20 Απριλίου 2012

Chapter 1 - notes


  • When an iOS application starts, it puts a view on the screen. You can think of this view as the background on which everything else appears
  • the groups at navigator are purely for the organization of files and do not correlate to the filesystem in any way. 
  • XIB - pronounced "zib"
  • When you build a project, the XIB file is compiled into a NIB file. 
  • The bundle is a directory containing the application's executable and any resources the executable uses. 
  • the labels and buttons are objects and objects have instance variables 
  • View objects are visible to the user
  • Model objects hold data and know nothing about the user interface. 
  • Controller are the managers in an application. they keep the view and model objects in sync, control the "flow" of the application, and save the model objects out to the filesystem.
  • Every iOS application has an "app delegate" object, and it is the primary controller of the application. 
  • Each button needs to trigger a method. When a UIButton is tapped, it sends a message to another object. The object that is sent the message is called the target. The message is called the action
  • What do IBOutlet and IBAction do in the declarations is that connect your controller and your view objects in the XIB file. 
  • Command-1, Command-2, Command-3, Command-4
  • App ID: The application identifier is a string that uniquely identifies your application on the App Store. Typically look like this: com.myname.GreatelookApp, where the name of the application follows the name of your company. 
  • The App ID in your provisioning profile must match the bundle identifier of your application. A development profile wil have a wildcard character (*) for its App ID and therefore will match any bundle identifier. 
  • Resources are things like images and sounds that are used by the application at runtime. XIB files, which are read in at runtime, are also resources. 
  • When you dragged one image file onto the icon tile, two things happened. First, the image file added to your project. Second, one entry were made in the MyApp-Info.plist.
  • The launch image has a specific role on iOS: it conveys to the user that the application is indeed launching and depicts the user interface that the user will interact with once the application has finished launching. One thing that launch image should not do is display a splash screen for your company or application. 

App Icons on iPad and iPhone - UI tab bar items

from stackoverflow

what is image size(resolution) for iPad 3 application development?



With the iPad 3, you also simply need to name your retina images foo@2x.png. It needs to be exactly two times the resolution of the corresponding foo.png. So, say foo.png is 10x10, then yourfoo@2x.png needs to be 20x20.
You can also make version specifically for iPhone/iPod or iPad and iOS will automatically chose the correct version. For this, you can use the ~iphone and ~ipad modifiers:
  • foo.png for all devices with non-retina display
  • foo~iphone.png specifically for iPhone/iPod non-retina
  • foo~ipad.png specifically for iPad non-retina
  • foo@2x.png for all devices with retina display
  • foo@2x~iphone.png specifically for iPhone/iPad retina
  • foo@2x~ipad.png specifically for iPad retina
You can mix them in any combination, as long as there's always a version for all your supported devices (if you're doing an iPad-only app there's no need to provide images for iPhone, of course). So it's OK to provide for example foo~iphone.pngfoo~ipad.png and then foo@2x.png.



from Documentation


Technical Q&A QA1686
App Icons on iPad and iPhone
Q: How are the icon files in my application bundle used on iPad and iPhone?
A: Below are guidelines for handling icon files for iPhone-only apps, iPad-only apps, and universal apps.
IMPORTANT: Icons marked with "Required" must be supplied in your application bundle.
iPhone-only Apps
Include the following in your application's Resources group in the Xcode project:
Table 1 : iPhone-only apps icon requirements.
Image Size (px)
File Name
Used For
Required Status
Notes
512x512
iTunesArtwork
Ad Hoc iTunes
Optional but recommended
File should be in png format, but name it without the .png extension
57x57
Icon.png
App Store and Home screen on iPhone/iPod touch
Required
<None>
114x114
Icon@2x.png
Home screen for iPhone 4 High Resolution
Optional but recommended
<None>
72x72
Icon-72.png
Home screen for iPad compatibility
Optional but recommended
<None>
29x29
Icon-Small.png
Spotlight and Settings
Optional but recommended
<None>
50x50
Icon-Small-50.png
Spotlight for iPad compatibility
Recommended if you have a Settings bundle, otherwise optional but recommended
<None>
58x58
Icon-Small@2x.png
Spotlight and Settings for iPhone 4 High Resolution
Recommended if you have a Settings bundle, otherwise optional but recommended
<None>
Your Resources group should look similar to Figure 1:
Figure 1: Add files to Resources group

Except for iTunesArtWork icon, list the names of each of these files in the Icon files entry in the Info.plist, in the order shown in the table. Follow the steps in "Add Icon files in Info.plist" section below. See Figure 4.
Back to Top 
iPad-only Apps
Include the following in your application's Resources group in the Xcode project:
Table 2 : iPad-only apps icon requirements.
Image Size (px)
File Name
Used For
Required Status
Notes
512x512
iTunesArtwork
Ad Hoc iTunes
Optional but recommended
File should be in png format, but name it without the .png extension
72x72
Icon-72.png
App Store and Home screen on iPad
Required
<None>
50x50
Icon-Small-50.png
Spotlight on iPad
Optional but recommended
<None>
29x29
Icon-Small.png
Settings on iPad
Recommended if you have a Settings bundle, otherwise optional but recommended
<None>
Except for iTunesArtWork icon, list the names of each of these files in the Icon files entry in the Info.plist, in the order shown in the table. Follow the steps in "Add Icon files in Info.plist" section below. See Figure 5.
Back to Top 
Universal Apps
Include the following in your application's Resources group in the Xcode project:
Table 3 : Universal apps icon requirements.
Image Size (px)
File Name
Used For
Required Status
Notes
512x512
iTunesArtwork
Ad Hoc iTunes
Optional but recommended
File should be in png format, but name it without the .png extension
57x57
Icon.png
App Store and the Home screen on iPhone/iPod touch
Required
<None>
114x114
Icon@2x.png
Home screen for iPhone 4 High Resolution
Optional but recommended
<None>
72x72
Icon-72.png
App Store and Home screen on iPad
Required
<None>
29x29
Icon-Small.png
Settings on iPad and iPhone, and Spotlight on iPhone
Recommended if you have a Settings bundle, otherwise optional but recommended
<None>
50x50
Icon-Small-50.png
Spotlight on iPad
Optional but recommended
<None>
58x58
Icon-Small@2x.png
Spotlight and Settings for iPhone 4 High Resolution
Recommended if you have a Settings bundle, otherwise optional but recommended
<None>
Except for iTunesArtWork icon, list the names of each of these files in the Icon files entry in the Info.plist, in the order shown in the table. Follow the steps in "Add Icon files in Info.plist" section below. See Figure 4.
Back to Top 
Add Icon files in Info.plist
To add the Icon files entry you will need to manually edit your Info.plist.
Open your Info.plist in Xcode, and locate the "Icon file" entry. Click on the plus (+) button at the end of the entry to make a new key entry. as shown in Figure 2.
Figure 2: Add a new entry under "Icon file" key


Then, type "Icon files" in the key column (notice the "s" added), or choose "Icon files" from the drop down list, as shown in Figure 3.
Figure 3: Add "Icon files" key in Info.plist

Next, turn down the disclosure triangle on "Icon files" and add the entries for the icons for your application, as shown in Figure 4 and Figure 5:
Figure 4: Add icon file entries for iPhone-only or Universal apps.


Figure 5: Add entries for iPad icon files.

Note: If you don't provide one of the listed optional icons, the system will automatically scale one of your existing icons to an appropriate size. However, it is strongly recommended that your application supply all the icons listed with specific sizes needed.
Back to Top 
Document Revision History
Date
Notes
2010-07-14
Fixed outdated "Add Icon files in Info.plist" section.
2010-07-12
Updated for iOS 4 requirements.
2010-04-09
New document that explains how the icon files in an application bundle are used on iPad and iPhone.
Posted: 2010-07-14




The documentation says that the tab bar image is usually 30x30, but I've found that the best size to setup the images is 48x32 pixels. This size still renders and gives you a bit more space.
The image is a PNG with transparency, only the mask is used. The UI renders the mask gray when unselected or blue/chrome when selected.