My Blog List

Saturday, June 25, 2011

Testing Stark's O'Reilly book

Oh dear, I just discovered a book that is going to take me off-track, but I think it's worthy of investigation!

It's Building iPhone Apps wiht HTML, CSS, and JavaScriptby Jonahtan Sark (O'Reilly)


I'm testing the just-my-own-html capabilities of blogger, wondering if I have to go and setup an actual web page or if this will do the trick for now.
I certainly did a lot of html tagging at one point in my life, and it would be fun to go back to it

Well blogger does put it's default tags in. How much is that going to throw me?

Probably I better setup a regular web page through comcast. I remember that was kind of a page last time I tried. Gee, I bet there is some place I can get a free student web page.

Syntax Review Continued: Focusing on Dot Notation

Dot notation page 147 Goldstein's Objective-C book

* Here the author has an example with dot notation. The class is 'vacationBudgetEurope'. Two of the ivars declared in the interface for that class 'exchangeRate' and 'budget' are referred to in these lines of code.

vacationBudgetEurope.exhangeRate = 1.2500;
vacationBudgetEurope.budget = 1000.00;

Well that makes sense to me.  I think that it may be encapsulation that throws me off when I encounter dot notation in the framework. Because I know it's not always this obvious.
 

Friday, June 24, 2011

Method Declarations: Back to Syntax (Fnishing Gestures and Chapter 11)


Hmmmm I got the tutorial working in the iPad Application Development book, chapter 11. But when I got to the section on gestures there was some syntax I'm unsure about. I need to go back to Goldstein's Objective-C book. I worked on that last year, but clearly I need to do some refreshing.

There's developing abilities with the framework but then every once and a while the language trips me up. I can't afford that when I want to focus on the framework documentation. So back-to-grass-tacks for awhile. What are grass tacks anyway? Am I even remembering the idiom correctly?

Going to summarize syntax as I go, starting with chapter 6 of the objective-c book.
  1. Method declarations are like function prototypes in Objective-C (page 146-7)
    1. When there's only one argument, I'll see just one ':' but there are lots of methods that take more than one argument. The number of ":"'s (colons) shows how many argments there are
    2. The code below declares the "createBudget:: method. It has two argments
    3. -(void) createBudget:(double) aBudget 
    4. withExchangeRate: (float) anExchangeRage;
    5. The COLON is considered to be a PART OF THE METHOD NAME
    6. If there are no colons than there are no arguments
  2.  The real method name is createBudget:withExchangeRate 
  3.  Notice that "("'s are used around both the 
    1. return value
    2. argument/data types - because we are casting one type to another (chapter 4)
  4. Inside of the method I am declaring, I will access the arguments using the identifier names 'aBudget' and 'anExchangeRate'

Wednesday, June 15, 2011

Study Notes: Syntax, Picking apart UILabel (sliders)


Study Notes Wednesday, June 15, 2011

Picking apart another line of code to study syntax,  from example on page 236

   sliderDisplay.text = [NSString stringWithFormat:@"%.2f", slider.value);

This is how I’m currently interpreting this line of code.

I’m messaging the NSSTring class to put the value attribute of slider (of type UILabel), a string of a certain format, into the text portion/value of the DISPLAY version of a slider.  I guess they are different because I’ll probably use the sliderDisplay in a view and the slider.value is just where I store things that I may be changing internally. And maybe this has to do with keeping things on the view separate from things I operate and do math on, etc. the value of slider is probably something I change directly. Maybe….

Here are the ideas that I used to figure out my current interpretation.

* Ways to figure out what “.text” means
o   Command option help
o   Check code sense in book
o   Check settings


My sense is that it is an attribute, a property of files of the type/class that sliderDisplay is. Because when I do a ctrl click on it, several classes come up.

So First I will see what class sliderDisplay is in my interface.

IBOutlet    UILabel     *sliderDisplay;

So now when I jump to definition for text, I will look for the one associatd with UILabel




   sliderDisplay.text = [NSString stringWithFormat:@"%.2f", slider.value);

So I think that sliderDisplay is an ivar that can be composed of different pieces/ivars depending on what I need. And I think that .text is one of the pieces/ideas/attributes/properties that I want to address.

I think that I’m saying that I’m picking up a value (the value attribute of the slider object)
    IBOutlet    UISlider    *slider;
    IBOutlet    UILabel     *sliderDisplay;
}

I’m messaging the NSSTring class to put the value attribute of slider (of type UILabel), a string of a certain format, into the text portion/value of the DISPLAY version of a slider.  I guess they are different because I’ll probably use the sliderDisplay in a view and the slider.value is just where I store things that I may be changing internally. And maybe this has to do with keeping things on the view separate from things I operate and do math on, etc. the value of slider is probably something I change directly. Maybe….

·     Notice that ‘text’ and ‘NSString’ are both colored purple.
o    I know that ‘NSString’ is a framework class.
o   What does that tell me about ‘.text’?
o   It’s not a framework class because it doesn’t start with a capital letter
o   It uses dot notation, which I thought could be a method or an ivar.     LOOK IN THE OLDER BOOK FOR DOT NOTATION   
o   Preference settings indicates it could be a CLASS or a TYPE or IVAR or GLOBAL name
o   But I don’t think MY ivars are purple, ‘other’


