Archive for the ‘Mac + OSX’ Category

AS3 Development in OSX

Sunday, January 20th, 2013

I had a small AS3 project and decided I would stray from the standard Flash Builder solution provided by adobe to see how things have changed over the last few years. I ended up looking at two solutions. Being major TextMate fan I set it up and hooked it up to the Flex SDK. On the recommendation of a colleague I checked out the latest version of FDT as well.

TextMate 2 still supports AS3. Due to the broad nature of the application it does require some setting up. There is a plugin for As3. The plugin however is not the only part of the setup process. See setup instructions here. If you already use TextMate or have an affinity for it then its very usable once you get through the setup process.

FDT used to be a Eclipse plugin back in the day. Some where between FDT 3 and FDT 5 it became its own app. Well you get eclipse pre-bundled with it. FDT used to be quite pricy. How ever now they offer a free version. The free version does not have all the bells and whistles you get with the paid for version but if your looking for is a quick and easy way to compile AS3 projects. It has a two step setup process and practically works out of the box. The only thing you have to do is hook it up to the Flex sdk then all the settings have defaults and you set them all in a GUI.

In short FDT is the easiest and quickest solution if all you want is to get in, compile then out.

AppCode File Template for CoreGraphics and PaintCode

Wednesday, November 21st, 2012

In my last post I setup a CALayer subclass for CoreGraphics and PaintCode.

I created an AppCode template that I am sharing here.

The header file template:

Implamentation file template:

 

Vector Graphics in iOS with CoreGraphics and PaintCode from an SVG file

Monday, November 19th, 2012

Since I started iOS development there has always been one thing missing for me. That has been a vector graphic file format. There is no format currently natively supported by apple.

I did some digging and found SVGKit. This is a very nice library that loads in .svg files. It even supports SVG animations. Not to mention its free. So I had to share this. However it can be tricky to set up.

In the end I settled on using PaintCode. PaintCode is a vector based graphics application that generates CoreGraphics Objective-C. PaintCode will also load in SVG files.

The idea is you load an SVG file into PaintCode. Edit it if needed then copy the Objective-C code into your project.

There are different ways you can include it in your projects. I would like to use it in layer of the CALayer flavour.

What I have done is create a CALayer subclass. That all you have to do is past in the PaintCode code.

For convenience I create all my vector assets at 100×100 pixels. I then use a scale to get it to the right size.

This assumes you have PaintCode and have already got the code ready. Also assumes the image is 100×100.

Step 1:
Add the “QuartzCore.framework” to your project.

Step 2:
Create a new file using the “Objective-C Class” template for iOS. USE CALayer Subclass

Step 3:
Add the bellow line to to your Header file(.h).

 

Step 4:

Add the bellow code to the implementation file(.m). Note: see line 17 if your image is not 100×100 pixels

Step 5:

Add the CoreGraphics code to the drawImage method.

Step 6:

Add this layer to a view that is currently on the view stack.

 

Thats all you need.

 

**Edit

I created an AppCode template for this.

 

Using LevelHelper without Box2d for Cocos2d-X

Thursday, November 8th, 2012

I have been trying out LevelHelper recently and it has been very useful when making games that have a fair bit of physics.

I was looking at making a really simple game that did not require physics. Thats where LevelHelper seemed to fall over. Since the editor generates code for you and that code has reference to Box2D.

Fear not for all is not lost, you can still use LevelHelper without implementing the physics. You still need use the Cocos2D-X with Box2D template in xCode. You just don’t attach the physics properties.

So follow the tutorials on the LevelHelper site. When you get to the bellow line of code in the second video:

The first parameter “world” is used to attach the physics properties. The second parameter “this” is what all the image assets in LevelHelper level are attached to. All you need to do is change the above line to:

Now just ignore any code to do with physics and Box2D.

Miller Cylindrical Projection with source for (Long, Lat) to (x, y)

Wednesday, May 2nd, 2012

Recently I have been trying to get a custom map working with Longitude and Latitude that plotted in the x and y in iOS. It also needed to work with a zoom and offset. It was a bit of an argus journey but I got there in the end.

What you will need is a projections type(map type) and the formula for the conversion. Ideally a projection type that compensates for the curvature of the earth.

I settled for a Miller Cylindrical projection. The problem with the maps is finding an accurate map. You can use maps with offsets but getting started it helps if you have an accurate map. I ended up going through a lot of maps before I found an accurate one. It had a white border that I had to crop off but otherwise it was perfect.

DONT FORGET TO CROP THE WHITE BOARDER IF YOU SCALE IT UP

