Beginning cocoa programming: delegates

Xcode 3.2.2
Mac OS X 10.6.8
Cocoa Programming for Mac OS X (third edition)
Chapter 6: Helper objects
What happened to the forum software?  I can't quote text/code anymore.
I'm trying to create a simple delegate for an NSWindow.  The delegate implements this method:
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize;
I can get my delegate to work if I use Interface Builder to connect my app's main(and only) window to an instance of my object(which appears in the MainMenu.xib inspector in IB).  However, I cannot get a delegate to work if I call setDelegate: on my app's main window.  In the book, there is one example where they use setDelegate: to setup the delegate object.  There is another example where they use IB to hook up the delegate.  The only distinction I can detect between the two examples is that in the one that employs setDelegate:, the delegate-or is not a widget, and in the one that uses IB to make the connection, the delegate-or is a widget.
This is the code that I used to try and programmatically set up a delegate:
//AppController.h
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject {
  IBOutlet NSWindow* window;
- (id)init;
@end
//AppController.m
#import "AppController.h"
#import "MyDelegate.h"
@implementation AppController
- (id)init
  if (![super init]) {
  return nil;
  MyDelegate* aDelegate = [[MyDelegate alloc] init];
  [window setDelegate:aDelegate];
  return self;
@end
//MyDelegate.h
#import <Cocoa/Cocoa.h>
@interface MyDelegate : NSObject <NSWindowDelegate> {
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize;
@end
//MyDelegate.m
#import "MyDelegate.h"
@implementation MyDelegate
- (NSSize)windowWillResize:(NSWindow *)sender
                         toSize:(NSSize)frameSize
     frameSize.height = 2 * frameSize.width;
     return frameSize;
@end
In IB, I went into the Library, and I dragged an Object to the MainMenu.xib window/inspector, and I named it AppController.  Then I dragged a connection from the AppController outlet named 'window' to the NSWindow.  When I build&run my code, I can resize the window to any size--the window size is not constrained to a 2:1 ratio. That is not the result I expect: I expect the window size to maintain a 2:1 ration. If I set an object's delegate, then when the event occurs, the object should grab the delegate and use it to call the delegation methods; there is nothing more I should have to do in my code.  What am I not understanding about cocoa delegates?

I constructed another simple example of a delegate: I created an app with one lone NSTextField on the window.  I wanted to see if setDelegate: would work with a different widget(NSTextField v. NSWindow).  My goal was to see if I could setup a delegate using setDelegate: on an NSTextField, such that a delegate method would be called when I typed in the text field.  I  looked through the documentation, and I decided to to see if implementing this delegate method would work:
- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor;
I created a new app(deleting the classes that Xcode automatically creates, as well as the instance in the MainWindow.xib window in IB), and then I created this class:
//MyDelegate.h
import <Cocoa/Cocoa.h>
@interface MyDelegate : NSObject <NSTextFieldDelegate> {
- (BOOL)control:(NSControl *)control
          textShouldBeginEditing:(NSText *)fieldEditor;
@end
//MyDelegate.m
@implementation MyDelegate
- (BOOL)control:(NSControl *)control
               textShouldBeginEditing:(NSText *)fieldEditor
          NSLog(@"***In delegate method...");
          return YES;
@end
1) In IB, I created an instance of MyDelegate by dragging an Object from the Library onto the MainWindow.xib window.  I entered the name MyDelegate in the TextField Identity Inspector.
2) In IB, I ctrl-clicked on the NSTextField, and then I dragged a connection from NSTextField's 'delegate' outlet to the MyDelegate instance(in the MainWindow.xib window).
3) Saved everything, build&run, and when I typed in the text field, I saw the logged message in the Debugger Console, as expected.
Next, I attempted to create code that uses setDelegate: to achieve the same thing as above.
4) In IB, I ctrl-clicked on the NSTextField and deleted the connection from the 'delegate' outlet to the MyDelegate instance.
5)  I made these changes to the code:
//MyDelegate.h
#import <Cocoa/Cocoa.h>
@interface MyDelegate : NSObject <NSTextFieldDelegate> {
          IBOutlet NSTextField* textField;
- (id)init;
- (BOOL)control:(NSControl *)control
          textShouldBeginEditing:(NSText *)fieldEditor;
@end
//MyDelegate.m
#import "MyDelegate.h"
@implementation MyDelegate
- (id) init
          if (![super init]) {
                    return nil;
          [textField setDelegate:self];
          return self;
- (BOOL)control:(NSControl *)control
          textShouldBeginEditing:(NSText *)fieldEditor
          NSLog(@"***In delegate method...");
          return YES;
@end
6) In IB, I ctrl-clicked on the MyDelegate instance in the MainWindow.xib window, and then I dragged a connection from the outlet 'textField' to the NSTextField(in the app's main window).
7) I saved in IB, then build&run (save everything), and this time when I typed in the textfield, the message was not logged to the Debug Console.
What is the matter with setDelegate:?  Why doesn't setDelegate: succeed in setting up the delegate so that I can see the message logged to the console?
Thanks

Similar Messages

