PDA

View Full Version : Learning Xcode: Looking for references / examples




W5UXH
Apr 24, 2013, 11:55 AM
I am attempting to learn the fundamentals of how to build OS X (10.8.3) GUI applications using Xcode 4.6.2. I apologize for this long post, but I want to try to get across my current state of ignorance in the hope there might be some helpful suggestions out there.

I also need to learn Objective-C, but I suspect using Interface Builder to develop GUI apps will be the more difficult step for me. I have done a lot of C and assembly programming over the years but never any OOP. I recently moved to a Mac Mini from Windows and really like it a lot. On Windows I could never face trying to learn Visual Studio and C++ etc. I am now pretty determined to learn how to produce GUI apps on the Mac but have only been at it seriously for a few weeks. (At age 67 I am a slow learner!)

I have been browsing for examples and tutorials and stepping through a number of things. Most examples and tutorials I have found are from older versions of Xcode and too many are for IOS rather than for OS-X.

I have the Fifth Edition of Programming in Objective-C and have on order the 4th Edition Hillegass book Cocoa Programming for Mac OS X. The Objective-C book has very little Xcode information and I hope the Hillegass book might be helpful in that area.

I have a specific project in mind that I think will be useful to help me get into both Objective-C and Xcode in more detail once I get past the initial "brick wall" where I am currently stuck. I will try to describe my goal, but my terminology will probably be pretty poor.

This project will have two text view objects, one to type characters into and one to display information in. I need to be "first responder" (?) so I can receive and process keyDown events and take actions by displaying something in the second text view object.

I have found an example Xcode project that is very similar to what I have in mind: http://hayne.net/MacDev/TestKeyDownEvent/

but it comes from Xcode version 2.4 and I am unable to "translate" it sufficiently to duplicate the function under Xcode 4.6.2 with AppDelegate etc.

I have gone through the Apple Getting Started tutorial and mechanically followed the steps to drag from the XIB objects to the AppDelegate.h file and set up the Actions and Outlets etc. but with very little understanding.

If anyone can provide links to other tutorials, references etc. I will be very appreciative. An example project, built with Xcode 4.6.2 that responds to each typed character and takes some action would probably be my ideal resource since I think I could then experiment and use Xcode until I generate files with the same content and in the process hopefully come to understand the fundamentals. I have not yet found anything of this nature.

My specific target project involves controlling and communicating with an external device using a USB serial port and this library: http://blog.andrewmadsen.com/

I have run the example project and it works well, but I have a long way to go before I am ready to integrate it into my own project.

Thanks.



larswik
Apr 24, 2013, 11:56 PM
If you have C under your belt and have a good understanding of that then stepping in to OOP will be easier. I have written a couple programs on the Mac and have a few apps in the app store. There is not a big difference, in my opinion in the 2.

When I started to learn programming I started with Programming in Objective-C. I found it to be hard to understand and stepped back and learned C first. I was then able to get into Object C but it was still a struggle learning the concepts.

Start with simple tutorial in the book and redo the tutorials your own way. I think if you try and start with the project you will get lost, start with the basics. All the books will use xcode so you will learn that as you go to as you go a long.

It took me 2 years from starting with C and then to objective C before I had an app in the app store. I would also consider learning ios since there is SO MUCH stuff out there to learn from. Then it becomes easy to step into making Mac apps. The concepts and code are almost the same from what I have experienced.

But I would also stay away from any GUI to start, that is just another thing you will need to learn. I should also mention that when I was learning it was over a year until I made my first GUI. I wanted to get a good understanding of Objective C.

This is a good book: http://www.bignerdranch.com/book/objective-c_programming_the_big_nerd_ranch_guide

Also what helped me is to see videos and follow along. Lynda.com has good references too.

Lynda's videos: http://www.lynda.com/Xcode-4-tutorials/Objective-C-Essential-Training/77860-2.html?utm_source=google&utm_medium=cpc&utm_campaign=Search-Dev-Objective-C&utm_content=xOvO0vAH&utm_term=%2Blearn%20%2Bobjective-c&gclid=CLTThKiD5bYCFa9cQgod-jkA5A

This is of course is just my 2 cents and how I started learning.

W5UXH
Apr 25, 2013, 08:03 AM
I appreciate your comments Lars. I had not found the Lynda videos. I just watched the first part giving some Objective-C history. I will definitely start the trial and see how it goes.

