port an iOS (iPhone) app to mac? - iphone

Is there a preferred way to go about this?
The app in question is not too large . . . single-player game that I wrote over the course of a couple of months.
EDIT: I should add that I have no experience with mac development . . . outside of what comes naturally with being an iOS developer.
EDIT: Classes heavily used in the game: subclasses of NSObject, UIView, and UIViewController. I don't know much about NSView, but I'm pretty sure all the UIView stuff will work in that class. Also some use of UITableViewController. I do also have Game Center, but I can leave that part out for now. There is no multi-touch.
EDIT: My graphics is all stuff that is in the QuartzCore and CoreGraphics frameworks. I do have a moderate view hierarchy.
EDIT: If you are doing such a port, you may also be interested in the issue of memory management

There's no easy way. It's that simple. Depressingly, you simply have to become good at programming the Mac.
"I'm pretty sure all the UIView stuff will work in that class" -- unfortunately, no. Everything is different that enough you have to work hard.
It's not a fun gig. Make sure you really, really think it's worth it financially.
Apart from anything else, be aware of the "sibling views don't work on OSX" problem if you stack up a lot of views in your iOS app. Essentially, you will have to change to using layers (instead of simply views) on the Mac if you rely on nested hierarchies of views here and there on the phone!
Click this link: Is there a proper way to handle overlapping NSView siblings? for the gory details on that particular problem!

http://chameleonproject.org/ UIKit for Mac
from Iconfactory is worth checking out.
"Chameleon is a work in progress. The framework currently implements about 60% of UIKit after nine months of work."
https://github.com/BigZaphod/Chameleon

You may have a lot of work ahead of you. While purely algorithmic classes will port without any change, anything that touches UIKit will likely need to be rewritten, or heavily adapted. The UI class design pattern on OSX is that of a relationship between views, where your code is responsible for managing controllers; while on iOS it is one of a relationship between view controllers, where view management is implied.
Of course, as BoltClock mentioned, you have the issue of interaction. Since touch no longer works, you will probably need to work on your interaction model first, even before you start porting.

There exists an open source (BSD) UMEKit library that may help with porting a few UI classes, but you may have to rewrite a fair amount of the UI to better handle the mouse/keyboard/multi-window/menu GUI environment. Basic NSObjects, and some Open GL and Quartz graphics rendering, may port with only minor touch ups.

As others say, porting can be a chore. The general techniques work, though. You redesign the interface in Interface Builder (where applicable) and check what the different controls are called (CocoaTouch only has a small subset of typical desktop controls). UI* typically becomes NS*. Tableview delegation is similar, so it will probably be easy.
I'll have to recommend the Aaron Hillegass book as usual. It's a great introduction to Mac development, and knowing iOS development gives you an edge.
Since it's a game, you probably need to consider how to do fullscreen mode. The game doesn't necessarily take up the entire screen anymore, and you shouldn't force it. A whole new set of preferences will now be necessary. There is of course some "fun" involved now that there are new ways to handle resolution listing/changing with Snow Leopard (with the previous ways giving you deprecation warnings).
Just accept that there will be a possibly lengthy transition period until everything "clicks" :)

Related

Pros and cons of using XIBs and doing views programmatically

