iPhone command line tool development, working with framework classes
Tech-Today

iPhone command line tool development, working with framework classes


iPhone command line tool development, working with framework classes

I was studying iPhone when I found this video tutorial and online exercises from Stanford University. I think they offered this course last 2009.

So I'm gonna follow their videos, slides, assignments and exercises.

Assignment 1B: WhatATool
This exercise explores the following classes: NSString, NSURL, NSMutableArray, NSArray, NSProcessInfo, NSMutableString, etc. For a depth explanation of these classes consult the xcode documentation.

You should follow the instruction from the pdf available on Stanford site. Or simply create a new Foundation class project. See attached image.

I'll explain the exercise in code:
#import <Foundation/Foundation.h>

void PrintPathInfo() {
    //expand the directory
    NSString *path = [@"~" stringByExpandingTildeInPath];
    NSLog(@"My home folder is at %@", path);
    
    //get the components of the url
    NSArray *folders = [path pathComponents];
    
    //print each component/folder
    for(NSString *element in folders) {
        NSLog(@"%@", element);
    }
}

void PrintProcessInfo() {
    NSString *processName = [[NSProcessInfo processInfo] processName];
    NSInteger processIdentifier = [[NSProcessInfo processInfo] processIdentifier];
        
    //prints the process name and id
    NSLog(@"Process Name: '%@' Process ID: '%i'", processName, processIdentifier);
}

void PrintBookmarkInfo() {
    NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
    //creates an NSURL object and add it to a NSMutableDictionary object
    [dictionary setValue: [NSURL URLWithString:@"http://www.stanford.edu"] forKey: @"Stanford University"];
    [dictionary setValue: [NSURL URLWithString:@"http://www.apple.com"] forKey: @"Apple"];
    [dictionary setValue: [NSURL URLWithString:@"http://www.cs193p.stanford.edu"] forKey: @"CS193P"];
    [dictionary setValue: [NSURL URLWithString:@"http://www.itunes.stanford.edu"] forKey: @"Stanford on iTunes U"];
    [dictionary setValue: [NSURL URLWithString:@"http://www.stanfordshop.com"] forKey: @"Stanford Mall"];
    
    //iterate
    NSString *key;
    for(key in dictionary) {
        NSString *value = [dictionary objectForKey:key];
        //checks if prefix has "Stanford" word
        if([key hasPrefix: @"Stanford"]) {
            NSLog(@"%@", value);
        }
    }
}

void PrintIntrospectionInfo() {
    //creates an assorted types of objects
    NSString *string = [NSString stringWithFormat:@"Hello World!"];
    NSURL *url = [NSURL URLWithString:@"http://google.com"];
    NSProcessInfo *processInfo = [NSProcessInfo processInfo];
    NSDictionary *dictionary = [NSDictionary dictionary];
    NSMutableString *ms1 = [NSMutableString string];
    [ms1 appendString:@"Hello "];
    [ms1 appendString:@"World!"];
    
    NSMutableArray *array = [NSMutableArray array];
    
    //add to an object array
    [array addObject: string];
    [array addObject: url];
    [array addObject: processInfo];
    [array addObject: dictionary];
    [array addObject: ms1];
    
    //iterate to the object array
    int count = [array count];
    for(int i = 0; i < count; i++) {
        //get the object at the current index
        NSObject *object = [array objectAtIndex: i];
        
        //prints the class name
        NSLog(@"Class name: %@", [object className]);
        
        //check if the object is a member of class NSString
        if([object isMemberOfClass: [NSString class]]) {
            NSLog(@"Is Member of NSString: YES");
        } else {
            NSLog(@"Is Member of NSString: NO");
        }
        
        //check if the object is a kind of NSString class
        if([object isKindOfClass: [NSString class]]) {
            NSLog(@"Is Kind of NSString: YES");
        } else {
            NSLog(@"Is Kind of NSString: NO");
        }
        
        //initialize a lowercaseString selector
        SEL selector = @selector(lowercaseString);
        //check if the object respond to that selector
        if([object respondsToSelector: selector]) {
            NSLog(@"Responds to lowercaseString: YES");
            //perform the method
            NSLog(@"lowercaseString is: %@", [object performSelector: selector]);
        } else {
            NSLog(@"Responds to lowercaseString: NO");
        }
        
        NSLog(@"==================================");
    }
}

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSLog(@"Hello, World!");
    
    PrintPathInfo();
    PrintProcessInfo();
    PrintBookmarkInfo();
    PrintIntrospectionInfo();
    
    [pool drain];
    return 0;
}




- How To Handle Checkbox Event In Swift
A very simple checkbox control.  @IBAction func btn_box(sender: UIButton) {        if (btn_box.selected == true)        {            btn_box.setBackgroundImage(UIImage(named: "box"),...

- Useful Article Links In Studying Swift
1.) For studying the basic of swift :      file:///Users/czetsuya/Downloads/404_advanced_swift.pdf-,%20attachment 2.) Useful for studying "Case Classes"      http://masteringios.com/blog/2014/06/26/hello-swift/2/ 3.) “Building...

- How To Access Asp:textbox With Runat=server Attribute In Javascript
For example you have a textbox which has a default value, and you want to clear that value when the user click on the textbox: <asp:TextBox ID="txtBox" runat="server" onclick="clear()" Text="Enter Keyword" /> <script type="text/javascript">...

- Create A New Eclipse-rcp Preference Page By Code When A Listener Is Invoked
Objective: -To create an eclipse-rcp preference page without using the preference extension, all is done in code. This is done by creating a customized button with a SelectionListener, and eventually that action will call a customized preference page....

- Remove Or Customize The Close/minimize/maximize Button In An Eclipse-rcp's Application's Window
There are times when you just want your eclipse rcp in the middle of the screen. To do that you have to set the style bits for the window's shell to customize the look of your window. The API is accessible here: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/index.html,...



Tech-Today








.