SlideShare a Scribd company logo
1 of 6
Download to read offline
CS193P                                                                            Assignment 1B
Winter 2010                                                                    Cannistraro/Shaffer

                       Assignment 1B - WhatATool (Part I)
Due Date
This assignment is due by 11:59 PM, January 13.

 Assignment
In this assignment you will be getting your feet wet with Objective-C by writing a small
command line tool. You will create and use various common framework classes in order to
become familiar with the syntax of the language.

The Objective-C runtime provides a great deal of functionality, and the gcc compiler
understands and compiles Objective-C syntax. The Objective-C language itself is a small set of
powerful syntax additions to the standard C environment.

To that end, for this assignment, you’ll be working in the most basic C environment available –
the main() function.

This assignment is divided up into several small sections. Each section is a mini-exploration of a
number of Objective-C classes and language features. Please put each section’s code in a
separate C function. The main() function should call each of the section functions in order.
Next week will add more sections to this assignment.

IMPORTANT: The assignment walkthrough begins on page 3 of this document. The
assignment walkthrough contains all of the section-specific details of what is expected.

The basic layout of your program should look something like this:

#import <Foundation/Foundation.h>

// sample function for one section, use a similar function per section
void PrintPathInfo() {
	      // Code from path info section here
}

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

	    PrintPathInfo();                  //   Section   1
	    PrintProcessInfo();               //   Section   2
	    PrintBookmarkInfo();              //   Section   3
	    PrintIntrospectionInfo();         //   Section   4

    [pool release];
    return 0;
}

Testing
In most assignments testing of the resulting application is the primary objective. In this case,
testing/grading will be done both on the output of the tool, but also on the code of each
section.

We will be looking at the following:
1. Your project should build without errors or warnings.
2. Your project should run without crashing.

                                            Page 1 of 6
CS193P                                                                           Assignment 1B
Winter 2010                                                                   Cannistraro/Shaffer

3. Each section of the assignment describes a number of log messages that should be printed.
   These should print.
4. Each section of the assignment describes certain classes and methodology to be used to
   generate those log messages – the code generating those messages should follow the
   described methodology, and not be simply hard-coded log messages.

A note about the NSLog function. It will generate a string that is prefixed with a timestamp, the
name of the process, and the pid. It will also automatically append a newline to the log
statement.

        2009-09-23 13:49:42.275 WhatATool[360] Your message here.


This is expected. You are only being graded on the text not generated automatically by NSLog.
You do not need to attempt to suppress what NSLog prints by default.

To help make the output of your program more readable, it would be helpful to put some kind
of header or separator between each of the sections.

Hints
Hints are distributed section by section but generally, the lecture #2 notes provide some very
good clues with regards to Objective-C syntax and commonly used methods.

Another source of good information is the Apple ADC site. In particular, these documents may
be particularly helpful:

http://developer.apple.com/documentation/Cocoa/Conceptual/OOP_ObjC

http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC

http://developer.apple.com/iphone/gettingstarted/docs/objectivecprimer.action


Troubleshooting
Remember that an Objective-C NSString constant is prefixed with an @ sign. For example,
@”Hello World”. The compiler will warn, and your program will crash if you use a C string
where an NSString is required.




                                           Page 2 of 6
CS193P                                                                           Assignment 1B
Winter 2010                                                                   Cannistraro/Shaffer

Assignment Walkthrough

In Xcode, create a new Foundation Tool project. Name it WhatATool.




You will be doing the bulk of your work in the WhatATool.m file where a skeletal implementation
of main() has been provided.

You should build and test at the end of each code-writing section.

Finding Answers / Getting to documentation
Some of the information required for this exercise exists in the class documentation, not in the
course materials. You can use the Xcode documentation window to search for class
documentation as well as conceptual articles.

Open the Xcode documentation window by choosing Help > Documentation.

The leftmost section of the search bar in the documentation window lets you search APIs, Titles
or Full-Text of the documentation. For now, use the API Search. Select an appropriate Doc Set
to search, for example the “Apple iPhone OS 2.0” doc set should contain all the materials you’ll
need for this assignment.




                                           Page 3 of 6
CS193P                                                                             Assignment 1B
Winter 2010                                                                     Cannistraro/Shaffer