I want to decide if it is better to use XIBs or to designs my views completely using code.
So far I have read that when you design your views on interface builder they are pre-built, so even if they use more memory the user feels everything is faster.
People say doing everything using code is harder but I find it to be just as easy, so I want to know if anyone has experienced some real speed gains when using nibs.
What have been your experiences, advice, etc?
Thanks!
You should be able to do both -- there are times when building a view programmatically is better/easier, and times when using a .xib is better/easier. Even if you only ever do things one way, you'll run into code that does it the other, and you'll need to be able to deal with that.
If you don't know how to use IB, then building your views in code is certainly easier. That is why you should learn to use IB. Once you understand IB, it's way, way faster to put together most of the view-based UI your app will likely need. IB helps you line things up, center objects, align base lines, connect controls to their targets and actions, etc. I think it's safe to say that everyone who uses IB effectively experiences "real speed gains when using nibs."
You should know how to use both. Performance differences between the two are negligible and should not be the reason that you choose one or the other.
Many people who are new to iOS development have the misconception that nibs (.xib files) are inferior to programmatically creating your UI and that if you use IB you're not a good iOS developer. That view is 100% wrong. IB is created by Apple and in use by Apple's developers to create their own Mac OS X and iOS apps. If IB (as a tool) is good enough to be used by some of the best developers in the world, it's probably good enough for most of us.
In practice I have found that a combination of the two usually fits the bill.
In my own apps I find that .xibs are great for laying out the basics of your views quickly and they allow you to iterate very quickly while giving you a preview of what your view will look like. It's also much easier to use auto layout in a .xib file.
Then when you need to do more advanced things like add fancy animations or move views around that is what IBOutlets are for. Anything that you put into a nib can be referenced through an IBOutlet. This allows you do then programmatically make your view come to life.
Lastly, you should fully understand what a nib (.xib) is doing automagically for you. You should understand what happens when a .xib's objects are unfrozen. There are many resources on the internet to understand .xib files better.
Also, learn how to use .xibs in an encapsulated way. For example, .xibs are crazy useful for things like prototype cells and they allow you to keep your code base modular (much more so than storyboards). Also, you will require less UI code in your view controllers.
Lastly, I always say that people should think of IB/.xibs like jQuery. It's going to save you a lot of time but the best developers still know how to do everything in javascript if they have to.
Good luck and have fun!
TL;DR version
Performance is not a consideration when deciding to use .xibs or not.
Use .xibs because they give you a preview of the view you are creating and they allow you to quickly iterate
In practice most apps will use a combination of both. You will programmatically add animations or move views around but the .xibs will be a starting point
Understand fully what happens when the objects in a .xib are unfrozen
You'll be more productive but be sure you fully understand what is happening behind the scenes.
I would always use XIB files unless there was a reason not to. This allows your views to be maintained easily in the future.
Some reasons for creating the views programmatically might be:
A control needs to be resized,
repositioned or otherwise altered
depending on something else
Controls
need to be added or removed
dynamically
There may be more reasons but there are not too many.
If you programmatically create views when there is no need you make it a lot more difficult for other developers to try to figure out what the view will look like and to change it.
If you build your views programmatically, you have control over the loading of elements. e.g. you could use lazy loading, and load secondary buttons, subviews, etc. a fraction of a second after the more important elements, allowing the key parts of the UI to come up faster. You could even animate some elements into position.
If you use IB, you get guides as to proper element spacings and positioning, but you could always copy the coordinates from IB into code if you aren't changing the design that often.
For simple UI elements, you will end up with more lines of code to maintain if you create them programatically.
IB and NIBs do a lot to optimise loading/unloading of views, but it is largely oriented to minimising memory usage vs. perceived speed for the user. For example, lazy loading if anything might make the app UI slightly slower, but it should make memory usage lower. This in turn could make overall app performance better on a large application, and is very much encouraged, but it's difficult to define "performance" in a narrow way. It's also difficult to say when you should or should not use IB - there will be some times you're much better off doing it in code.
One often overlooked element to the IB or not debate is development speed, especially if you have multiple developers. On a larger team/project you'll probably have some developer(s) who specialise more in the infrastructure, business logic etc. of the app and some developer(s) who specialise more in the UI. In this case, use of IB will make it easier for them to work independently, which should make overall development more efficient.
I view IB as a core part of the development platform for iOS development. It's not the right solution in every situation but not knowing how to use IB will be a real limiting factor.

Tips for Rapid iPhone/iPad Development