·     Reencountered the apple documentation on objective-c and programming in objective – c. Good time to look at this again. Plan to start reading through this today after I work a little more on this example.

Tuesday, June 14, 2011

Study Notes: Syntax, Picking Apart the UIColor example

Study Notes: Syntax UIColor example



* Notice there are examples linked from frameworks class documentation. Studying these has been suggested in class and by Goldstein for learning
…..
What the following

   theTextField.textColor    =[UIColor blueColor];

seems to boil down to is

…. Set the textColor attribute (property) of my ‘theTextField’ ivar to be BLUE.


And here are all the details I went through to figure that out
….
I want to better understand this line of code from page 236

    theTextField.textColor =[UIColor blueColor];

“theTextField”

·    is a pointer I defined in the interface file associated with this implementation file.

@interface SettingsViewController : UIViewController {
    <SettingsViewControllerDelegate> delegate;
    float                       sliderValue;
    IBOutlet  UITextField   *theTextField;

·    The pointer is of type UITextField, a frameworks class
·    The part that follows theTextField uses dot notation
o     I THINK textColor is an instance method associated with UITextField



Let’s see if I can figure that out

·     option+ command on UITextField
·     follow link to ()delegate Protocol

NO DICE NO REFERENCE TO textColor


Overview
A UITextField object is a control that displays editable text and sends an action message to a target object when the user presses the return button. You typically use this class to gather small amounts of text from the user and perform some immediate action, such as a search operation, based on that text.
In addition to its basic text-editing behavior, the UITextField class supports the use of overlay views to display additional information (and provide additional command targets) inside the text field boundaries. You can use custom overlay views to display features such as a bookmarks button or search icon. The UITextField class also provides a built-in button for clearing the current text.
A text field object supports the use of a delegate object to handle editing-related notifications. You can use this delegate to customize the editing behavior of the control and provide guidance for when certain actions should occur. For more information on the methods supported by the delegate, see the UITextFieldDelegate protocol.


Go back up a level looking for textColor (some kind of method I think….)

It is a property of the UITextFieldClass. Don’t quite understand that. I know I use the property declaration to substitute for accesors. Well I least I see it that is something



OK back to

    theTextField.textColor =[UIColor blueColor];

I know that [] syntax means that I’m messaging an object. “Many methods in UIKit require you to specify color data using a UIColor object, and for general color needs it should be your main way of specifying colors. “
 So I’m messaging the UIColor class from the blueColor method.

I guess that I’m saying…. Set the textColor attribute (property) of my ‘theTextField’ ivar to be BLUE.





Understanding UIColor use


·     option+ command on UIColor to get documention

Overview
A UIColor object represents color and sometimes opacity (alpha value). You can use UIColor objects to store color data, and during drawing you can use them to set the current fill and stroke colors.
Many methods in UIKit require you to specify color data using a UIColor object, and for general color needs it should be your main way of specifying colors. The color spaces used by this object are optimized for use on iOS-based devices and are therefore appropriate for most drawing needs. If you prefer to use Core Graphics colors and color spaces instead, however, you may do so.
Most developers should have no need to subclass UIColor. The only time doing so might be necessary is if you require support for additional colorspaces or color models.


·     UIColor is the class
UIColor Class Reference
Inherits from
Conforms to
Framework
/System/Library/Frameworks/UIKit.framework
Availability
Available in iOS 2.0 and later.
Declared in
UIColor.h
UIInterface.h
·      
·     blueColor is a class method assoc. with UIColor
blueColor
Returns a color object whose RGB values are 0.0, 0.0, and 1.0 and whose alpha value is 1.0.
+ (UIColor *)blueColor
Return Value
The UIColor object.
Availability
·                       Available in iOS 2.0 and later.

Study Notes: On PROTOCOLS and DELEGATES



Finally, I am starting to get a better sense of the use of protocols and delegates.  The light that went on today was as a result of page 235 in Goldstein/Bove's iPad Application for Dummies, 2nd edition.

It helps that I'm picking through the example tiny bit by tiny bit, like I'm looking for gold dust in a big pan of water, rock and dirt. (Not a reflection on objective-c!)

"The methods that a class delegates are defined in a protocol..... (using).... the @protocol directive."

"Protocols declare methods that can be implemented by any class."

 .....

Previous helpful references from one of following page groups 204, 234-5, 318

* One object delegates the task of implementing one of it's methods, to another object

* Methods a class delegates are defined in a protocol


Tuesday, June 7, 2011

Coding Study Notes:Foundation- NSNumber

Coding Study Notes:Foundation- NSNumber

Page 322 in the Kochan, Programming in Objective-C 2.0

·   create objects so that values declared as  C data types can be worked with as objects
·   Use NSNUmber class to create objects from different data types
·   Early example with integer value uses two lines, but later examples do conversion with one line of code, embedding the message/receiver syntax in along with the assignment statement

·   program 15.1 from the text


// Working with Numbers

//#import <Foundation/Foundation.h>
#import <Foundation/NSObject.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSString.h>


int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSNumber    *myNumber, *floatNumber, *intNumber;
    NSInteger   myInt; // why doesn't myInt need to be a pointer? Because it's used for conversion?
   
