skip to Main Content

I have a macOS app that I wrote years ago; it has been working well on my Mac. Recently I thought it would be nice to have that same app on my iPhone so I added an iOS target to my Xcode project. I have never built for iOS before so I’m on new ground here.

Anyway, when I built for iOS, I got an error message: "Cocoa is not available when building for iOS." In Apple’s "Cocoa Fundamentals Guide" there is a prominent statement: "Cocoa is a set of object-oriented frameworks that provides a runtime environment for applications running in OS X and iOS."

Does that mean I can run an app that uses Cocoa but not build one? I’m at a loss; I have no idea how to get past this one. Can an iOS app be built without Cocoa? How would I even go about doing that? Any suggestions at all will be welcome. I’m running Xcode 12.5 on macOS Big Sur 11.4. My app’s UI is written in Objective-C and its muscle is in plain C. Also, my app is only for my own use, not for publication.

2

Answers


  1. Try to rewrite your code using Cocoa touch or UIKit. I am not good at iOS coding, by the way as I know Cocoa framework is for Mac OS, the framework for touch devices is Cocoa touch.

    Login or Signup to reply.
  2. Anyway, when I built for iOS, I got an error message: "Cocoa is not available when building for iOS." In Apple’s "Cocoa Fundamentals Guide" there is a prominent statement: "Cocoa is a set of object-oriented frameworks that provides a runtime environment for applications running in OS X and iOS."

    That’s somewhat confusing wording. iOS uses a variation on the Cocoa theme called Cocoa Touch. More specifically, the user interface framework on macOS is called AppKit while the iOS user interface framework is UIKit. If you’re comfortable with AppKit, it’s not hard to learn enough UIKit to get things done. Other frameworks (Foundation, Core Graphics, Core Data, etc.) are pretty much the same on both platforms.

    Does that mean I can run an app that uses Cocoa but not build one?

    No. You’re going to have to rewrite at least the user interface parts of your app before it’ll run on iOS. iOS devices obviously use a somewhat different user interaction model: there’s no hardware keyboard, no mouse, a touch screen that can handle multiple simultaneous touches, a much smaller screen, and a variety of sensors that don’t exist on the Mac, so a different approach to interacting with the user is different. If you were careful to separate the business logic (model) from the user interface (views) in your Mac app, you’ll likely be able to reuse most of that unchanged.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search