For my job, I've been writing an iPad application that the user can enter data into, view some pictures, etc. It's been annoying me that I'm reaaaallly slow at writing in Obj-C and I find myself bogged down in the UI (an example would be I always have to put in a UITableView which is time consuming...) I think that I have a pretty good handle on the language and Apple SDK.
Does anyone have any tips regarding how to speed up the development process from a UI perspective? Are there alternative tools to xCode and IB? Are there libraries with classes that are faster to program w/? Anything is appreciated,
mj
Interface Builder can already speed up your development considerably if you learn to use it. For example, see this custom table cell with IB tutorial.
For example, at my current employer I've seen a Cocoa Mac OS X app where the settings dialog was done completely in IB... there was no code for modifying or sync'ing the values in the NSUserDefaults with the interface elements, everything was done in IB.
Also, see this interesting article: Striking the Balance: Interface Builder vs. Code.
Avoid UITableViewController if you aren't already.
For speeding up TableView dev, I always keep a pretty generic implementation of TableView handy that I can copy and paste snippets from.
If you are constantly doing TableViews for different object types, try using Protocols to make the implementations more uniform.
Don't be afraid of UIViews as subviews as opposed to constantly using UIViewControllers. Sometimes a VC is just an extra layer of complexity that you don't need.
My experience is that the biggest thing you can do as an iPhone developer to become more efficient is to know when and when not to use Controllers as opposed to Views when doing complex interfaces.
Wish I could be more specific but your question is a little vague... there's nothing wrong with Interface Builder, it's just a steep learning curve.

Good reasons why to not use XIB files?

Are there any good reasons why I should not use XIB / NIB files with an highly customized UI and extensive animations and super low memory footprint needs?
As a beginner I started with XIB. Then I figured out I couldn't do just about everything in them. It started to get really hard to customize things the way I wanted them to be. So at the end, I threw all my XIBs away and did it all programmatically.
So when someone asks me if XIB is good, I generally say: Yeah, if you want to make crappy boring interfaces and don't care too much about performance, go ahead. But what else could be a reason not to use XIB?
Am I the only iPhone developer who prefers doing everything programmatically for this reasons?
I think that Interface Builder is one of the biggest assets of Mac (and by extension, iPhone) software development. GUIs are visual; why not create them using a visual interface? IB is flexible enough that you can lay out an interface using its "generic" components, and then subclass them where necessary. Sure, if you have a unique interface you're going to have to subclass a view class and perform custom drawing, but you can also lay out your interface in IB and then easily use the inspector to switch the class to your custom subclass.
Honestly I think it's a spectrum of convenience. If you are comfortable writing everything in code then go for it. If you design your project well then it should be about the same amount of work creating new windows, etc. But I know that a lot of people aren't as comfortable with the GUI world so nib/xibs work well there.
I honestly find myself using XIBs as a base quite often and editing them with code to get the specific look I want. Personal preference.
For a specific con on that point, views can be difficult to configure after loading them from a xib. When you have conflicting settings between IB and code that can be nasty to troubleshoot.
Here's a question for the list. What is the performance hit to using a xib? I thought they were a plus because they don't get loaded into memory until you need them. That said, that load time is longer which will slow your program down. Thoughts?
One thing I found better about code is for the event connections on controls, when you search for uses of a method (message) you find them if they are coded and you don't find them if they were set in IB.
On the other hand laying out objects on a view is much easier in IB where you can see their size and positions. When you do that in code you have to guess at the size and origin settings and then run it and make adjustments, then run it again to see what it looks like.
When your application has some kind of "standard" views, go with the XIB. If you need real customization, depending on external content (XML...) do it programatically.
I started using XIBs and now it's all code, I find myself more comfortable this way. I had real problems with XIBs, and now writing the interfaces all in code really saves me time.
I save tons of time when dealing with UIControllers (UITabBarControllers, UINavigationControllers etc.) in the start up phase where all the navigation stuff is hooked up.
I just build X viewControllers with a accompanying XIB, throw in the stuff needed in IB, labels, images etc. This means that for almost any sort of app you can have a proof of concept up in a few hours. This is enough to justify spending some time learning the ins and outs of IB. Especially on the iPhone where you can have a ton of good UI ideas, but they all fail when they move from the Simulator to an actual device.
The best thing, in my mind, is to balance it out, if you find yourself using a lot of time doing the "change the frame 3 px -> compile -> ahh.. needs two pixels more -> change 2 px - compile -> ahh.. 1 more px" for something that could be done in IB, you will seriously start to waste time.
I start as above, but afterwards I often throw the XIBs away for custom stuff. The trick is to not spend hours on implementing versions of custom stuff in code over and over again, but figure out how it should be and do the custom stuff once:)
The XML content of a nib file is very complicated. This makes it extremely difficult to review changes or fix merge conflicts with a version control system like Git.
Interface Builder is a nice idea, but Bret Victor, in his talk "Inventing on Principle" and his essay "Learnable Programming," implicitly challenges Apple to build an even better IDE.
One idea, based on Bret Victor's principle: What if I could select a "Move Tool" in the iOS Simulator app that let me move a button in my app and then the frame code changed in the implementation (.m) file? This would be much better.