    intNumber = [NSNumber numberWithInteger: 100];
       
    // oh but wait, bet I can do the same thing in NSLog as I do with the other guys
    NSLog (@" Let's try to put message receiver into NSLog %li", [intNumber integerValue]);
   
    myInt = [intNumber integerValue]; //  for some reason intNumber has to get converted using integerValue

   
    NSLog (@"\n * * * *");
    NSLog (@"\n Before conversion The integer object was %li", intNumber );
   
    //I think we are casting the interger value as a long
    NSLog (@" %li", (long) myInt);
   
    // * * * long value
   
    myNumber = [NSNumber numberWithLong: 0xabcdef];
    NSLog (@"\n A long value %1x", [myNumber longValue]);
   
    // * * * * char value
   
    myNumber = [NSNumber numberWithChar: 'X'];
    NSLog (@"\n A character value %c", [myNumber charValue]);
   
    //float value
   
    floatNumber = [NSNumber numberWithFloat:100.00];
    NSLog (@"\n A float number %g", [floatNumber floatValue]);
   
    //double
   
    myNumber = [NSNumber numberWithDouble:12345e+15];
    NSLog (@"%1g", [myNumber doubleValue]);
   
    // wrong access
   
    NSLog (@"%i", [myNumber integerValue]); // no error, I have to know what I'm doing uh oh
   
    // Test two numbers for equality
   
    if ([intNumber isEqualToNumber: floatNumber]== YES)
    //    NSLog (@"Numbers are equal %li, %g," [intNumber integerValue] [floatNumber floatValue]);
    //    NSLog (@"Numbers are equal %i" , intNumber  ); runs clean - prints address of pointer
    {
    NSLog (@"Numbers are equal " );
        // page 325
        // NSLog format is [ my-NSNumber-declared-object retrieval-instance-method-for-NSNumber]
    NSLog (@" \n this integer %li", [intNumber integerValue]);
    NSLog (@" \n and a float I'm gonna show next " );
        NSLog (@"\n This float number %g", [floatNumber floatValue]);
       

    //&&&&&
    NSLog (@" \n %li", (long) myInt);
    }
    else
         NSLog (@"Numbers are not equal");
         
         // Test if one Number is <, ==, or > second number
         
    if ([intNumber compare: myNumber] == NSOrderedAscending)
         NSLog (@"First number is less than second");
   
    NSLog (@"First number is gonna print, then Second number \n");
    NSLog (@" \n this integer %li", [intNumber integerValue]);
    NSLog (@"%1g", [myNumber doubleValue]);
   
   
   
    [pool drain];
    return 0;
}

/*
 run
 [Switching to process 5458]
 Running…
 2011-06-06 22:02:40.622 NumberObjectsVer2[5458:a0f]  Let's try to put message receiver into NSLog 100
 2011-06-06 22:02:40.626 NumberObjectsVer2[5458:a0f]
 * * * *
 2011-06-06 22:02:40.626 NumberObjectsVer2[5458:a0f]
 Before conversion The integer object was 4296052080
 2011-06-06 22:02:40.627 NumberObjectsVer2[5458:a0f]  100
 2011-06-06 22:02:40.627 NumberObjectsVer2[5458:a0f]
 A long value abcdef
 2011-06-06 22:02:40.628 NumberObjectsVer2[5458:a0f]
 A character value X
 2011-06-06 22:02:40.629 NumberObjectsVer2[5458:a0f]
 A float number 100
 2011-06-06 22:02:40.629 NumberObjectsVer2[5458:a0f] 1.2345e+19
 2011-06-06 22:02:40.630 NumberObjectsVer2[5458:a0f] 0
 2011-06-06 22:02:40.630 NumberObjectsVer2[5458:a0f] Numbers are equal
 2011-06-06 22:02:40.631 NumberObjectsVer2[5458:a0f] 
 this integer 100
 2011-06-06 22:02:40.631 NumberObjectsVer2[5458:a0f] 
 and a float I'm gonna show next
 2011-06-06 22:02:40.632 NumberObjectsVer2[5458:a0f]
 This float number 100
 2011-06-06 22:02:40.632 NumberObjectsVer2[5458:a0f] 
 100
 2011-06-06 22:02:40.633 NumberObjectsVer2[5458:a0f] First number is less than second
 2011-06-06 22:02:40.633 NumberObjectsVer2[5458:a0f] First number is gonna print, then Second number
 2011-06-06 22:02:40.634 NumberObjectsVer2[5458:a0f] 
 this integer 100
 2011-06-06 22:02:40.634 NumberObjectsVer2[5458:a0f] 1.2345e+19
 Debugger stopped.
 Program exited with status value:0.
 */