Section 1: Strings as file system paths

NSString has a set of methods that allow you to manipulate file system paths. You can find
them in the NSString documentation grouped under the heading “Working with paths”     .

In this section, begin with an NSString constant that is a tilde – the symbolic representation for
your home directory in Unix.

          NSString *path = @"~";

Starting with that string, find a path method that will expand the tilde in the path to the full
path to your home directory. Use that method to make a new string, and log the full path in a
format like:

          My home folder is at '/Users/pmarcos'

NSString has a method that will return an array of path components. Each element in the
returned array is a single component in the original path.

Use this method to get an array of path components for the path you just logged.

Use fast enumeration to enumerate through each item in the returned array, and log each path
component. The result should look something like:
	         /
          Users
	         pmarcos

Section Hints:
    • With string convenience methods, a common pattern is to reuse the same variable:
                NSString *aString = @"Bob";
      	         aString = [aString stringWithSomeModification];



Section 2: Finding out a bit about our own process
Look up the class NSProcessInfo in the documentation.

You will find a class method that will return an NSProcessInfo object. (In fact, you should find a
very handy code sample there as well).

From this object, you can access the name and process identifier (pid) of the process.

Log these pieces of information to the console using NSLog in the format:

          Process Name: 'WhatATool' Process ID: '4556'

Section Hints:
    • We didn’t discuss NSProcessInfo in lecture at all, so you aren’t missing any slides or notes.
      All of the information you need is in the NSProcessInfo class documentation.
    • Comparing the process info you logged with the prefix that NSLog generates can help
      verify you’re logging the correct information.



                                            Page 4 of 6
CS193P                                                                             Assignment 1B
Winter 2010                                                                     Cannistraro/Shaffer



Section 3: A little bookmark dictionary

In this section, you will build a small URL bookmark repository using a mutable dictionary. Each
key is an NSString that serves as the description of the URL, the value is an NSURL.

Create a mutable dictionary that contains the following key/value pairs:

Key (NSString)                    Value (NSURL)
Stanford University               http://www.stanford.edu
Apple                             http://www.apple.com
CS193P                            http://cs193p.stanford.edu
Stanford on iTunes U              http://itunes.stanford.edu
Stanford Mall                     http://stanfordshop.com

Enumerate through the keys of the dictionary. While enumerating through the keys, check each
key to see if it starts with @”Stanford” If it does, retrieve the NSURL object for that key from the
                                       .
dictionary, and log both the key string and the NSURL object in the following format below. If
the key does not start with @”Stanford” no output should be printed.
                                          ,

           Key: 'Stanford University' URL: 'http://www.stanford.edu'

Section Hints:
    • Use +URLWithString: to create the URL instances.
    • NSString has methods to determine if a string has a particular prefix or suffix. Remember
      to log only those keys that start with ‘Stanford’.
    • The methods for creating and adding items to a mutable dictionary are located in the
      Lecture #2 slides. Remember that an NSMutableDictionary is a subclass of NSDictionary
      and so inherits all of its methods.
    • When using a dictionary and fast enumeration, you are enumerating the keys of the
      dictionary. You can use the key to then retrieve the value. NSDictionary also defines a
      method called valueEnumerator that returns an NSEnumerator object which will directly
      enumerate the values. You can use either approach.

Section 4: Selectors, Classes and Introspection
Objective-C has a number of facilities that add to its dynamic object-oriented capabilities.  Many
of these facilities deal with determining and using an object's capabilities at runtime. 

Create a mutable array and add objects of various types to it. Create instance of the classes
we’ve used elsewhere in this assignment to populate the array: NSString, NSURL, NSProcessInfo,
NSDictionary, etc. Create some NSMutableString instances and put them in the array as well.
Feel free to create other kinds of objects also.

Iterate through the objects in the array and do the following:

      1.    Print the class name of the object.
      2.    Log if the object is member of class NSString.
      3.    Log if the object is kind of class NSString.
      4.    Log if the object responds to the selector "lowercaseString".


                                             Page 5 of 6
CS193P                                                                           Assignment 1B
Winter 2010                                                                   Cannistraro/Shaffer

      5. If the object does respond to the lowercaseString selector, log the result of asking the
         object to perform that selector (using performSelector:)

