iPhone Programming Question - Stanford iTunes U Help

Discussion in 'iOS Development' started by TechnoEagle, Feb 3, 2010.

  1. TechnoEagle

    TechnoEagle Member

    Joined:
    Jan 2, 2010
    Messages:
    169
    Likes Received:
    0
    Device:
    4G iPod touch
    I have just started trying to learn how to develop iPhone/iPad apps. I have been using the Stanford lecture videos on iTunes U, and have learned a lot so far. I did come across a problem while doing homework assignment 1B. I can't seem to figure out how to get it to work. Has anyone either watched these videos, or just knows a lot about Objective-C? If someone could post the code for the assignment so that I can figure out what I was doing wrong, that would be great! The homework assignment can be found at http://cs193p.stanford.edu As I said before, it is assignment 1B that I cannot figure out.

    Here is the code for my implementation file:

    Code:
    #import <Foundation/Foundation.h>
    void PrintPathInfo()
    {
    	NSString *path=[@"~" stringByExpandingTildeInPath];
    	NSLog(path);
    }
    void PrintProcessInfo()
    {
    	NSString *infoAboutProcess=@"Process Name: ";
    	infoAboutProcess=[infoAboutProcess stringByAppendingFormat:[[NSProcessInfo processInfo] processName]];
    	infoAboutProcess=[infoAboutProcess stringByAppendingFormat:@" Process ID: "];
    	infoAboutProcess=[infoAboutProcess stringByAppendingFormat:[NSProcessInfo processInfo]];
    	NSLog(infoAboutProcess);
    }
    void PrintBookmarkInfo()
    {
    	
    }
    void PrintIntrospectionInfo()
    {
    	
    }
    int main (int argc, const char * argv[]) {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
        PrintPathInfo();
    	PrintProcessInfo();
    	PrintBookmarkInfo();
    	PrintIntrospectionInfo();
    	
    	[pool release];
        return 0;
    }
    For the PrintPathInfo() method, I cannot figure out how to separate each part of the path directory onto a separate line. For the PrintProcessInfo(), I keep getting weird errors and cannot figure out what to do. I haven't even started to work on the PrintBookmarkInfo() and PrintIntrospectionInfo() yet, because I want to get the first two methods working, first.
    Thanks in advance!
  2. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    [objc]
    void PrintPathInfo() {
    // print each directory of <home-dir> path on separate line
    NSArray *directories = [NSHomeDirectory() componentsSeparatedByString

    Please Register or Log in to view images

    "/"];
    for (int i = 1; i < [directories count]; ++i)
    NSLog(@"%@", [directories objectAtIndex:i]);

    }

    void PrintProcessInfo() {

    NSLog(@"Process Name: %@\tProcess ID: %d", [[NSProcessInfo processInfo] processName], [[NSProcessInfo processInfo] processIndentifier]);

    }
    [/objc]

    I haven't tested that code, but it should be fine, unless I made some sort of misspelling.

    EDIT: You really should learn Objective-C before struggling too much with things like this.

    EDIT 2: If those functions are to be used by users (not for debugging purposes), you may want to use printf() or puts() for standard output.
  3. TechnoEagle

    TechnoEagle Member

    Joined:
    Jan 2, 2010
    Messages:
    169
    Likes Received:
    0
    Device:
    4G iPod touch
    Thank you so much! Could you also post your code for the other methods? I tried them, but still don't know enough to be able to get them.

    Please Register or Log in to view images

  4. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    I don't even know what they are supposed to do. Besides, I'm not going to do everything for you.

    Please Register or Log in to view images



    btw, the name 'method' refers to a subroutine of a class. 'function' is what we are dealing with now. </pedantry>
  5. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    The courses assume that you know Objective-C. They are NOT designed to teach you Objective-C, but rather to show you some the iPhoneOS API (mostly UIKit).

    I'm not meaning to sound condescending, but you should really take a few lessons in Objective-C before continuing the iPhoneOS courses. What you are trying to do is basic, basic, Foundation API. There literally is a one line command to do that.

    Again, I apologize if I come off sounding rude, as that is not my intent.


    EDIT: I guess part of my tone is that I *really* dislike the Stanford course. It is a complete waste of time and teaches you nothing; it barely scratches the surface of anything. You'd be much better off purchasing a good book. The students' final projects are all garbage as well. That is *not* their fault, it's the course's fault.
  6. Unregistered

    Unregistered Guest

    Stanford lectures

    Hi SkylarEC,

    I'm currently finding the Stanford lectures exceptionally helpful. I've been reading tutorials online, trying to jump in and then research problems when I stumble across them, and simply using the Apple documentation. All of these are good methods but seem to be slow going, and to be honest I wasn't making as much progress as I wanted and it was quite frustrating.

    I started the Stanford lectures yesterday, and after just the first two lectures a number of things 'clicked' for me - some basic Objective-C stuff (the second lecture is objective-c and I believe other future lectures will be primarily objective-c as well), but primarily a lot of interaction involving Interface Builder. I think that the reason for this is Interface Builder is graphic and involves a lot of clicking, selecting, and dragging. This is much easier to see in a video than imagine from a written description. (The problem of written instruction is made worse by different versions of XCode and different versions of the iOS SDK, when a minor change would be insignificant to an experienced developer but is a huge hurdle to a beginner)

    In summary, I think the Stanford lectures are great. They remove the need of buying a book. Further, a book is often not quite up to date simply due to the time required to write, edit, and publish - I just went to a local bookstore and they only had a book on Objective-C 2.0. Have you viewed the lectures on iTunes? They are just like the lectures I remember from school - and I would hate to be a paying student, but you can't deny that there is a lot to be learned from them.

    Of course, a successful graduate of the course is not automatically a good iOS developer - and they are still a beginner. But they are a beginner that has had some textual / visual / audial guidance into the very elementary aspects of iOS. A student at that level - having the foundations, or at least knowledge of the foundations - would be able to research and teach themselves most advanced topics.
  7. NolesFans

    NolesFans New Member

    Joined:
    Sep 23, 2008
    Messages:
    404
    Likes Received:
    0
    Device:
    iPod touch
    I did look at some Stanford material, It doesn't help you to understand what is X is doing.

    By doing everything in Interface builder, it is not going to help you to be better iOS developer because it is doing works for you.

    Actually the "Objective-C 2.0" book is latest update for the language.
  8. Unregistered

    Unregistered Guest

    Maybe you are looking at different Stanford lectures. I am currently reviewing lecture 3, "Custom Classes, Object Lifecycle, Autorelease & Properties"

    It is assuming I know OOP but is explaining the objective-c syntax and any differences from C++ / Java etc.

    Sorry if I gave the impression that it tried to 'do everything in Interface builder'. That is not the case. Interface builder is a useful tool for - surprisingly - Building Interfaces. In most cases it is going to be the most productive way to create interfaces. It makes a lot of sense to teach how to use it.

    The lecturer is an engineer at Apple and is involved in development there. I think he is quite good.
  9. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Unregistered Guest, I watched the videos before I made my judgement. I still stand by my opinion that they are a waste of time. The don't go into any depth on any topic. If you follow through with all the videos, the only thing you will learn is how to make the same garbage that is already flooding the AppStore. If you want to make quality apps, those lectures are not the way to go.
  10. bgizzle

    bgizzle Administrator Staff Member

    Joined:
    Sep 13, 2007
    Messages:
    5,100
    Likes Received:
    543
    Device:
    iPhone 6
    As someone who is taking the class in person at Stanford, I must say that the lectures don't go very deep but serve as a great starting point. The real value is talking to the lecturer before class and getting some really good feedback on questions that go much deeper. Of course, that's not included in the videos so its of no help to people that are watching online. I think that the audience for the class, at least among Stanford students, is people who are already familiar with some CS concepts and languages like Java (most likely or C), and need a "map" of the libraries and basic functionality that UIKit, CoreGraphics, CoreData, etc.. The point of the class and lectures is to give you an idea of what is available, and then you can dig deeper on your own by using the documentation. For my part, I've been wanting to get into all of this but have simply been to busy to sit down and force myself to research all the libraries. Someone curating it into lectures that point out the key points is very valuable, because it takes away the barrier of having to sift through a ton of information and figure out what's important and what's not. The projects are also very helpful in this regard. I don't know how all of this plays out for the internet audience, but that's just my two cents.

Share This Page