How do I add a subview to a view - objective-c

I want to learn more about XCode, so I created an application that is intended for general desktop/laptop use, but not for iPhone.
It has AppController built on #include "Foundation/Foundation.h" and using files that I named AppController.h, AppController.m, and the MainMenu.xib file that was generated by the development system.
Now I want to add a subview. As I work though the problem, I'm obviously leaving out something or I'm incorrectly coding something. I can find many tutorials that provide a list of steps that are intended for iPhone applications, but none that fit my non-iPhone project.

Here's a chapter from Aaron Hillegass's book that shows how to do custom views and explains the view hierarchy.
There's also a "View Programing Guide" available on Apple's web site.
I'd very much recommend buying the physical book of "Cocoa Programming for Mac OS X" and going through each of the chapters and doing each of the practice apps. You might think it expensive, but it's absolutely worth every penny. It one of those resources I used way back when I wanted to become a hardcore Cocoa engineer.

Related

Creating a simple, single-view Quartz app

I'm an Objective-C newbie. Most of my experience is in Java. Also, I've never really used Xcode before and so I'm pretty new at that as well.
I'm trying to create a simple, single-view Quartz OS X app (not iOS) to display agent-modeling simulations. The graphics are pretty simple; just colored squares and grids. I have been looking at Quartz tutorials and I can see how I could accomplish this (as far as drawing things are concerned). What I can't find is an example that tells me how to tie it all together. What do I put in AppDelegate? Do I need a WindowController? How do I link that up with AppDelegate? I got as far as creating a Quartz Composer View in Interface Builder for my app, but I have no idea where to go from there.
As I mentioned before, I've looked for numerous tutorials but there is nothing that I can find that gives me information as far as linking everything together.
You should visit this web page before you do anything else. It will show you how a Cocoa application is structured and where the appropriate entry points are to place your code.
While the entire article merits reading, visit the section "Entry and Exit Points," which best addresses your particular questions.

What comes after learning objective-c for programming an ios device?

It appears the language is the same for either device ios or mac os on a mbp, but if I learn Objective-C in a tutorial, won't I also need to learn cocoa or cocoa touch to program effectively?
I'm not sure how to start on my path of learning to program an ios device. I know I need to learn objective-c and that appears to work on all apple products. Then do I move to cocoa touch for ipad and iphone? What comes after objective-c?
The type of project is akin to a web app but native objective-c app instead. Have ui, buttons, the app hits some back end location, returns data, I put it on that same ui. Only, as stated, use objective-c and whatever framework and library to do it (that's my dilemma. I dont know what to do next after objective-c).
thanks.
Cocoa and Objective-c go hand in hand. For getting started, I would suggest going over some old WWDC footage and following some of the examples there.
As far as Cocoa and Cocoa touch are concerned, they are very similar in many aspects, same name conventions, similar structure, etc. Learn one, and you can easily pick up the other.
#craig adds:
I would further this answer by also mentioning that Objective-C is a programming language, while Cocoa/Cocoa Touch are collections of frameworks that are provided by Apple, and used by developers to add functionality to their programs. (Which are written in Objective-C.) The Cocoa frameworks contain various UI components like buttons, table views, sliders, etc. in addition to various fundamental classes like NSString and other text- and graphics-based APIs
I started my learning by watching thenewboston's xcode tutorials:
you can begin with this one
Good luck :)
I prefer books for some strange reason and I found that the Apress series of IOS development is really good. The book goes through developing iPhone and iPad apps using all kinds of Cocoa libraries. There's a lot of good books out there on the subject; I would go find one that looks like it would suit your needs.

Porting from iOS to OS X

I have to port an iOS application to OS X. I have a little experience with iOS (although I didn't write the applications) and I would like have some suggests.
1) The application has some nice animations -- should I use Quartz to do them on OS X?
2) How can I change the View to have the same effect as the UINAvigationController on OSX? I searched for this component in the Object Library inside Interface Builder but I didn't find it.
This is liable to be quite an involved process, as (for example) none of the UIKit classes (currently) exist on Mac OS X.
As such, it's likely that you'll only be able to meaningfully retain the model level classes and that a substantial amount of the remaining code may need to be re-written.
My suggestion would be that you thoroughly prepare checklist that contains all tasks. It is not that simple as just looking for equivalent classes in Application Kit to UIKit classes.
it also depends on how app is written. If it has followed MVC properly, then complete files of business logic can be taken without any problems. If not, you will more or less write your new mac app from the scratch.
Yes, Core Animation is always a way to go in this cases, but it may happen that you'll encounter a lot of work because of possible different dimensions.
UINavigationController is something that doesn't exist on "normal" desktop interfaces. The closest equivalents are tab menus/tab sheets and you know how different they are.
If I were you, I would focus on binging content on the Mac, forget about interface concepts from iOS and rather make new interface concepts on the Mac that are compliant with Apple guidelines.

migrating an application from carbon to cocoa

