views:

23569

answers:

11

Using PyObjC, you can use Python to write Cocoa applications for OS X. Can I write native iPhone apps using Python and if so, how?

+12  A: 

Not currently, currently the only languages available to access the iPhone SDK are C/C++ and Objective C.

There is no technical reason why this could not change in the future but I wouldn't hold your breath for this happening in the short term.

That said, Objective C really isn't that scary...

Dave Verwer
Objective-C rocks.
vy32
I've written a multi-feature iPhone app in Objective-C and a multi-feature Mac app in PyObjC, and I have to say that, based on the experience, Objective-C's syntax for data structures in particular (such as arrays and dictionaries) is significantly more cumbersome and tedious than Python's. I've basically refused to do further development on my iPhone app until Apple includes support for PyObjC. The comparatively verbose and tedious syntax of Objective-C is incredibly distracting to me when I'm trying to develop the top-down flow of my algorithms.
Chris Redford
@Dave Verwer: is this answer still up-to-date?
bukzor
@bukzor nope, see http://stackoverflow.com/questions/3691655/embedding-python-in-an-iphone-app
cobbal
@cobbal: Then this thread is pretty misleading.. What's the correct way to go about getting it corrected?
bukzor
@bukzor upvote the now correct answer and leave a comment indicating that the post is out of date (done)
cobbal
+33  A: 

You can use PyObjC on the iPhone as well, due to the excellent work by Jay Freeman (saurik). See iPhone Applications in Python.

Note that this requires a jailbroken iPhone at the moment.

gavrie
+4  A: 

The iPhone SDK agreement is also rather vague about whether you're even allowed to run scripting languages (outside of a WebView's Javascript). My reading is that it is OK - as long as none of the scripts you execute are downloaded from the network (so pre-installed and user-edited scripts seem to be OK).

IANAL etc etc.

schwa
A: 

Newer versions of the iPhone SDK licensing agreement disallow jailbreaking. So while it is possible to do what you are looking to accomplish, there is no legal way to do it at the moment.

mmc
Why does that really matter? It's not immoral. As long as you don't sell jailbroken phones, nobody will care.
Zifre
I didn't state that there was anything wrong with it. It's not a value judgement, it's a fact. The Apple Developer Agreement disallows jailbreaking.If the original poster entertains any idea of ever distributing their application on the App Store, it's something that they need know.
mmc
+1  A: 

You can do this with PyObjC, with a jailbroken phone of course. But if you want to get it into the App Store, they will not allow it because it "interprets code." However, you may be able to use Shed Skin, although I'm not aware of anyone doing this. I can't think of any good reason to do this though, as you lose dynamic typing, and might as well use ObjC.

Zifre
A: 

The only significant "external" language for iPhone development that I'm aware of with semi-significant support in terms of frameworks and compatibility is MonoTouch, a C#/.NET environment for developing on the iPhone.

Mike
Yes but with the new iPhone Developer Agreement we must wait and see what will become of Mono Touch.
Holli
@Holli: The now new dev agreement puts MonoTouch in the clear
phsr
@phsr Yes, I already noticed. Great news.
Holli
+6  A: 

Yes you can. You write your code in tinypy (which is restricted Python), then use tinypy to convert it to C++, and finally compile this with XCode into a native iPhone app. Phil Hassey has published a game called Elephants! using this approach. Here are more details,

http://www.philhassey.com/blog/2009/12/23/elephants-is-free-on-the-app-store/

+7  A: 

Edit: Another recent update to the Developer Agreement means that you can use whatever you like, as long as you meet the developer guidelines. Section 3.3.1 has been entirely removed.

Source: http://daringfireball.net/2010/09/app_store_guidelines

--

A recent update to the iPhone Developer Agreement for iPhone OS 4 means that apps must be originally written in either Objective C, C++, C or Javascript as executed by WebKit.

3.3.1 — Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs. Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs (e.g., Applications that link to Documented APIs through an intermediary translation or compatibility layer or tool are prohibited).

This means that apps created using Python would not be approved for the App Store.

Source: http://daringfireball.net/2010/04/iphone_agreement_bans_flash_compiler

Gordon Christie
Thankfully, this language has been removed from 3.3.1!!
phsr
+1  A: 

Technically, as long as the interpreted code ISN'T downloaded (excluding JavaScript), the app may be approved. Rhomobiles "Rhodes" framework does just that, bundling mobile Ruby, a lightweight version of Rails, and your app for distribution via the app-store. Because both the interpreter and the interpreted code are packaged into the final application - Apple doesn't find it objectionable.

http://rhomobile.com/products/rhodes/

Even after the latest apple press release - rhodes apps (mobile ruby) are still viable on the app-store. I'd find it hard to believe that tinyPy or pyObjC wouldn't find a place if there is a willing developer community.

Michael McCracken
+3  A: 

It seems this is now something developers are allowed to do: the iOS Developer Agreement was changed yesterday and appears to have been ammended in a such a way as to make embedding a Python interpretter in your application legal:

SECTION 3.3.2 — INTERPRETERS

Old:

3.3.2 An Application may not itself install or launch other executable code by any means, including without limitation through the use of a plug-in architecture, calling other frameworks, other APIs or otherwise. Unless otherwise approved by Apple in writing, no interpreted code may be downloaded or used in an Application except for code that is interpreted and run by Apple’s Documented APIs and built-in interpreter(s). Notwithstanding the foregoing, with Apple’s prior written consent, an Application may use embedded interpreted code in a limited way if such use is solely for providing minor features or functionality that are consistent with the intended and advertised purpose of the Application.

New:

3.3.2 An Application may not download or install executable code. Interpreted code may only be used in an Application if all scripts, code and interpreters are packaged in the Application and not downloaded. The only exception to the foregoing is scripts and code downloaded and run by Apple’s built-in WebKit framework.

jkp
A: 

I'm wondering - why would it be advantageous to program in python? Apple has gained great advantage my having almost all of their iphone apps programmed in Obj C. Standardization makes for the best environment for collaboration/competition.

Alex Horan