For example, if an array contained an NSString, an NSURL and an NSDictionary the output might
look something like this:

2008-01-10    20:56:03   WhatATool[360]   Class name: NSCFString
2008-01-10    20:56:03   WhatATool[360]   Is Member of NSString: NO
2008-01-10    20:56:03   WhatATool[360]   Is Kind of NSString: YES
2008-01-10    20:56:03   WhatATool[360]   Responds to lowercaseString: YES
2008-01-10    20:56:03   WhatATool[360]   lowercaseString is: hello world!
2008-01-10    20:56:03   WhatATool[360]   ======================================
2008-01-10    20:56:03   WhatATool[360]   Class name: NSURL
2008-01-10    20:56:03   WhatATool[360]   Is Member of NSString: NO
2008-01-10    20:56:03   WhatATool[360]   Is Kind of NSString: NO
2008-01-10    20:56:03   WhatATool[360]   Responds to lowercaseString: NO
2008-01-10    20:56:03   WhatATool[360]   ======================================
2008-01-10    20:56:03   WhatATool[360]   Class name: NSCFDictionary
2008-01-10    20:56:03   WhatATool[360]   Is Member of NSString: NO
2008-01-10    20:56:03   WhatATool[360]   Is Kind of NSString: NO
2008-01-10    20:56:03   WhatATool[360]   Responds to lowercaseString: NO
2008-01-10    20:56:03   WhatATool[360]   ======================================

Section Hints:
   • When you ask various classes, such as NSString, for its class name, you may not get the
      result you expect.  Your logs should report what the runtime reports back to you - don't
      worry if some of the class names may seem strange, these are implementation details of
      the NSString class. Encapsulation at work!




                                           Page 6 of 6

More Related Content

What's hot

How to really obfuscate your pdf malware
How to really obfuscate your pdf malwareHow to really obfuscate your pdf malware
How to really obfuscate your pdf malware
zynamics GmbH
 
Introduction to mobile reversing
Introduction to mobile reversingIntroduction to mobile reversing
Introduction to mobile reversing
jduart
 

What's hot (20)

Tech breakfast 18
Tech breakfast 18Tech breakfast 18
Tech breakfast 18
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
Java notes
Java notesJava notes
Java notes
 
Java for C++ programers
Java for C++ programersJava for C++ programers
Java for C++ programers
 
Swift Tutorial Part 2. The complete guide for Swift programming language
Swift Tutorial Part 2. The complete guide for Swift programming languageSwift Tutorial Part 2. The complete guide for Swift programming language
Swift Tutorial Part 2. The complete guide for Swift programming language
 
How to really obfuscate your pdf malware
How to really obfuscate your pdf malwareHow to really obfuscate your pdf malware
How to really obfuscate your pdf malware
 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)
 
C#.NET
C#.NETC#.NET
C#.NET
 
C sharp
C sharpC sharp
C sharp
 