Last night I did find one of the Mac Developer tutorials (TextViewDelegate) that looks like it is close to the nature of the example I am looking for. It responds to key events and takes an action in a very small program. So I will be trying to dig into that also as I continue studying.

Thanks.

Chuck


This is of course is just my 2 cents and how I started learning.

iphonedude2008
Apr 25, 2013, 10:25 AM
I would suggest against using interface builder at least while you are still learning. It limits your knowledge of what is actually going on which in turn makes it harder for you to solve problems and make good looking a GUI. Animation is also easier when you do everything in code. O

W5UXH
Apr 25, 2013, 10:47 AM
OK, that is two votes for staying away from IB for now. I am not sure if the way to do that is to use a terminal window and the CLANG compiler, or to use Xcode and a Command Line Tool application with the Foundation type?

I would suggest against using interface builder at least while you are still learning.

ArtOfWarfare
Apr 25, 2013, 12:52 PM
OK, that is two votes for staying away from IB for now. I am not sure if the way to do that is to use a terminal window and the CLANG compiler, or to use Xcode and a Command Line Tool application with the Foundation type?

No, it would entail instantiating your views in code and using methods like addSubview: to embed those new views in existing views.

iphonedude2008
Apr 26, 2013, 12:04 AM
No, it would entail instantiating your views in code and using methods like addSubview: to embed those new views in existing views.

Exactly. Although your code will be full of those annoying cgrectmake functions and addsubviews, you will definitely have a better understanding of ios and osx programming. It is also easier to support many devices that way.

ArtOfWarfare
Apr 26, 2013, 12:38 AM
Exactly. Although your code will be full of those annoying cgrectmake functions and addsubviews, you will definitely have a better understanding of ios and osx programming. It is also easier to support many devices that way.

You're probably putting those functions in the wrong file if you're finding them annoying...

iphonedude2008
Apr 26, 2013, 10:08 AM
What I mean is that it is annoying the time it takes to get the views in the right place, especially when the view has a transform or you are animating it.

dejo
Apr 26, 2013, 10:12 AM
What I mean is that it is annoying the time it takes to get the views in the right place, especially when the view has a transform or you are animating it.

The creators of Interface Builder probably found them annoying too! :D

iphonedude2008
Apr 26, 2013, 11:38 AM
The creators of Interface Builder probably found them annoying too! :D

Exactly. I wish interface builder actually generated code instead of an XML file. It would be much faster. That's why I code my views.

chown33
Apr 26, 2013, 01:16 PM
Exactly. I wish interface builder actually generated code instead of an XML file. It would be much faster. That's why I code my views.

It would then be impossible to replace a nib without recompiling.

Honestly, I've never noticed any big delays loading nib files, so I don't think creating interfaces in code is that much faster than loading a nib. Or did you mean "faster to create" rather than "faster to load at runtime"?

dejo
Apr 26, 2013, 03:16 PM
Or did you mean "faster to create" rather than "faster to load at runtime"?

If it's the former, I would disagree. I find it way faster to layout the UI in IB than hand-coding it.

iphonedude2008
Apr 26, 2013, 04:48 PM
If it's the former, I would disagree. I find it way faster to layout the UI in IB than hand-coding it.

It is faster to lay out, but I like the customization and control you have over coded views. Especially when making custom views.

iphonedude2008
Apr 26, 2013, 10:20 PM
It would then be impossible to replace a nib without recompiling.

Honestly, I've never noticed any big delays loading nib files, so I don't think creating interfaces in code is that much faster than loading a nib. Or did you mean "faster to create" rather than "faster to load at runtime"?

I have never had any start time in my apps, even when setting up complex layouts, loading complicated files, and doing 1000's calculations all before the app loads. Or maybe I'm just really good at multithreading.

Madd the Sane
Apr 27, 2013, 01:24 PM
It is faster to lay out, but I like the customization and control you have over coded views. Especially when making custom views.

As for custom views: if its a subclass of only NSView, you can put an NSView in the window, then change the class to your custom class. If you have a subclass of another view, do the same thing with the superclass then set the class to the subclass. However, on both cases, you can't change subclass-only parameters: you would have to do it on the viewDidLoad in the window controller.

Interface Builder (before it merged with Xcode) allowed the creation of custom views and editing their values via IB plug-ins. However, this functionality was lost in the move to Xcode 4 (IB wasn't garbage collected, while Xcode is) hopefully the move to ARC will mark the return of Interface Builder plug-ins.