http://en.wikipedia.org/wiki/File:Miller_projection_SW.jpg

I scaled it up for testing purposes up to a height of 6563 and a width 8933 cropped.

Here is the Objective-C code and little C to get he job done:

As you can see the the hight and width is hard coded. What if your map needs an offset and you also need to have a dynamic size to compensate for zoom levels.

The description method

Tuesday, October 11th, 2011

Any object can implement the description method that is used to return a description of the contents of a receiver. The problem i have always found with this method. Is keeping the method up to date during the development process. Also getting other developers working on the project also keeping it up to date.

With that problem in mind I put together this method that will automatically generate the string and list all available properties in the the receiver. It will print out when the instance is used in NSLog or or printed using the GDB debugger commands in my previous post.

You can also find it on my custom xCode 4 templates here on github. Right at the bottom the class.

xCode GDB Debugger Commands

Thursday, September 22nd, 2011

One of the things that I struggled with going from eclipse and Visual Studio to xCode was the the debugger.  Most of the objects have memory references rather than values. For a long time while developing iOS apps all i would get, or though I had was one cryptic error message. Till I discovered po which stands for print object. This allowed me to print out the contents of an object which can be very useful.

Here is  list of gdb commands: (Warning properties are not identified by the debugger so dont use anything with dot notation)

po – print object – can be used to print out the likes of NSStrings and NSDictionaries
use: po someObject

print – prints base types – used to print out to the screen ints floats and the like
use: print myFloat

set – set a variable – allows you to set variables
use:  set someString=@”test”

call – calls a method – can be used to call methods or the properties getters and setters
use: – call [someObjectInstance withString:@”newString”];

n – Next – always you to travers your code during breck
use: n

There are 2 main places you can use the commands.

The first is the consol output during a break or crash just after the gdb:

The second is in a break point first set a break point then click the “Click to add action text” ass seen bellow.

Now you can add you command in the newly available text field that will always be triggered at that point in the code.

Carful with the break point triggers not to confuse your self if you put sets or calls in there.

Setting up xCode 4 Projects

Friday, June 24th, 2011

Every time I start a new xCode project i do it a little differently. I include files in some and settings in others. I have decided to put them all here to make sure i don’t miss any. If you have any other project settings, scripts, snippets or useful utils please drop a comment.

1. Enabling and dealing with Zombies:

This allows you to find errors that come from delloced objects being called upon. That normally just gives you the useless error bad access. with this enabled it should take to a class or function when you see the bad access error. This can be dealt with in 2 ways either enabling zombies in the editor thus allowing you to debug it in xCode or using instruments. If the first method does not work for you try the second.

Method 1 xCode Debug:

  1. get to the run settings by press: cmd+alt+r
  2. from the left nave select “RUN  yourApp.app”
  3. select “Arguments” from the right tab system
  4. expand if not already expanded the environment variables
  5. add NSZombieEnabled the name parameter and YES to the value parameter

Method 2 instruments Debug:

Rather than take you through it Mark Johnson has created a good video that talks you through it.

Check out his blog post for more details: http://www.markj.net/iphone-memory-debug-nszombie/

2. Replacing NSLog with PSLog

PSLog is a NSLog replacment. I have seen it arround for a while now. Basicly it gives you a bit more info like where log is called from. The only problem with it, is the dependancy it creates on having to keep importing PSLog in every one of your projects.

I modified it so you can use NSLog in your code and at compile time in debug mode it replaces your NSLogs with PSLogs. During deploy it replaces NSLog with comments. This way it removes any depandacies on the PSLog function.

How ever this only applies to the PSLog function it self none of its expanded counter parts like PSLogDebug. Using PSLogDebug will maintain a dependancy.

Check it out:

https://github.com/abeazam/PSLog.git

If you #import “PSLog.h” in the .pch file in the support group in your project you wont have import it in every file you want to use it. which Helps the whole dependancy issue.

TODO, FIXME converted to warnings

I duno if you noticed but if you add a //TODO: or //FIXME: comments it appears  in the function menu. The problem with that though is you need to be in the class to see the list. Ideally what I wanted was a list of todos that I can see them all in one place. You can do that by adding a bash script that adds them as warnings.

  1. Select your project in the left hand menu
  2. Select your project in the target right hand menu
  3. Click “Add Build Phase” in the bottom right.
  4. Select “Add Run Script”
  5. Past in the script below and your done 🙂

i think this guy might have come up with it: http://deallocatedobjects.com/2011/05/11/show-todos-and-fixmes-as-warnings-in-xcode-4/