I am working on an application in which I need to migrate the whole code of it from carbon to cocoa.I have experience in programming of C,C++,python and Java during my college time and internship but have never touched objective C or have done any programming for Mac(Carbon and Cocoa) before this.
So Can you please suggest me some sources to start with, also how should I go about the whole migration ?
After researching on net I have found that most the people have suggested following books
Cocoa Programming for Mac® OS X, Third Edition by Aaron Hillegass
Programming in Objective C - Stephen Kochan
I have got both these books.
Should I read them first and then should start with the code change? (it will take some time to read both of these)
OR
after having a decent fimiliarity with Obj C and Cocoa, should I directly get started with code migration?
Also,
since I don't know carbon , what should I refer to learn carbon to have sufficient knowledge to migrate the carbon code to cocoa?
First, learn Carbon so you can read the program and understand how it's currently implemented.
Install the Legacy documentation set in Xcode to gain access to the Carbon guides. You'll want to read the Carbon Overview, then Getting Started with Carbon, then everything that Getting Started links to. You'll also need to learn Core Foundation, which some of the more modern parts of Carbon use; read Core Foundation Design Concepts and the Memory Management Programming Guide for Core Foundation.
Then, learn Cocoa.
I didn't learn by the Hillegass book, but a lot of people swear by it. My current favorite Cocoa book is “Cocoa and Objective-C: Up and Running” by Scott Stevenson. The way I learned Cocoa was using Apple's own docs. Start with The Objective-C Programming Language, the Cocoa Fundamentals Guide, and the Memory Management Programming Guide for Cocoa. Much of the last document will seem really familiar, but skip nothing. Read every one of those guides from beginning to end and all the way through.
Once you've learned Cocoa's general concepts, you can move on to more application-specific material. Start with the Application Architecture Overview and most of what that document links to. The Cocoa Guides list has the full list of guides.
Down the road, you'll also need to make the application compatible with 64-bit mode. If you still have any Carbon code by that point, you'll need to read the 64-bit Guide for Carbon Developers; either way, you'll also need the general 64-bit Transition Guide and the 64-bit Transition Guide for Cocoa.
I am working on this process myself right now, and it's a fairly complex undertaking for a full document-based application that uses a few frameworks. My Carbon app has dozens of menu items, the interface is built with Carbon Nibs and implemented using Carbon event hooks. The programming language is C++. Going back in history, the original Mac classic version was implemented in straight C, so there's a little bit of legacy from that era too. Resource-based PICS for example!
There are several approaches one can take, so it depends on your particular situation how to proceed. In my case I decided to start with a bare Cocoa document-based project and start building the document loading code, because the hooks for that are already in place in the empty project. This seems like a good place to start for me, because it gets me into the mode of working with Cocoa and thinking about the app in terms of smaller pieces.
You really have to take a methodical approach and look at what your app depends on in Carbon versus which parts of your app are independent - for instance your abstract classes. If your app is in C++ there may be some pitfalls with converting over to pure Objective-C. Operator overrides can be tricky to notice, for example.
You can mix C++ with Objective-C, as described in Apple's Carbon-Cocoa Integration Guide and around the web you can find plenty of C++ wrappers for Cocoa foundation objects like NSStrings. So if you already have C++ classes that wrap CFString, these can come in handy.
Generally-speaking, you can leave your data storage just as it is. If you use malloc() and calloc() to make a linked list of structs, there's no special reason to move over to an NSArray. You won't get better performance. The real change comes in the interfaces, the way you call and access that data from other objects. If you decide to mix C++ and Objective-C objects in the same app it helps to encapsulate as much as possible. That is, as much as possible make your abstract C++ classes only refer to their own data and that of other C++ objects. Eventually this will make it easier to transition them to Objective-C.
If you're transitioning from one event model to another or from Carbon port-based imaging to Cocoa's views-based imaging, it's probably best to start with a fresh Objective-C app and bring over your model classes first. Add some test functions to make sure they all work within the new language. If your app is anything like mine (old) then it probably needs to display some things larger, and to have more polish in the interface. This is a good time to rebuild those parts piece-by-piece.
There's definitely no great shortcut. The PDF linked above is the best document I've found on the topic.

Idiomatic, classy, open-source examples of Cocoa Interfaces?

Greetings, I'm currently learning Cocoa and Objective-C. I've run through "all" the tutorials and I'm fairly comfortable with the ObjC language. What I'm looking for now is to learn Cocoa idioms and see real code used in nice-looking Cocoa apps.
It seems like serious apps (iTunes, etc.) don't just drop in the IB elements. They do a lot more with code to tweak them to look good. (Example: the iTunes playlist drawer. How does one go about getting that styling?)
Here are some examples of nice UI's that are open source that I've found:
Smultron (current home, open-source fork)
Transmission
Vienna
Gitnub
Any other suggestions on Open-Source apps that have great Cocoa user interfaces?
You might want to look at BWToolkit, by Brandon Walkin. It's pretty awesome, containing an elegant collection of UI elements and other objects. The source code is provided so you can see how custom controls and views were created.
Brandon even provides some walkthrough movies, such as "Creating an iCal interface in 3 minutes."
A few other open source apps to dig into are Camino, Colloquy for both Mac and iPhone, Adium, and Quicksilver (lots of UI customization).