Blog Archives

What is a Method in Objective-C Anyway?

You can think of this post as the first in a series of ‘The bits that nobody else explains very well’… An explanation ‘cheat-sheet’ article if you will, for anyone who’s starting to dabble in iOS or Mac OS programming and wants to not only ‘know’ how to program, but who wants to ‘understand’ what they’re coding as well. Many tutorials will gloss over these basic explanations, dismissing them as second nature, or failing to understand how fundamentally important it is that their readers understand the concepts behind the code they are being taught.

To some more experienced developers, these explanations might seem too simplistic and in some cases, even ‘wrong’ technically. That doesn’t matter here, what matters is that the fundamental concepts are understood. This article will be part of a series and if there’s a particular item you’d like me to cover just let me know in the comments section, or by heading to the contact form! Now without further ado, lets talk about Methods in Objective-C.

 

Methods In Objective-C

Right, now hang on a second… You know what a method is right? No… of course not, why would you even be reading this article if you did? So let me explain… Programming is essentially a set of instructions for a computer to carry out (in this case a shiny, drool worthy, iPhone… but a computer nonetheless). These instructions need to be wrapped in some sort of container in order for the code you write to make any sort of sense at all. Here’s an example I like to use, it’s called the ‘Making a cup of tea’ example…

If you wanted a cup of tea, and someone else was in the room with you, what would you say? Well, let’s assume you’re uncharacteristically rude and dispense with the pleasantries, you would say “Make me a cup of tea“… What you wouldn’t say is, “Take the kettle, fill the kettle with water, turn the kettle on, wait for the kettle to boil, take a mug, put a tea bag in it, once the kettle has boiled pour water from the kettle into the mug, take a spoon, stir the tea, remove the teabag, add milk, maybe sugar, put the milk away, put the spoon in the sink, bring me the cup

When you say to somebody “Make me a cup of tea” they understand the process to make a cup of tea, because it has already been explained to them in detail (probably a long time ago, but that’s irrelevant). When you ask somebody to “Make me a cup of tea” they know they need to carry out a set of instructions in order to fulfil that process and provide the output (In this case, a refreshing beverage!)

Methods to a computer are a way of containing these instructions, so you might decide to write the method “Make me a cup of tea” and within that method, you would write the code instructing the computer exactly how it should do that. The fantastic benefit of this is that now the computer knows how to “Make a cup of tea” you can call that method from within other methods, to perform that set of instructions. Essentially, once you’ve told the computer how to “Make a cup of tea” once, you need never tell it again.

Now, to dwell on this particular example just one moment longer… Remember that big long list of instructions that you wouldn’t say to another person if you wanted them to make you a cup of tea, “fill the kettle with water, turn the kettle on, etc…”. In the same way that you would write the method “Make me a cup of tea”, you would also write the method “Fill the kettle with water” which contained precise instructions for how exactly it would ‘Fill the kettle with water’. Within your “Make me a cup of tea” method, you would then simply call your “Fill the kettle with water” method as part of that process.

If you can understand this fundamental principle then you are one step closer to becoming an elite programmer! Seriously though, this may seem simple to the experienced programmers out there, but no one really explains this stuff very well and it’s important.

 

So what does a Method look like in code then?

Well, I’m glad you asked… I just happen to have an example right here! Before I show it to you though, allow me to explain a little bit of jargon I might use from now on. A programming language is like any other language, it has lexicon (words) and syntax (rules for combining those words) and as with any other language, there are many people out there who will argue for many, many days (and nights… seriously) about the correct use of programming syntax / lexicon. What I will use in these articles is examples that I consider to be ‘best practice’, I’m sure there will be people who disagree with my examples, but they’re not writing this article now are they!

So, a traditional objective-C method looks a bit like this…

[cc lang="objc"]

- (NSString*)getName {

NSString * name = @”Jeff”;

return name;

}
[/cc]

What on earth does this method do? Well… lets switch a few names around, and it should all become a bit clearer…

[cc lang="objc"]

- (CupOfTea *)makeMeACupOfTea {

CupOfTea * tea = milk + mug + water;

return tea;

}
[/cc]

So let’s examine what we have here. The first line tells us two things about this method, firstly - (CupOfTea *) tells us the ‘output’ of this method, or in english… what this method will give to whoever or whatever calls it. Secondly it tell us what the name of the method is, in this case makeMeACupOfTea, now we can choose what we call our methods (exciting huh?) and don’t underestimate this process. As soon as you get any number of different methods in one place, it becomes very important for you ‘the programmer’ to be able to quickly remember and know what each of your methods are called.