Snippets
Snippets are one of the things that stood out to me in xCode. Here are a few of mine:

Completion shortcut – log
Completion scope – function and method

Completion shortcut – imp
Completion scope – processor directive

If you want to make a variable just stick them in <#here#>.

Crash Log Server

http://quincykit.net/
https://github.com/therealkerni/QuincyKit

Sends the crash report to a server with a single line of code. I have not tried the push notifacsion but every thing else seems to work resonably.

http://quincykit.net/

Please let me know if you find anything else that helps keep a project in shape.

Unix and SSH Commands From Scratch

Tuesday, April 19th, 2011

In my last post I discussed node.js. This can be installed on a server. Originally I wanted to talk through how I installed Node.js and what plugins I have come to use. I took a look around and found a few ppl struggling with ssh. I figured best to cover some of the basics of server based commands first. I expect any one reading this have some Technical/Programming experience.

I am going to assume you have a sever and are working from a Unix based machine(Linux or OSX).

Accessing your server:

usr: would be your user name to the server for the sake if this example lets say your user name is peter

host: is your server url/ip lets say for this example its Watson.com

so in your command window type in your server details press enter:

Enter you password and you should be in.

Basic Commands:

Here is a list of basic commands to help you move around the folders and manipulate the files.


Type that and it will list all the files and folders


That will show all the hidden files too.


Primary navigation command.


goes up a folder.


navigates to the folder with the name folderName


Takes you to your home directory.


creates a directory


copies file.txt to someFolder and renames the file.


moves file.txt to someFolder and renames the file.


deletes txtFile.txt


touch creates the file with no content


Displays resources and process


Downloading

wget downloads a file at a location the above line downloads googles index.html page


git clone will clone a git repository to your current location


svn checkout checks out a svn repo


Editors
You will edit a lot of text files on server a far bit. So I will list 3 Degrees of editors.

Easy

this one is easy all shortcuts (^ is ctrl) are listed at the bottom but not as powerful as the other two.

Medium

this is obviously more powerful than pico but to achieve that it uses states when u start you can’t type you need to enable typing. This is just a taster of how to use it. There are entire pages on the web that list all the shortcuts.

i
press i when u are not in edit mode and it will insert the cursor to allow you to type

press ESC then :wq
esc enters command mode w stands for write and q stands for quite so save and exit

press ESC then :q!
quit with out saving

Hard

best text editor i could write a whole post on it. If you wana use google it.

Compiling Code
In Unix you can tailer a build for your system. so its compiled for you and you alone 🙂 Lets say you downloaded a project from the internet using git or svn.

Complete in order below

cd
to the location of the files

set settings in the build for your machine its automated it just does it


compiles your code

tests the compile

installs your compiled code

Removes all the compiled files and cleans up for you

Comming soon 🙂 sudo pico /etc/motd

Password Protecting Mail.app and your e-mails

Monday, September 6th, 2010

One of the issues I had with using the Mail.app on OSX is its lack of security.

If some one is logged in as you they then get access to everything else on you machine like say your mail client.

Now I really like the Mail client. I have no intention of switching clients. So a solution was required.

After a little digging i found there was no mods for Mail. No hacks or any other means in which to password protect the client and the mail. Eventual I realised I was doing it all wrong its not the emails and the client that can be protected but where they are being stored is what can be protected.

I finally realised if I created a encrypted dmg and ran everything from there it would yield the same results.

Aim:
Get both the Mail.app and my email onto a password protected drive.

Process:

  1. Open Disk Utility to create the encrypted DMG /Applications/Utilities/Disk Utility.app
  2. Click “New Image” on the top
  3. Select a Name and a save as location
  4. Further down under size select the size I made mine 10GB  this depends on how much mail you expect to store locally
  5. Below that make sure select the Encryption
  6. Hit create set the password and now you should have a mounted encrypted drive
  7. Move your Mail app  from /Applications/ to the root of your mounted encrypted drive cut it don’t copy it
  8. Then make make an alias of the Mail app in the in the /Applications/ folder(ctrl dragging the icon)
  9. Now you need to cut and past your emails to the encrypted drive find the folder /Users/YOUR_USERNAME/Library/Mail and past it in the encrypted drive
  10. Now make an alias of the mail folder from you encrypted drive  back to the /Users/abraham.azam/Library/ (ctrl dragging the folder)
  11. Finished.

If you click the mail icon on the Dock it should now access your mail client and your amils from a scure and ecrypted location. if you unmount the drive and click the icon it will promt you for the password to the dmg then opens the mail app.

please let em know what you think of these steps 🙂