  • Cocoa programming on Intel?

    Ive just switched my programming development from Windows to Apple. As I'm new to the programming model of Mac OS X, I've started to use Cocoa, I've just currently released that the switch to Intel mean's Universal Binaries, sounds great but what does it exactly mean for the Cocoa programmer?
    In order for my code to be Universal, would I have to rewrite the entire code?
    My code will become near 90%-99% dependant on Cocoa programming model!
    Also I will intend to use specific code scripts that uterlize CPU instruction sets. So, shall keep on using Cocoa programming language, regardless of the computer architecture, or should I change the programming language, i.e. Darwin?

    Hi Haresh--
    According to Apple, Cocoa applications should be the easiest to make into Universal Binaries. I've converted one application of mine to Universal and tested it on an iMac at the local Apple Store. I just put in a couple of checks for divide by zero and that's about all I had to change in the code.
    This project was imported from CodeWarrior, and by far the most difficulty I had was figuring out what Xcode did with my plists and dealing with the text encoding of the source files.
    I've compiled a couple of other programs of mine as Universal Binaries, and for them, I haven't made a single change to the source code. But, I haven't tested them on Intel, so I'm not yet certain they'll run, though I'm pretty confident.
    However, I'm confused by what you mean in your last sentence about CPU instruction sets. Do you mean inline assembly? If so, I'm not sure about that, but I'd guess that won't work.
    charlie

  • Beginning Dialog Programming

    Dear Friends,
    I want to begin with dialog programming in ABAP. So, please tell me how to start & where to look out for the good examples. Please tell me about the examples in IDES also.
    Bye,
    Nishant

    Nishant,
    I found the book 'ABAP/4 Programming the SAP R/3 System' critical to my success when I started learning Dialog Programming 2 years ago.
    This book covers other issues as well, but there are a 120 pages devoted to the basics of Dialog Programming.
    It also covers ABAP Objects, reports, interactive reports, and building all types of dictionary objects.
    http://tinyurl.com/9a6t4
    Make sure to get 2nd Edition.
    Hope this helps,
    Brett

  • Beginning java programming in a course from home

    hi, i've recently started working on a java course, learning from home and am a bit stuck on what it all means really as my level of english isnt very good.
    it says i have to write a class to represent a calendar date, and then write a program that instantiates 2 of these date objects, initializes their member variables and print them out.
    Would someone please be abel to help me with an example of this,
    I would be so grateful!!!
    from
    waynemorgan86