Interface Builder vs Cocos 2D - how choice the best for your app

I was a flash developer for 3 years, and in the last 5 months, i begin the iphone development, i do 2 applications with interface builder for clients, and now i really want to do a little game, is quite simple, one match 3! I made the engine in interface builder, and seens good to me! But after i read some posts, i really want to try it in the cocos2D! So, in 2 days i rewrite all my first engine for cocos2D, very annoying upsidedown coordinates but ok, i really do! But the performance side by side with interface builder version is really scare! Many Many slow downs at the cocos2d side! And the animation seens bugged to me! I really scare! I really don't know what is the best choice for a simple game.
And i want some opinions:
Using cocos2d when need some physics? When we have many objects at screen? What is the performance boost i have with cocos2D?
I have how to share this 2 applications with you guys?! Without your UID?!
cocos2d uses chipmunk, which IMHO is a great physics library if all you need is 2d! Apple doesn't support ad-hoc distribution without knowing the Device ID of the test device!
I think baDa is asking when to use cocos2D and Interface Builder. Since you can develop games using Interface Builder, is it advisable to do so? What are the performance differences between this two approach (cocos2d vs Interface Builder)?
I also had a confusion and ask this to my self when i was just starting to program. After working with several games. I reallized that you can actually combine this two approaches. The big BUT is, when working with objects dynamically (specially with bunch of images) using IB, it totally removes the flexibility of the code. Adding/removing images, adjusting coordinates and replaceing scenes is just too awkward, bulky, and wastefull to implement.
My simpole rule is to use coocs2d for game developemnt and IB for other apps that is reach in interfaces.

NIB/XIB files with Cocoa programming - faster development time?

I have been programming with the iPhone SDK for some time now.
I have not been using Interface Builder. This scares me a little. I know that in effect I may be 'fighting the framework' but I do not see it that way.
I find it very easy to just instantiate my UITabBarController in my app delegate, instantiate a UINavigationController, then push and pop view controllers as I go.
Naturally I do not have an extensive knowledge of how to architect an app with XIB files because I have never done so, however I do know the general gist of it, having built some Mac apps in Cocoa using NIBs. So I am not completely ignorant.
My question is whether there is an increase in development time when choosing to lay out UITableViewControllers and UIViewControllers using XIBs rather than programmatically instantiating them and then setting up the ivars.
As I see it, both methods still require you to subclass the view controller for customization which will probably occur for the majority of your views. As well, there are still manual classes required for delegates, and the process of connecting outlets from within the XIB seems comparable to me from setting an ivar.
Or am I missing some other major point?
Thanks!
Code takes much longer to write to configure UIs than IB does.
Plus, you can hand off design to designers and let them tweak the UI.
In the end they both accomplish the same thing. You should use either one depending on the circumstances. Most of the time writing the code to create and position views, and especially maintaining it down the road, will take much longer than using IB. In a simple app for the iPhone though, this might not be true and you'd be just as well off creating everything in code. Basically, you should know how to do both, and pick the path that involves the clearest code and quickest development.
IB shines when you're using it to actually lay out views; even two or three views can be a real hassle to lay out and configure in code. I do tend to use it for tab bar and navigation controllers, and sometimes for subcontrollers (usually only if I think the user is very likely to use it), but that's more just because I'm already there so I find it convenient.
With this new version 3 OS they're announcing next week, I'm hoping Interface Builder gains some of the flexibility it has in Cocoa, where you can add palettes for your own classes and even build up complex non-view data structures (by using custom palettes). We'll have to see, though.
Don't worry too much, IMO Interface Builder is a little over-rated too.
It's definitely useful for getting things up and running quickly, or if you have an app with a lot of screens that are tedious to setup, but you're not missing much.
For the uses you outline just doing things in code is fine, and possibly even a little easier to understand.
Laying out views, or custom cells though... then you get into a ton of font/color/position setting that quickly explodes into a lot of code, hard to maintain and tweak. Much easier to adjust what you want in IB in those cases.