1..Net Framework Architecture-(c#)
1..Net Framework Architecture-(c#)1..Net Framework Architecture-(c#)
1..Net Framework Architecture-(c#)
 
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift ApplicationsHack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
 
AngularConf2015
AngularConf2015AngularConf2015
AngularConf2015
 
Introduction to mobile reversing
Introduction to mobile reversingIntroduction to mobile reversing
Introduction to mobile reversing
 
Introducing TypeScript
Introducing TypeScriptIntroducing TypeScript
Introducing TypeScript
 
Core Java
Core JavaCore Java
Core Java
 
Packer Genetics: The selfish code
Packer Genetics: The selfish codePacker Genetics: The selfish code
Packer Genetics: The selfish code
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Csharp
CsharpCsharp
Csharp
 
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming LanguageSwift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
 
API workshop: Deep dive into Java
API workshop: Deep dive into JavaAPI workshop: Deep dive into Java
API workshop: Deep dive into Java
 

Viewers also liked (6)

Mobile development
Mobile developmentMobile development
Mobile development
 
01 introduction
01 introduction01 introduction
01 introduction
 
Mume HTML5 Intro
Mume HTML5 IntroMume HTML5 Intro
Mume HTML5 Intro
 
More! @ ED-MEDIA
More! @ ED-MEDIAMore! @ ED-MEDIA
More! @ ED-MEDIA
 
Mume JQueryMobile Intro
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile Intro
 
iOS Development Introduction
iOS Development IntroductioniOS Development Introduction
iOS Development Introduction
 

Similar to Assignment1 B 0

Assignment2 A
Assignment2 AAssignment2 A
Assignment2 A
Mahmoud
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docx
fredharris32
 
Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7
ashhadiqbal
 
Ts archiving
Ts   archivingTs   archiving
Ts archiving
Confiz
 
27.1.5 lab convert data into a universal format
27.1.5 lab   convert data into a universal format27.1.5 lab   convert data into a universal format
27.1.5 lab convert data into a universal format
Freddy Buenaño
 
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docxCS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
faithxdunce63732
 
OverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxOverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docx
alfred4lewis58146
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential files
CIS321
 
ActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsActionScript 3.0 Fundamentals
ActionScript 3.0 Fundamentals
Saurabh Narula
 

Similar to Assignment1 B 0 (20)

Assignment2 A
Assignment2 AAssignment2 A
Assignment2 A
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docx
 
Aspect-oriented programming in Perl
Aspect-oriented programming in PerlAspect-oriented programming in Perl
Aspect-oriented programming in Perl
 
Java lab-manual
Java lab-manualJava lab-manual
Java lab-manual
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
 
iOS Application Development
iOS Application DevelopmentiOS Application Development
iOS Application Development
 
Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7
 
Ts archiving
Ts   archivingTs   archiving
Ts archiving
 
27.1.5 lab convert data into a universal format
27.1.5 lab   convert data into a universal format27.1.5 lab   convert data into a universal format
27.1.5 lab convert data into a universal format
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
 
PRG 421 Education Specialist / snaptutorial.com
PRG 421 Education Specialist / snaptutorial.comPRG 421 Education Specialist / snaptutorial.com
PRG 421 Education Specialist / snaptutorial.com
 
A Project Based Lab Report On AMUZING JOKE
A Project Based Lab Report On AMUZING JOKEA Project Based Lab Report On AMUZING JOKE
A Project Based Lab Report On AMUZING JOKE
 
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docxCS 23001 Computer Science II Data Structures & AbstractionPro.docx
CS 23001 Computer Science II Data Structures & AbstractionPro.docx
 
Language-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible researchLanguage-agnostic data analysis workflows and reproducible research
Language-agnostic data analysis workflows and reproducible research
 
1. introduction to python
1. introduction to python1. introduction to python
1. introduction to python
 
OverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxOverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docx
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential files
 
NamingConvention
NamingConventionNamingConvention
NamingConvention
 
ActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsActionScript 3.0 Fundamentals
ActionScript 3.0 Fundamentals
 
Basics java programing
Basics java programingBasics java programing
Basics java programing
 

More from Mahmoud

مهارات التفكير الإبتكاري كيف تكون مبدعا؟
مهارات التفكير الإبتكاري  كيف تكون مبدعا؟مهارات التفكير الإبتكاري  كيف تكون مبدعا؟
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
Mahmoud
 
كيف تقوى ذاكرتك
كيف تقوى ذاكرتككيف تقوى ذاكرتك
كيف تقوى ذاكرتك
Mahmoud
 
مهارات التعامل مع الغير
مهارات التعامل مع الغيرمهارات التعامل مع الغير
مهارات التعامل مع الغير
Mahmoud
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
Mahmoud
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائقتطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
Mahmoud
 
الشخصية العبقرية
الشخصية العبقريةالشخصية العبقرية
الشخصية العبقرية
Mahmoud
 
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيهمهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
Mahmoud
 
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
مهارات التفكير الإبتكاري  كيف تكون مبدعا؟مهارات التفكير الإبتكاري  كيف تكون مبدعا؟
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
Mahmoud
 
مهارات التعامل مع الغير
مهارات التعامل مع الغيرمهارات التعامل مع الغير
مهارات التعامل مع الغير
Mahmoud
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائقتطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
Mahmoud
 
كيف تقوى ذاكرتك
كيف تقوى ذاكرتككيف تقوى ذاكرتك
كيف تقوى ذاكرتك
Mahmoud
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
Mahmoud
 
الشخصية العبقرية
الشخصية العبقريةالشخصية العبقرية
الشخصية العبقرية
Mahmoud
 
Accident Investigation
Accident InvestigationAccident Investigation
Accident Investigation
Mahmoud
 
Investigation Skills
Investigation SkillsInvestigation Skills
Investigation Skills
Mahmoud
 
Building Papers
Building PapersBuilding Papers
Building Papers
Mahmoud
 
Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02
Mahmoud
 
Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01
Mahmoud
 
A Basic Modern Russian Grammar
A Basic Modern Russian Grammar A Basic Modern Russian Grammar
A Basic Modern Russian Grammar
Mahmoud
 

More from Mahmoud (20)

مهارات التفكير الإبتكاري كيف تكون مبدعا؟
مهارات التفكير الإبتكاري  كيف تكون مبدعا؟مهارات التفكير الإبتكاري  كيف تكون مبدعا؟
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
 
كيف تقوى ذاكرتك
كيف تقوى ذاكرتككيف تقوى ذاكرتك
كيف تقوى ذاكرتك
 
مهارات التعامل مع الغير
مهارات التعامل مع الغيرمهارات التعامل مع الغير
مهارات التعامل مع الغير
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائقتطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
 
الشخصية العبقرية
الشخصية العبقريةالشخصية العبقرية
الشخصية العبقرية
 
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيهمهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
مهارات كتابه السيرة الذاتيه واجتياز المقابله الشخصيه
 
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
مهارات التفكير الإبتكاري  كيف تكون مبدعا؟مهارات التفكير الإبتكاري  كيف تكون مبدعا؟
مهارات التفكير الإبتكاري كيف تكون مبدعا؟
 
مهارات التعامل مع الغير
مهارات التعامل مع الغيرمهارات التعامل مع الغير
مهارات التعامل مع الغير
 
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائقتطوير الذاكرة    تعلم كيف تحفظ 56 كلمة كل 10 دقائق
تطوير الذاكرة تعلم كيف تحفظ 56 كلمة كل 10 دقائق
 
كيف تقوى ذاكرتك
كيف تقوى ذاكرتككيف تقوى ذاكرتك
كيف تقوى ذاكرتك
 
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكمستيفن كوفي ( ادارة الاولويات ) لايفوتكم
ستيفن كوفي ( ادارة الاولويات ) لايفوتكم
 
الشخصية العبقرية
الشخصية العبقريةالشخصية العبقرية
الشخصية العبقرية
 
Accident Investigation
Accident InvestigationAccident Investigation
Accident Investigation
 
Investigation Skills
Investigation SkillsInvestigation Skills
Investigation Skills
 
Building Papers
Building PapersBuilding Papers
Building Papers
 
Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02Appleipad 100205071918 Phpapp02
Appleipad 100205071918 Phpapp02
 
Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01Operatingsystemwars 100209023952 Phpapp01
Operatingsystemwars 100209023952 Phpapp01
 
A Basic Modern Russian Grammar
A Basic Modern Russian Grammar A Basic Modern Russian Grammar
A Basic Modern Russian Grammar
 
Teams Ar
Teams ArTeams Ar
Teams Ar
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 

Assignment1 B 0

  • 1. CS193P Assignment 1B Winter 2010 Cannistraro/Shaffer Assignment 1B - WhatATool (Part I) Due Date This assignment is due by 11:59 PM, January 13. Assignment In this assignment you will be getting your feet wet with Objective-C by writing a small command line tool. You will create and use various common framework classes in order to become familiar with the syntax of the language. The Objective-C runtime provides a great deal of functionality, and the gcc compiler understands and compiles Objective-C syntax. The Objective-C language itself is a small set of powerful syntax additions to the standard C environment. To that end, for this assignment, you’ll be working in the most basic C environment available – the main() function. This assignment is divided up into several small sections. Each section is a mini-exploration of a number of Objective-C classes and language features. Please put each section’s code in a separate C function. The main() function should call each of the section functions in order. Next week will add more sections to this assignment. IMPORTANT: The assignment walkthrough begins on page 3 of this document. The assignment walkthrough contains all of the section-specific details of what is expected. The basic layout of your program should look something like this: #import <Foundation/Foundation.h> // sample function for one section, use a similar function per section void PrintPathInfo() { // Code from path info section here } int main (int argc, const char * argv[]) { NSAutoreleasepool * pool = [[NSAutoreleasePool alloc] init]; PrintPathInfo(); // Section 1 PrintProcessInfo(); // Section 2 PrintBookmarkInfo(); // Section 3 PrintIntrospectionInfo(); // Section 4 [pool release]; return 0; } Testing In most assignments testing of the resulting application is the primary objective. In this case, testing/grading will be done both on the output of the tool, but also on the code of each section. We will be looking at the following: 1. Your project should build without errors or warnings. 2. Your project should run without crashing. Page 1 of 6
  • 2. CS193P Assignment 1B Winter 2010 Cannistraro/Shaffer 3. Each section of the assignment describes a number of log messages that should be printed. These should print. 4. Each section of the assignment describes certain classes and methodology to be used to generate those log messages – the code generating those messages should follow the described methodology, and not be simply hard-coded log messages. A note about the NSLog function. It will generate a string that is prefixed with a timestamp, the name of the process, and the pid. It will also automatically append a newline to the log statement. 2009-09-23 13:49:42.275 WhatATool[360] Your message here. This is expected. You are only being graded on the text not generated automatically by NSLog. You do not need to attempt to suppress what NSLog prints by default. To help make the output of your program more readable, it would be helpful to put some kind of header or separator between each of the sections. Hints Hints are distributed section by section but generally, the lecture #2 notes provide some very good clues with regards to Objective-C syntax and commonly used methods. Another source of good information is the Apple ADC site. In particular, these documents may be particularly helpful: http://developer.apple.com/documentation/Cocoa/Conceptual/OOP_ObjC http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC http://developer.apple.com/iphone/gettingstarted/docs/objectivecprimer.action Troubleshooting Remember that an Objective-C NSString constant is prefixed with an @ sign. For example, @”Hello World”. The compiler will warn, and your program will crash if you use a C string where an NSString is required. Page 2 of 6
  • 3. CS193P Assignment 1B Winter 2010 Cannistraro/Shaffer Assignment Walkthrough In Xcode, create a new Foundation Tool project. Name it WhatATool. You will be doing the bulk of your work in the WhatATool.m file where a skeletal implementation of main() has been provided. You should build and test at the end of each code-writing section. Finding Answers / Getting to documentation Some of the information required for this exercise exists in the class documentation, not in the course materials. You can use the Xcode documentation window to search for class documentation as well as conceptual articles. Open the Xcode documentation window by choosing Help > Documentation. The leftmost section of the search bar in the documentation window lets you search APIs, Titles or Full-Text of the documentation. For now, use the API Search. Select an appropriate Doc Set to search, for example the “Apple iPhone OS 2.0” doc set should contain all the materials you’ll need for this assignment. Page 3 of 6
  • 4. CS193P Assignment 1B Winter 2010 Cannistraro/Shaffer Section 1: Strings as file system paths NSString has a set of methods that allow you to manipulate file system paths. You can find them in the NSString documentation grouped under the heading “Working with paths” . In this section, begin with an NSString constant that is a tilde – the symbolic representation for your home directory in Unix. NSString *path = @"~"; Starting with that string, find a path method that will expand the tilde in the path to the full path to your home directory. Use that method to make a new string, and log the full path in a format like: My home folder is at '/Users/pmarcos' NSString has a method that will return an array of path components. Each element in the returned array is a single component in the original path. Use this method to get an array of path components for the path you just logged. Use fast enumeration to enumerate through each item in the returned array, and log each path component. The result should look something like: / Users pmarcos Section Hints: • With string convenience methods, a common pattern is to reuse the same variable: NSString *aString = @"Bob"; aString = [aString stringWithSomeModification]; Section 2: Finding out a bit about our own process Look up the class NSProcessInfo in the documentation. You will find a class method that will return an NSProcessInfo object. (In fact, you should find a very handy code sample there as well). From this object, you can access the name and process identifier (pid) of the process. Log these pieces of information to the console using NSLog in the format: Process Name: 'WhatATool' Process ID: '4556' Section Hints: • We didn’t discuss NSProcessInfo in lecture at all, so you aren’t missing any slides or notes. All of the information you need is in the NSProcessInfo class documentation. • Comparing the process info you logged with the prefix that NSLog generates can help verify you’re logging the correct information. Page 4 of 6
  • 5. CS193P Assignment 1B Winter 2010 Cannistraro/Shaffer Section 3: A little bookmark dictionary In this section, you will build a small URL bookmark repository using a mutable dictionary. Each key is an NSString that serves as the description of the URL, the value is an NSURL. Create a mutable dictionary that contains the following key/value pairs: Key (NSString) Value (NSURL) Stanford University http://www.stanford.edu Apple http://www.apple.com CS193P http://cs193p.stanford.edu Stanford on iTunes U http://itunes.stanford.edu Stanford Mall http://stanfordshop.com Enumerate through the keys of the dictionary. While enumerating through the keys, check each key to see if it starts with @”Stanford” If it does, retrieve the NSURL object for that key from the . dictionary, and log both the key string and the NSURL object in the following format below. If the key does not start with @”Stanford” no output should be printed. , Key: 'Stanford University' URL: 'http://www.stanford.edu' Section Hints: • Use +URLWithString: to create the URL instances. • NSString has methods to determine if a string has a particular prefix or suffix. Remember to log only those keys that start with ‘Stanford’. • The methods for creating and adding items to a mutable dictionary are located in the Lecture #2 slides. Remember that an NSMutableDictionary is a subclass of NSDictionary and so inherits all of its methods. • When using a dictionary and fast enumeration, you are enumerating the keys of the dictionary. You can use the key to then retrieve the value. NSDictionary also defines a method called valueEnumerator that returns an NSEnumerator object which will directly enumerate the values. You can use either approach. Section 4: Selectors, Classes and Introspection Objective-C has a number of facilities that add to its dynamic object-oriented capabilities.  Many of these facilities deal with determining and using an object's capabilities at runtime.  Create a mutable array and add objects of various types to it. Create instance of the classes we’ve used elsewhere in this assignment to populate the array: NSString, NSURL, NSProcessInfo, NSDictionary, etc. Create some NSMutableString instances and put them in the array as well. Feel free to create other kinds of objects also. Iterate through the objects in the array and do the following: 1. Print the class name of the object. 2. Log if the object is member of class NSString. 3. Log if the object is kind of class NSString. 4. Log if the object responds to the selector "lowercaseString". Page 5 of 6
  • 6. CS193P Assignment 1B Winter 2010 Cannistraro/Shaffer 5. If the object does respond to the lowercaseString selector, log the result of asking the object to perform that selector (using performSelector:) For example, if an array contained an NSString, an NSURL and an NSDictionary the output might look something like this: 2008-01-10 20:56:03 WhatATool[360] Class name: NSCFString 2008-01-10 20:56:03 WhatATool[360] Is Member of NSString: NO 2008-01-10 20:56:03 WhatATool[360] Is Kind of NSString: YES 2008-01-10 20:56:03 WhatATool[360] Responds to lowercaseString: YES 2008-01-10 20:56:03 WhatATool[360] lowercaseString is: hello world! 2008-01-10 20:56:03 WhatATool[360] ====================================== 2008-01-10 20:56:03 WhatATool[360] Class name: NSURL 2008-01-10 20:56:03 WhatATool[360] Is Member of NSString: NO 2008-01-10 20:56:03 WhatATool[360] Is Kind of NSString: NO 2008-01-10 20:56:03 WhatATool[360] Responds to lowercaseString: NO 2008-01-10 20:56:03 WhatATool[360] ====================================== 2008-01-10 20:56:03 WhatATool[360] Class name: NSCFDictionary 2008-01-10 20:56:03 WhatATool[360] Is Member of NSString: NO 2008-01-10 20:56:03 WhatATool[360] Is Kind of NSString: NO 2008-01-10 20:56:03 WhatATool[360] Responds to lowercaseString: NO 2008-01-10 20:56:03 WhatATool[360] ====================================== Section Hints: • When you ask various classes, such as NSString, for its class name, you may not get the result you expect.  Your logs should report what the runtime reports back to you - don't worry if some of the class names may seem strange, these are implementation details of the NSString class. Encapsulation at work! Page 6 of 6