    not compiled... not unit tested... but commented to the beejeepers.
    //DateStringExample is an example of a simple java class. It creates two dates,
    //initialises their member variables, and prints both values.
    class DateStringExample
         //the DateString class encapsulates all the variables and methods which
         //enable is to store a date as a String, and retrieve it again.
         private String DateString {
              //a "member" variable... note that it is private meaning that it is
              //visible only within the DateString class... so other classes can't
              //see it, allowing you to restrict access to this value, and validate
              //value when it is "stored".
              private String date;
              //a default contructor ("no arg" constructor) nb: if you don't
              //specify a default contructor java creates an empty one for you.
              DateString() {
                   //set the value of the date variable in this instance of the DateString
                   //class to todays date, which is the default value of a Date object.
                   this.date = (new Date).toString;
              //a "setter contructor" allows you to create a new DateString and
              //set it's value in one easy move.
              DateString(String date) throws Exception {
                   setDate(date);
              //a "setter" validates the supplied value and sets the member variable.
              void setDate(String date) throws Exception {
                   if (date = null) throw Exception("null date");
                   try {
                        Date tmp = DateFormat.parse(date);
                   } catch ( ParseException e ) {
                        throw new Exception("invalid date " + date, e);
                   this.date = date;
              //a "getter" returns the current value of the member variable.
              DateString getDate() {
                   return(this.date);
         //this is the special main method which java run's automatically when
         //you run the "program"
         public static void main(String[] argv)
              try {
                   //get me an instance of a DateString called today, which contains
                   //todays date (as a string);
                   DateString today = new DateString();
                   //get me another instance of a DateString called today, which contains
                   //tomorrowsa date
                   DateString tomorrow = new DateString("2006-09-20 12:46:00");
                   //output the two values
                   System.out.println("today is "+today+" and tomorrow is "+tomorrow);
                   //try to set tommorow to an invalid date, and print again
                   tomorrow.setDate("2006-02-31 00:00:00");
                   System.out.println("today is "+today+" and tomorrow is "+tomorrow);
              //catch any errors, and just report them to the standard error stream.
              } catch (Exception e) {
                   System.err.println(e);
    //NOTES:
    //* This whole class is obviously a complete waste of time, except as
    //      a simple example of a class to newbie java programmers.
    //* The Java language provides a rich featured set of classes for date manipulation.//and a few obvious bugs... hand this in as is and you will fail.
    corlettk: removed dodgy BadDateStringException, I think.

  • Beginning Swing programming problem

    My classmates and I are trying to write a simple Swing program with a single button and a text field that contains the number of times the button has been pressed since the program started. The problem is that in the ActionPerformed method, any changes to the text field ends up with multiple event errors. It will print the count fine to the command prompt, but not the GUI. Any insight would be greatly appreciated.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class CounterGUI extends JFrame implements ActionListener
         public int count = 0;
         Container contents = getContentPane();
         JTextField counter;
         final String temp = "Total times pressed: ";
         public CounterGUI()
              final int width = 300;
              final int height = 300;
              setSize(width, height);
              JTextField counter = new JTextField(temp + count);
              counter.setEditable(false);
              JButton clicker = new JButton("Click me!");
              clicker.addActionListener(this);
              clicker.setActionCommand("Click");
              contents.add(counter, "Center");
              contents.add(clicker, "South");
         public void actionPerformed(ActionEvent e)
              String command = e.getActionCommand();
              if(command == "Click")
                   count++;
                   counter.setText(temp + count);     
                   System.out.println(count);
         public static void main(String[] args)
         JFrame f = new CounterGUI();
         f.addWindowListener(new WindowCloser());
              f.setVisible(true);

    Hi Guys,
    The line JTextField counter = new JTextField(temp + count); is declared in the constructor, this means that the field counter is not visible to other methods and you'll get a null pointer exception (NPE) when you try to access the class field counter
    Change to counter = new JTextField(temp + count); Now if you were catching and displaying exceptions you'd notice that this was happening.
    Dave

  • Beginning Bluetooth Programming - Basic Stack Question

    I have moderate but not extensive experience with Java development, and have just stumbled across the javax.bluetooth JSR-082 packages. I'm interested in using these packages, but have a general question or two that deals just as much with bluetooth as it does with Java itself...if anyone could be of help, it would be much appreciated.
    Despite all the articles I've read, I'm a bit confused about the initialization of the bluetooth stack. My laptop has bluetooth integrated into it, is running XPSP2, and from what I can tell its now using the WIDCOMM driver. Does this mean that I have access to the WIDCOMM stack (ostensibly using the Broadcom SDK)? Or do I need additional software? I also keep reading that XP has included the Microsoft Bluetooth Stack...but nowhere do I read how to access it, nor any instructions, nor the beginning of instructions, for initialization of either the WIDCOMM or Microsoft stacks within the context of JSR-082. Any suggestions or input would be appreciated.

    See: http://developers.sun.com/techtopics/mobility/midp/articles/bluetooth1/

  • Compiling a Cocoa program and run - crash at startup

    Hello there!
    I've got a really strange problem. I've got two different macs (an iMac late 2008 and a MacBook late 2008). I've got on both Mac OS X 10.6.2 and XCode 3.2.1.
    On both the macs I downloaded the same sources of an i386 application. On the MacBook it compiles fine (configuration Release/Debug Mac OS X 10.6 i386) and starts as well as expected. On the iMac I compile it fine but when I start it, it crashes.
    Here is the crash log... CoreFoundation is the thread that crashes. Any idea? I've tried to reinstall XCode and its components, to uninstall and reinstall it... dunno what's the difference between the two configurations! Without considering I formatted both before installing Snow Leopard just to start from scratch.
    Any hing? Thanks
    http://pastebin.com/m55a16428

    Thanks
    Dunno WHY, but on the iMac it was crashing due to that method... I created two NSString and simply deleted the name method... something like this:
    NSString *sBehavior = [[behaviorPopup selectedItem] representedObject];
    NSString *sRoute = [[routePopup selectedItem] representedObject];
    NSString *status = [NSString stringWithFormat: @"%@ (%@). ",sBehavior,sRoute];
    Now it works on both the macs

  • Cocoa,mac-app development,objective-c programming books

    I have knowledge of C language and little bit of object oriented programming using Java.
    Recommend me some books for the topics that I want to learn are given below:
    1. Objective-C language learning course.
    2. Cocoa Programming using XCode 4
    Please recommend books that are readily available in India.
    Books that you recommend should have comprehensive knowledge of each topic. 
    P.S- I have gone through some of the pages at developer.apple.com on topics like objective-c.Still I require some more knowledge through books.

    If you're new to iPhone development, then you should definitely read this first:
    My First iPhone App, a Programming Tutorial.
    In a nutshell if you want to develop for the iPhone:
    You need a Mac Computer of some kind, Mac Mini, iMac, MacBook etc. You cannot develop for the App Store on a Windows or Linux PC.
    Join the Free iPhone Developers Program. This gives access to the SDK and Xcode development system which you download and install. It includes an emulator so you can test most apps except those which need hardware such as the camera or GPS.
    Pay $99 a year for access to the developer program. This lets you install apps on your own iPhone/iPod Touch/iPad. It also gives earlier access to betas and past versions of the SDK.
    Development Process
    So you've been developing away and have got a version that runs in the emulator. Next you've paid your $99 and been accepted in the developer's program. This means you can now try your app out on your iPhone. Here is an overview of how you do that. Apple's developer website provides a lot more detail.

  • Reading a text file into a program

    Hi
    First off I am new to this and know very little about Cocoa programming. I have followed some tutorials e.t.c. and can make basic applications but I have a project I am doing which requires more knowledge than I have.
    The problem: part 1
    I can make a basic 'Hello world' app that has a window and has text in it, but i want this text to be read directly from an external text file. I plan on using a heart rate monitor which will give me information via the serial port and i have written the appropriate applescript to write this data to a text file. I now want a basic cocoa application that will display the contents of this text file as to show the users heart rate.
    This is only the beginning but i figure it's a start, once i have this down i can move onto the real reason behind the project.
    Below is what i found in the ref library. I think it's what i need to be using but i don't know where to put it and where to define the text file that needs to be read.
    "stringWithContentsOfFile:encoding:error:
    Returns a string created by reading data from the file at a given path interpreted using a given encoding.
    *+ (id)stringWithContentsOfFile:(NSString *)path encoding:(NSStringEncoding)enc error:(NSError *)error
    Parameters
    path
    A path to a file.
    enc
    The encoding of the file at path.
    error
    If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, pass in NULL.
    Return Value
    A string created by reading data from the file named by path using the encoding, enc. If the file can’t be opened or there is an encoding error, returns nil."
    Below is my code i made using a tutorial. All it does it make a window appear with 'hello world' in it. The idea is to replace the hello world with the text in the external .txt file
    #import "HelloView.h"
    @implementation HelloView
    - (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
    // Initialization code here.
    return self;
    - (void)drawRect:(NSRect)dirtyRect {
    NSString* hello = @"Hello, World!";
    NSPoint point = NSMakePoint(15, 75);
    NSMutableDictionary* font_attributes = [NSMutableDictionary new];
    NSFont* font = [NSFont fontWithName:@"Futura-MediumItalic" size:42];
    [font_attributes setObject:font forKey:NSFontAttributeName];
    [hello drawAtPoint:point withAttributes:font_attributes];
    [font_attributes release];
    @end
    If anyone can help me it would be much appreciated
    Thanks
    Adam

    Hello,
    Well doing that way you just need to put another string in the "hello" container.
    Instead of - (void)drawRect:(NSRect)dirtyRect {
    NSString* hello = @"Hello, World!";
    /...../} you define "hello" another way
    - (void)drawRect:(NSRect)dirtyRect {
    NSString *hello = [NSString stringWithContentsOfFile:@"/Your/Path/Here/" encoding:NSUTF8StringEncoding error:NULL];//Assuming UTF8 encoding
    if ( ! hello)
    hello =@"Failed to load the string";
    NSPoint point = NSMakePoint(15, 75);
    NSMutableDictionary* font_attributes = [NSMutableDictionary new];
    NSFont* font = [NSFont fontWithName:@"Futura-MediumItalic" size:42];
    [font_attributes setObject:font forKey:NSFontAttributeName];
    [hello drawAtPoint:point withAttributes:font_attributes];
    [font_attributes release];
    The "if/else" was there to test successful loading of the file, and give you hints of why in case of failure but you can do without. I changed it so you just report an error occurred to user..
    All that said drawing strings in a window is more often done using a NSTextField in Interface Builder, if you wanna learn Cocoa maybe you should go that way.

  • How to start programming in os x or ios

    Hi Guys,
    Someone please can give me some advice or link or smtgh, if i want to start programming in os x?
    I really like apple's stuff
    Thanks,
    Peter

    First of all, you should be familiar with the concept of programming and software development. If that's the case, the next step is to become a good programmer in C or C++. As you know, C++ is a superset of C, with the ability to do object-oriented programming in advanced. It is the only language that helps you to gain a deep understanding of OO design and implmentation. There are a lot of books out there, but I recommend:
    1. Teach yourself C by Herbert Schildt.
    2. Teach yourself C++ or C++ from the ground up both by Herbert Schildt.
    3. The C++ programming language by Bjarn Stroustrup (The creator of C++).
    4. Learn C on the Macintosh by Dave Mark.
    5. Learn C++ on the Macintosh by Dave Mark.
    5. Objects, Abstractions, Data Structures and Design using C++ by Elliot B. Koffman and Paul A.T. Wolfgang. (A must read book)
    Knowing C/C++ is a great ability, as it allows you to develop software for any other platform you want, such as Microsoft Windows or Linux or anything else. In fact, the underlying structure of all operating systems used today, has been implemented in C or C++.  There is Unix operating system at the core of Mac OS X. So you can also make programs for Mac OS X using C or C++.
    The object-oriented API of Mac OS X is called Cocoa and Apple has chosen Objective-C at this level. This language is also a superset of C and is very powerful. It is a dynamic programming language as opposed to C++. Learning to program in Objective-C is not so hard, and it just takes some time to get comfortable with the syntax and the dynamicity of the language.
    If you learn to program for Mac OS X, then you can easily port your knowledge to iOS. There is also Unix at the kernel level of iOS, so there are a lot of similarities in both operating systems.
    There are a lot of books and resources to learn to program for Apple devices. You should know that after learning to program in Objective-C, which is nothing special other than doing OOP in C, you should learn about Cocoa, it's architecture, design, and huge class library used to create applications for Mac OS X. And to create apps for iOS, you need to be familiar with Cocoa Touch, the litle brother of Cocoa.
    My recommendation:
    Books:
    1. Objective-C for absolute beginners - Apress
    2. Learn Objective-C on the Mac - Apress
    3. Programming in Objective-C 2.0 - Adisson Wesley (recommended by most programmers)
    4. Learn Cocoa on the Mac - Apress
    5. Cocoa Programming for Mac OS X 4th edition - Adisson Wesley
    6. Cocoa Design Patterns - Adisson Wesley (Very important to read - it is about OO design patterns used in Cocoa)
    7. Pro Objective-C Design Patterns for iOS - Apress (I have not yet read it, but I think it is good)
    8. Beginning iOS 6 Development - Apress (There are a lot of books on iOS programming out there. I have not read this one yet, but I think it is good to take a look at.)
    At the end, you always have to use developer documentation provided by Apple, which is accessible through developer.apple.com web site.
    Hope this short brief introduction helps you.
    If there are anything you want to know, feel free to let me know and I will help you as far as I can.

  • Newbie help: learning programming on xcode

    Hi all!
    I'd like to start learning programming either in java as well as in C using my mac. So i've downloaded Xcode on my PB g4 10.3.9.
    I know there's a lot of tutorials online on java and C, and that's fine. The hardest thing, that i really cannot solve by myself alone, it is figuering out how to manage all files that I need to use for programming on Xcode.
    My question is:
    Is there a book somewhere, on amazon or free or wherever, where i can find a tutorial explaining step by step programming java or C using Xcode?
    So i can learn the programming tips and also how to manage them on Xcode, using my mac.
    Thank you for the attention
    Tom
    power book g4   Mac OS X (10.3.9)  

    C is a good first language because many other languages are based on it or similar. There's lots to learn with "just text," meaning applications that don't have buttons and windows and graphical user interface items. You learn about variables, constants, arrays, loops, conditionals, functions, pointers, data types, recursion, algorithms like searching and sorting, etc.
    You also might find a community college class or some other class that teaches beginning programming.
    The next thing to learn is some object oriented programming. C is not an object oriented language. Java, C++, and Objective-C are object oriented languages. Objects are are things that have instance variables (variables like ints or doubles or whatever that are inside the object and not so accessible to the rest of the program) and methods (functions that just work for that kind of object.)
    You might ask, well why not learn an object oriented language to begin with? You can, but it may be easier to learn basic stuff in a language like C first. Both C++ and Objective-C are supersets of C, meaning they include all of C and add some more. Java is very C like and adds more.
    If you're heading towards writing mac programs using Cocoa, Objective-C is good to learn because it is the most natural language for writing Cocoa programs.
    Then you can get a Cocoa book, like the one by Aaron Hillegass and learn about Cocoa. Cocoa includes buttons and windows and is not "just text."
    After you have learned so much about a computer language or two or three, it may be surprising that an API (application programming interface) like Cocoa is way bigger! No one can memorize it all. So you look stuff up in the documentation and search the internet and make little experiments to figure things out.

  • Yet another cocoa without interface builder post

    I am sure its been brought up before. I would like to know if its possible to write Cocoa apps without Xcode, Interface Builder, or NIB files in general; another words, write Cocoa programs programmatically using ONLY Objective C. Before you ask me why I would want to do such a thing and that I am crazy, please hear me out.
    I come from a Win32 background, and my primary languages are C and C++. I am getting used to Objective C (though I wish I could use C++ to program in Cocoa). I picked up a copy of Cocoa(R) Programming for Mac(R) OS X (3rd Edition) by Aaron Hillegass, and have been trying to learn cocoa from it for the last few months. Basically, I am having big trouble wrapping my mind around cocoa via the very conceptual high level approach this book takes. I can not for the life of me begin to understand this whole making connections with interface builder.
    I do NOT plan to write production applications in cocoa by hand, but if I could just write a few trivial applications in cocoa by hand without interface builder or nib files, perhaps when I do use interface builder, I won't have such a hard time understanding whats going on.
    Thanks in advance for the help.

    __mikem wrote:
    I am sure its been brought up before.
    I don't care. Your question isn't about learning how to program and learning via the iPhone SDK. I'll do anything I can for you
    I would like to know if its possible to write Cocoa apps without Xcode, Interface Builder, or NIB files in general; another words, write Cocoa programs programmatically using ONLY Objective C.
    Certainly. You can write command-line Cocoa apps. Xcode is just an IDE like Visual Studio.
    Before you ask me why I would want to do such a thing and that I am crazy, please hear me out.
    I come from a Win32 background, and my primary languages are C and C++. I am getting used to Objective C (though I wish I could use C++ to program in Cocoa). I picked up a copy of Cocoa(R) Programming for Mac(R) OS X (3rd Edition) by Aaron Hillegass, and have been trying to learn cocoa from it for the last few months. Basically, I am having big trouble wrapping my mind around cocoa via the very conceptual high level approach this book takes. I can not for the life of me begin to understand this whole making connections with interface builder.
    You specifically asked to avoid the topic, but I'm sure there are several of us who are really tired of iPhone questions who would be happy to try our hand at explaining the User Interface architecture in Cocoa - if you want to try.
    I do NOT plan to write production applications in cocoa by hand, but if I could just write a few trivial applications in cocoa by hand without interface builder or nib files, perhaps when I do use interface builder, I won't have such a hard time understanding whats going on.
    You can write Objective-C programs using whatever editor and IDE/makefile you want. You can even work with all the non-UI parts of Cocoa to get a feel of how it works. Technically, you could write code using only Carbon and never use Objective-C, but that is really a dead-end.
    A good idea might be start looking at doing writing MacOS X kernel extensions. You should still use Xcode, but only as an IDE. The code would all be C++ (or a subset thereof) with no user interface or NIB files. Realistically, that is probably harder than learning Interface Builder, but it is probably the most productive path available to you for developing MacOS X and avoiding Interface Builder.

  • Learning Programming on the Mac

    Hi All
    I have decided to learn programming and hopefully turn it into a career. This current economy is killing off my current trade. I would be starting from scratch as I have very limited understanding of programming, or the fundamentals. But I have a very strong Mac and general computer skills.
    From my research I've decided to learn C then C++. So I've picked up The C Programming Language Book (Dennis M Rictche) and Programming Principles and Practices Using C++ (Bjarne Stroutruup). As well I will be entering a collage course.
    I am giving myself about 3 months to get comfortable then start designing some software of my own creations. Plus creating software for other platforms.
    Software for the Mac is it necessary to learn Object C? And would only having a PPC Mac be a limitation of learning the languages, as this is all I have at the moment. It does run 10.5. I will install Xcode as well. Is there anything else in terms of setting up the computer to learn and create software that I need to do?
    Thanks

    Hey, Knitsu -- I know you've since asked this question in a separate thread (welcome to the forums by the way!), but I wanted to touch on one point that you mentioned here. By the way, good for you for looking up and old thread and reading through it -- not enough people do that before they post a new thread (myself included).
    but from my understanding, just looking up eduation learning in the toronto area, most schools have this object oriented programming and C learning for windows systems. Now would this be OK to learn, and still be able to use in the MAC environment IE: with Dashcode and Xcode?
    First off, Dashcode is just for developing Dashboard widgets, so that's the only thing you would be using that for -- Xcode is the main Mac IDE that you'll be using to develop your applications, in addition to Interface Builder. You write your code in Xcode, and you put together your GUI (graphical user interface) in Interface Builder.
    Secondly, to answer your question about learning on Windows and whether or not it will apply to Mac programming, the answer is yes, and no. As far as the C language goes, the answer is yes, more or less. If you take a class for learning C on Windows, what you learn will be directly applicable to Mac programming. The C language is the same language, whether you are programming it on Mac OS X or on Windows. That being said, there will be some differences in the overall experience of programming C on Mac versus on Windows. For that reason, if you take a class on C using Windows, I would buy a book on C programming on the Mac to read along with your course to help you apply what you are learning to the Mac. For this I would recommend the Apress book "Learn C on the Mac", since it is the best book for beginning Mac programming anyways, in my opinion (see my post in the thread you started).
    Now, as far as a class on object-oriented programming goes, your C class won't cover this, since C is not an object-oriented language. If you take a Windows-based class on OOP (object-oriented programming), it will probably teach it to you in the context of C++, if you're lucky, but more likely pseudocode. Pseudocode is code that simulates a real programming language, but it isn't -- it's just English words put together to teach you how programming works on a basic level. Personally, I think this is an absolutely horrible practice, since it tried to teach you programming without teaching you a programming language, which is not only less effective (for most people, in my opinion), but a waste of time as well, since that time could be going to learning a real language like C. Pseudocode might look like this:
    if this = that then
    write "this string"
    end if
    Something like that (I'm not a master of pseudocode -- I took one class on OOP that taught using it a ways back). Anyways, for this reason, it would be much better if you could find a class that taught OOP using a real language, which would probably be C++ if it was a Windows-based class. C++ is a superset of the C language, which means that it has everything C has plus extra (the "extra" here is object-oriented support, so C++ is kind of like an object-oriented version of C, although it also adds other features as well), and C++ is the OO version of C that Windows programming is likely to use.
    Now, Mac OS X allows developers to use C++ as well, but Mac has its own superset of the C language that it prefers you use instead of C++ -- it's called Objective-C. Objective-C is a superset (an extension) of the C language, much like C++, but the main difference (besides the fact that it's a different language) is that Objective-C, unlike C++, was designed with Mac programming in mind. For this reason, it would be best for you to go about learning object-oriented programming using Objective-C. However, the concepts you learn in a class on object-oriented programming using C++ (or even pseudocode) will still be applicable to Mac programming. The language won't be, but the concepts will be. In other words, you will still have to go back and learn OOP through Objective-C at some point, but the concepts you learned in your C++ or pseudocode Windows-based class will help you do so, since all OO languages revolve around similar concepts (objects, in particular).
    I hope this helped to answer some of your questions, and best of luck with your journey toward Mac programming!

  • Newbie to mac programing-orienatation needed, no technical question yet

    hi
    i want to build nice looking apps like rapidweaver for my engineering courses and was wondering where to start.....
    i have had one c++ course(no objective-c though) a couple of years back but in windows....and i am currently reading "learn c in the mac" form spiderworks.i am starting to remeber what i learned and learn new stuff..link here:
    http://www.spiderworks.com/books/learncmac.php
    where do you guys recomend i go after this?
    i read something a big nerd ranch course for cocoa programming....it's expensive 3.5k but i am sure it's worth it...
    has anyone done that course or have any other recomendations on wehre to go from here
    thanks a lot
    jtarud

    Hi!!
    You can even read things from apple; you can download pdfs and read something interesting.
    For example: http://developer.apple.com/documentation/Cocoa/index.html and start in the "Getting Started" part and "Fundamentals". These topics will give you a way to explore.
    You can learn Carbon also: http://developer.apple.com/documentation/Carbon/index.html for your C++ code.
    And then you can Mix Objective-C, C and even C++ to get your application flying!!
    Objective-C for the interface (usind Interface Builder) and Mix it with you C or C++ code for special behavior - this could be you model (in Objective-C policy!!).
    Hope i help!! C U!!
    iMac G5   Mac OS X (10.4.6)   + iMac G3

  • Learning Mac Programming and XCode

    I know how to program in PHP, currently learning Visual Basic in a college coarse, and am very interested in learning C++/Obj-C programming with Cocoa within XCode, but I do not know what books would be a good starting point. The only C programming I have ever done was back 14 years ago when I was in high school and never got into the old Classic Mac Toolbox.
    Does anyone know of a good book that is both a "learn how to program on the mac with XCode" and a good reference for the programming language itself? I have messed around with interface builder a bit and really like how easy it is to mock up the design, but the actual code logic is beyond me at this point and I would like to get deeper into it.

    Rod,
    there is no single book to teach you both. I would recommend the following books:
    1. Programming in Objective C by Stephen Kochan
    2. Cocoa: Programming for OS X by Aaron Hillegass
    After reading them, you will decide if you need a book on XCode itself.
    I am afraid C++ is a different kind of animal and you will need different books.
    Mihalis

Maybe you are looking for

  • Target for a .pdf  with the link target _blank does not open in a new window.

    I have a simple html document with links to .pdf documents all set to _blank but only one opens in a new window.  The others open as _self.  Changing the target doesn't seem to make a difference. Any idea as to why that is happening?

  • Where did my library go?

    My classic iPod tragically died. My son gave me his old Touch, reset to factory settings. I went to my iTunes account. All my music is gone, both bought from iTunes store and put in library from cd's. My computer's library had been deleted. DId this

  • Sync Async using proxies ( Calling Outbound proxy from Inbound proxy )

    I'm trying to generate Asynchronous Outbound message from the Synchronous Inbound message message  due to a requirement. My question is : is it really possible to develop such a scenario?. I'm getting weird error such as Kernal exception etc. Please

  • Does DVT  Tutourial work with latest Production JDeveloper?

    I got my brand spanking new Jdeveloper 11g installed, and I want to go through the Introduction to ADF Data Visualization Components Tutorial. I get stuck at the build of the schema, after following the instructions on buidling the schema step 5. I g

  • IPad and ebooks .epub which fonts trouble free

    Hi. Does anyone have a CURENT REFERENCE a LIST of FONTS that will work without problems on the popular tablets specifically iPads and kindles. I am creating an ebook -  an .epub file on my Macbookpro OS X 10.8 using inDesign CC. I searched the intern