Right, so we know that this method is called makeMeACupOfTea and that it will output a CupOfTea *, Wonderful! Don’t worry about what the * means right now, we’ll get to that in another article. So the rest of the method is within a pair of curly brackets (Yep, that is the technical term for them!) Everything that is within the { } is the ‘doing’ code of that method. Here you will find the code that actually makes the cup of tea.

All we are doing in this functional code, is creating a new object (more on this in a future article) called tea of type CupOfTea which is (if you recall) the output of this method. Don’t worry about how we’re creating tea here, in this example it’s just a bit of pseudocode (code which explains a purpose but is not actually functional or valid code) to make my point. So to finish the method off, all we do is return tea; Easy (When you know how!) So, now you know what my makeMeACupOfTea see if you can work out what the ‘real life’ getName method does? (A bit of googling will tell you what an NSString object is… Well, you didn’t think I was going to do ALL the work for you , did you?

 

Taking methods to the next level…

So, hopefully now you understand what a method is, what it’s purpose is, and how to use them. There is one more thing… Inputs, or parameters as they’re more commonly known. So it’s all very well, we have these methods to return us lovely objects, but what if we want to use these objects, say in another method for example. Well, that’s where a parameter comes in… You can pass another object into your method as a parameter. Let’s go back to our old makeMeACupOfTea example to demonstrate this, so if we use a parameter to pass the method a TeaBag * the method would probably look something like this…

[cc lang="objc"]

- (CupOfTea *)makeMeACupOfTeaWithThisTeabag:(Teabag *)myTeaBag {

CupOfTea * tea = myTeaBag + water + milk;

return tea;

}
[/cc]

So here you can see that we have extended our method, to pass into the method the teabag that we want the method to use, in order to make the tea (at this point the water + milk are still elements of pseudocode purely for explanation purposes). So breaking down the method again, you can see we have a colon : in the method name, followed by the object type of the parameter in brackets, in this case (Teabag *) followed by the name of the parameter that you will use to reference the object you are passing into the parameter within the ‘doing’ code (the bit in-between the curly brackets if you remember). So anytime you type myTeaBag within your method, the computer will know you are specifically referring to the myTeaBag that you have passed into the method as a parameter.

We can take this a step further, and actually pass in multiple parameters to a method. This is done like so…

[cc lang="objc"]

- (CupOfTea *)makeMeACupOfTeaWithThisTeabag:(Teabag *)myTeaBag Water:(Water *)myWater Milk:(Milk *)myMilk {

CupOfTea * tea = myTeaBag + myWater + myMilk;

return tea;

}
[/cc]

So now what we’re doing, is telling the computer to make a CupOfTea with this teabag, this water, and this milk! The formatting is probably wrong in this blog post, but that’s never what this was about. I don’t care right now if you don’t know the ‘best practices’ or if you are able to write code in the most efficient and optimal way as possible (although that becomes important later on.) Today I will be happy if you just understand methods a little bit more, and are slightly more comfortable in how to use them and what exactly they are doing.

Once you grasp the concept of methods, you’re one step closer to writing the next ‘Angry Birds’. Seriously though, it’s an important step into the world of programming. Even though this article has focused on Objective-C, the fundamental principles are the same in most programming languages, the lexicon and syntax will be different but the concept will be the same. This has been quite a long post, so my suggestion would be to go away, digest it, write some methods, and come back if you need any further guidance. Practice, makes perfect… Oh and remember: The computer is following instructions, it will only ever do what you tell it to do (and it’s really very fussy about how it gets told!)

This is the first of a series of articles, and is really the first time I’ve sat down to try to write a guide like this. I would appreciate any and all feedback, positive and negative! Just leave a comment below. Likewise if you want clarification on anything I’ve said in this article, let me know in the comments and I’ll update the article with more information on your point. For now, thanks for reading and happy coding!

Tagged with: , , , ,
Posted in Informative

Degree Results…

Hello All,

Just a very quick post, I am delighted to announce that i have graduated from Bournemouth University with a 1st Class BSc (Hons) Degree in Music and Audio Technology. My CV has been updated appropriately, and you can find my CV here. Additionally, I was presented with the ‘Student of The Course’ certificate for the three years of study. Additionally, Media interest had picked up on the Twinthesis Project, and it has been featured by The Telegraph, and various local BBC Radio Stations, A feature has also been produced for BBC Radio 4′s Today programme and will be broadcast soon.

As always, i’d like to thank you for visiting my site, and i hope you enjoy some of the interesting and innovative projects you’ll find me working on. I am now actively looking for employment within the audio, software programming, social media, or education sector. So please download my CV here.

Sam

Tagged with: , ,
Posted in Informative, Press & Media

Welcome, from FODI 2011…

[caption id="attachment_214" align="alignleft" width="225"] iResponse at FODI 2011, Bournemouth University[/caption]

If you’re reading this, I’m assuming you’ve been directed here either by me, or by scanning my QR code at the Festival of Design and Innovation. In either case, Welcome. I’m glad you’d like to know a bit more about me, and the projects i’m working on. Feel free to browse the site, you can find my CV (I’m currently looking for employment!) and examples of my previous work, etc.

The project I’ve been exhibiting at FODI 2011 is the ‘iResponse’ iPhone application, more release information is available here. Once FODI is complete, I will be uploading the promotional materials and examples demoed at the show for you to download and experiment with. Currently the application is still in development, but release is scheduled towards the end of this year (2011.)

Another project I’ve been working on, and has become quite popular in the media recently is ‘Twinthesis’. This is a synthesiser which is powered entirely by data from Twitter in real-time. The synthesiser takes data from the 20 most recent tweets at any different time, and maps each character of a tweet to various tones, hums, and bleeps to create a unique sonification of that tweet. The synthesiser is built within the Max/MSP architecture and is available to download here.

That’s all for now, I hope you enjoy the site. Please feel free to contact me, either by email, twitter (@Sammio2) or using the built in form here. This site will be regularly updated with progress on my work and various project ideas that I am starting and hoping to work on after graduation.

Tagged with: , , , , , , ,
Posted in Informative, Press & Media

Press Release from Bournemouth University

UPDATE: Official Bournemouth Uni Website Updated: http://bit.ly/kp0ODy

Further Information: Charles Elder, Press & PR Manager

(tel): 01202 961032   email: press@bournemouth.ac.uk

17 June 2011

 

How does your room ‘sound’? New app can help!

The creator of the ‘Twinthesiser’ – the unique web-based software which turns posts made on Twitter into real sounds – will present his latest project as part of the 2011 Festival of Design and Innovation at Bournemouth University.

Sam Harman, who is just completing his BSc (Hons) in Music and Audio Technology, will demonstrate his new iPhone application as part of the Festival which opens for a private view on Thursday, 23 June before opening to the general public on Friday, 24 June.

Sam’s iPhone Impulse Response Application is designed to capture the acoustical characteristics of a room, (otherwise known as an impulse response) which can then be duplicated through a computer. “It’s really designed for musicians, audio technicians or acousticians but the application makes it easy for anyone to use,” Sam enthuses. “Previously it’s required a lot of microphones, cables, laptops, etc but now you can just do it all on your iPhone and then plug-in to your computer and use the data collected by the application to make any audio on your computer sound like it was being performed or recorded within the room or environment that you’ve captured.”

Earlier this year, Sam introduced the world to his ‘Twinthesiser’ which he designed to “explore the ‘sound’ of twitter, in an attempt to sonify the human randomness being generated on the service.”

Through the ‘Twinthesis’ software, Sam has assigned each character its own distinctive tone. The software then accesses a Twitter feed every 30 seconds or so, selecting the top 20 tweets at random and repeats it to produce a kind of rhythm or ‘symphony’ of high pitched bleeps and deeper humming sounds.

“The Twinthesisier can then go through the tweets a character at a time to produce a sort of melody,” says Sam. “In time I hope we could get to the stage where it could pull data off Twitter at more than 100 times every second and this would produce a sort of global symphony.”

“Theoretically the application could be configured to draw data from Facebook or Twitter or from any other source of random data,” Sam continues. “You could also apply the engine to groups of people so you could take the tweets from one country and compare them with the sound of tweets from another country.

“It could become a sort of worldwide controllable instrument, which I think is really cool,” Sam concludes. “There are limitless things you can do.”

“Sam’s work on Twinthesis along with the audio application he developed for the iPhone is a perfect example of the brilliant work that our students in Music and Audio Technology are able to deliver,” says Dr Alain Renaud (title). “His work, along with other students, blends creativity and complex technologies, to ultimately deliver products that have a commercial potential in the field of Creative Technologies.”

BU’s BSc (Hons) in Music and Audio Technology gives students an opportunity to apply electronic and computer technologies to create contemporary music and audio. Students from the degree will join other emerging designers and innovators from BU’s School of Design, Engineering & Computing to display and demonstrate their creations at the 2011 Festival of Design & Innovation.

Open free to the general public from Friday, 24 June to Monday, 27 June on the University’s Talbot Campus, the 19th annual Festival – sponsored by B&Q, the UK’s leading home improvement retailer – will showcase over 170 designs and prototypes created by talented final year students completing undergraduate degrees in Product Design, Industrial Design, Design Engineering, Fashion & Textiles

(from BU’s partner institution, Wiltshire College, Salisbury), Interior Design, Computer Aided Product Design, Sustainable Graphics & Packaging (from BU’s partner institution, University College Yeovil) and Music and Audio Technology.

Further information on the 2011 Festival of Design and Innovation at BU – including opening times, exhibits and travel directions – are available on the Festival website: www.festival.bournemouth.ac.uk

 

Further information about the Twinthesis programme can be found at Sam Harman’s website – http://samharman.com/2011/03/twinthesis-twitter-powered-synthesis/

 

To hear the Twinthesiser ‘in action, please visit – http://soundcloud.com/theharmonizer/twinthesis

 

Tagged with: , , , , , , ,
Posted in Informative, Press & Media

MIDI comes to iOS devices

That’s right, it’s exciting news for people like me all over the world. Information has just leaked that apple has implemented the MIDI standard in the next version of its iOS operating system for iPhones, iPads, and iPod Touch’s. Apple allows you to send data over USB (via the camera connection kit) or over WiFi, which presents some very interesting opportunities (as long as there is no lag!)

It’s brilliant news, and although some say MIDI may be a dying standard I believe it’s seen a new lease of life on lower powered mobile devices such as these. I think it won’t be long before we see some really creative uses of the new API and I personally cannot wait to try developing with it! Below is a video showing how one developer has used the new API!

[via Engadget]

Tagged with: , , ,
Posted in Informative

C++ VST Vibrato Plugin

VST Vibrato Plugin

The following project was to fully design and implement a vibrato plugin for Cubase using Steinberg’s VST SDK. The plugin is programmed in the C++ language and is provided here for you to download. You have the option of downloading just the .dll plugin file (which is all you need to use the plugin), but I have chosen to provide a version which contains the source code project (Microsoft Visual Studio 2008 format) and the initial algorithm modelling (in MaxMSP format).

The full download also contains the VST SDK 2.4 but is referenced to locally, so you should not need to install and configure the SDK to view the working project. Please note that the SDK is completely owned by Steinberg, and I have not made any modifications to the development kit for use within this project. Below are the links to the downloadable files, including the software manual for the plugin.

- Full Download (Including Plugin, Source Project, and SDK)

- Plugin Only (Just the .DLL file)

- Software Manual

To install the plugin for use within Cubase, simply copy the file “Vibrato.dll” to the following Directory…

"C:\Program Files\Steinberg\Cubase Studio 5\VSTPlugins"

This directory may be different depending on your current operating system or version of Cubase. Please see the software manual for more detailed system requirements and installation instructions. This work was produced as a second year assignment for Bournemouth University, please feel free to use the example and learn from the source code but please don’t try and pass it off as your own work.

As always, thank you for your interest in my development work. Any comments, suggestions, or feedback are always welcomed in the comments below or via the Contact Me form.

Tagged with: , , ,
Posted in Portfolio

Under Development

Several apps for the iOS platform are currently under development. Due to the sensitive nature of the intellectual property rights associated with these apps, information will be uploaded once the apps are released. Please check back at a later date!

Thanks!

Tagged with: , ,
Posted in Applications

DSLR Photography Flash Application

This post contains a video demonstrating a flash application I created in the first year of study at Bournemouth University. The brief was for a simple tutorial based application developed in Adobe Flash, to demonstrate key principles of digital SLR photography. My application exceeded the expectations for the assignment, and i received a grade of 98% for this piece of work, please feel free to watch the video below.

The application was developed entirely in Adobe Flash, I created the graphic elements using Adobe Photoshop, and all photographs were taken by me specifically for this project. The application makes use of both standard animation techniques as well as action script code, and object orientated programming. I have been further developing this application and intend to release it for free in the near future.

Tagged with: , ,
Posted in Portfolio