Browsed by
Category: Xcode

Run PHP scripts in native macOS app with Xcode & Swift

Run PHP scripts in native macOS app with Xcode & Swift

Developer Curiosity

Many, many years ago, as an open source PHP and WordPress developer, I had a system for testing arbitrary PHP as I honed my skills and learned new techniques. I had a file on my web server called test-php.php that did nothing but output the results of my code and would spend hours writing code, upload to server, switch to browser, refresh. This is how I learned the basics of regex, converted base64, tested operators, and refined my database access techniques.

I’m with Swift!

On a bored and underutilized day in 2012, I decided to figure out how to write an app to simplify the process. I had similarly written two apps previously, the first of which was a rip on a crazy flub by the Mitt Romney campaign when they released a campaign app called, “I’m with Mitt!” which would overlay Mitt Romney Oh ’12 campaign slogans on live photos. Hilariously, their developers failed to QC it thoroughly, ending up with a silly typo on the main overlay which draped the photos, meant to be shared socially using the app’s built-in functionality, with the slogans, “A Better Amercia” and “I’m with Mitt”.
Fork me on GitHub
That was not typo in my post. I know how to spell America. So, being smart like I am, I built an app that did the exact same thing. Except I misspelled “Mitt” as “Milt”. I called it “I’m with Milt” and overlookably misspelled something in every overlay.

Read More Read More

Better Native PHP Syntax Support in Xcode

Better Native PHP Syntax Support in Xcode

I’m a big fan of the Xcode IDE from Apple. Unfortunately, it is myopically focused on development for iOS and Mac OS X, using Objective-C. A long time ago, it was a lot more open. You could find a variety of plugins that would extend its functionality to include the projects you work with, such as PHP syntax support, in Xcode outside of the Apple software ecosystem. But for the past several years Apple has made it difficult to extend the IDE beyond their intended purposes. I’m mainly a backend PHP developer, but I have been a long-time Mac user. This puts me in the position of having second-rate tools for the biggest reason I use my computer. Yes, there are IDEs for Mac OS X that focus on PHP, but they’re all cross-platform and written in Java, which is, itself, a second class citizen on the Mac platform.

[asa]0321833899[/asa]

I’ve suffered through using Netbeans, Eclipse, and PHPStorm for years, all the while yearning for a grown-up IDE like Xcode to do my job. No longer! With Xcode 4, Apple introduced CodeSnippets that allow a user to not only save commonly used code snippets to an easily accessible palette, but we can tokenize the snippets and define the prefix text to which Xcode’s autocomplete feature will respond. Type “fore…” and if you have a snippet called “foreach”, Xcode will offer up the helpful autocomplete list with your snippet. Hit tab or enter and the snippet will be inserted at the cursor. Hit tab again and you’ll be guided through the snippet’s tokens, one by one, allowing you to fill in the blanks.

[asa]0321967208[/asa]

With this in mind, I went to work creating over 5,000 snippets to cover the entirety of the PHP language. See my github repo here: https://github.com/tonyjohnston/PHP-Xcode-Autocomplete Now I have native-like autocomplete for Xcode. I start typing “str” and here’s what I see:

Screen Shot 2013-06-07 at 6.21.41 PM

I tap enter and this is what results:Screen Shot 2013-06-07 at 6.23.58 PM

I type “if” and Xcode presents this:Screen Shot 2013-06-07 at 6.25.17 PM

Arrow down to ifelse and tap enter:Screen Shot 2013-06-07 at 6.26.30 PM

Each of those blue rectangular ovals is a tabable token, just waiting for you to enter your specifics, just like Xcode’s support for Objective-C. It’s a huge advancement in the arena of Mac PHP IDEs. It took me about 6 hours to put this whole thing together so I’m sure that it can get better. Feel free to fork my GitHub repo for PHP Xcode Support and help make PHP a first class citizen on the only great IDE for the Mac.