Re: Writing Cocoa apps w/o using Interface Builder
Re: Writing Cocoa apps w/o using Interface Builder
- Subject: Re: Writing Cocoa apps w/o using Interface Builder
- From: Simon Wilson <email@hidden>
- Date: Sat, 30 May 2009 20:24:44 +0200
Hi Jonathan,
> Could someone please post a "HelloCocoa" equivalent to this Java
program:
This kind of question is probably better directed at the Cocoa mailing
list.
However, these are the simple steps required to do this without *any*
code, i.e. using IB the "Cocoa way":
1) Create a new Xcode Cocoa project (select "Cocoa Application").
2) Open MainMenu.xib in IB and open the main window
3) Drag a button to the center of the window. Double click the button
and change the text to "Look, No Code!".
4) Hold down the control button and drag a connector from the button
to the "First Responder" object in the nib window. Select terminate:
from the displayed list of selectors.
This should take all of 30 seconds.
Build and run the app. This app is functionally equivalent to your
Java app. It presents a window on start up with a single button which
closes the application when clicked.
> I got so angry with Xcode/IB because this Apple seemed to have
nerfed this possibility with the way they architected Cocoa.
You got so angry with Xcode not because Apple "nerfed" up the
architecture of Cocoa but because you haven't understood the concepts
and have became frustrated.
Trust the voices of the many people on this list that have taken the
time to respond to your postings and invest the necessary time to
investigate Xcode, IB and Cocoa. You might just find that the tools
are better designed and more able than you currently assume.
Recommendation:
If you're familiar with IoC and dependency injection then thinking of
IB as a visual editor for an IoC/dependency injection container may
help. If you are not familiar with the concepts of IoC and dependency
injection then reading up on these concepts/patterns (which have
nothing to do with Apple) may help you better understand why IB and
Cocoa are designed the way they are.
One addendum to Gwynne's code:
From a quick view of the code it doesn't appear that clicking the
button will result in the window closing. Add the following 2 lines to
applicationDidFinishLaunching: to achieve this:
[button setTarget:window];
[button setAction:@selector(performClose:)];
Apologies to Gwynne if I overlooked something...
Regards,
Simon
On May 30, 2009, at 19:01 PM, Jonathan Mast wrote:
Joar,
I haven't really tried creating a Cocoa app programmatically. What I
saw in the iPhone tutorial about doing such seemed to required quite a
bit of boilerplate code. I guess that was IB is supposed to shield us
from ;)
Finlay,
I agree that Objective-C is a better choice than C++. I would really
like to learn it's SmallTalk-based syntax the same way I taught myself
Java: with simple, programmatic GUI programs. This approach is very
rapid and allows to one to learn any language (not just the GUI
framework) very quickly. I got so angry with Xcode/IB because this
Apple seemed to have nerfed this possibility with the way they
architected Cocoa.
Everyone,
Could someone please post a "HelloCocoa" equivalent to this Java
program:
<code>
package example;
import javax.swing.*;
public class HelloJava {
public static void main(String[] args) {
JFrame jf = new JFrame();
JPanel jp = new JPanel();
jp.add(new JButton("Hello Java!"));
jf.setContentPane(jp);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.pack();
jf.setVisible(true);
}
}
</code>
The only this program does is create a window with a clickable button
in it.
Thanks
On Sat, May 30, 2009 at 11:30 AM, colo <email@hidden> wrote:
If your making a game or a custom interface you have no option but to
learn how to program an interface without IB
other than creating the first UIView controller in IB it's stupid not
to know how to do it by code.
Unless your just making a normal table based app you have no choice as
my experience learning it has gone about.
On Sat, May 30, 2009 at 7:12 AM, Finlay Dobbie
<email@hidden> wrote:
> On Fri, May 29, 2009 at 10:06 PM, Jonathan Mast
> <email@hidden> wrote:
>> No offense taken, Seth. I figured out the issue and indeed it was
a missed
>> connection in IB. And while my previous comments were hyperbolic,
I still
>> think Apple could have done better with Cocoa/InterfaceBuilder.
Either they
>> could have made IB more intuitive and/or Cocoa easier to manipulate
>> programmatically. I just expect more from Apple I guess.
>
> I actually found IB to be far more intuitive than most other
> environments. Similarly, I find that Objective-C is much simpler and
> more intuitive than C++.
>
> Much of the initial griping and whining about the Apple environment
> ("OMG THESE SQUARE BRACKETS ARE UGLY", "IB IS BROKEN", "COCOA IS
> UNINTUITIVE" etc) come down to the fact that it is different from
> whatever previous environment you were used to. However, this is not
> really Apple's failing: there are often good reasons why they have
> approached things differently. These may not be immediately obvious
> whilst your brain is still contorted into weird shapes from dealing
> with environment X or environment Y.
>
> Good engineers accept that there are differences between environments
> and languages, new concepts to be learned, and new applications of
> existing concepts to discover. The best engineers see this as an
> opportunity, not a burden.
>
> -- Finlay
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Xcode-users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden