Skip to main content


Showing posts from 2011

Power of PHP: Reuse code with classes

Last time we looked at how PHP could be used to add hyperlinks to text URLs. Now this is something that could be really handy and that we might reuse over and over again. So let's save it as a class. For transparency this will be a separate file called livetext.php and it will be saved in a subfolder called 'classes'. This is what the class looks like in its entirety: <?php class liveText { function addHyperlinksToURLs ($data){ $patterns = array('/(http:\/\/|https:\/\/)/','/([a-zA-Z0-9\-\.]+ \.)(com|||org|net|mil|edu|CO.UK|ORG.UK|COM|ORG|NET|MIL|EDU) (\/.[A-Za-z0-9\.&%\/-]{1,}|)/'); $replace = array('','<a href="http://\0">\0</a>'); echo preg_replace($patterns, $replace, $data); } } ?> It consists of a single function and this does all the work. So that's it for this class. Now when we want to use it, we first of all include it with the line: include ("classes/

Remove .DS_Store files from ePUB files

I've found that since upgrading to Lion OS X .DS_Store files have been inserting themselves into ePUBs when they are zipped, and I don't think I'm alone. To erase these use the following command from within the folder containing the ePUB (changing "filename" to the name of your file): zip -d filename.epub `unzip -l filename.epub | grep .DS_Store | awk '{print $4}'` The solution is essentially the one provided by Meitar Moscovitz to remove .DS_Store files from ZIP files, since ePUBs are renamed ZIP files.

Power of PHP: Make live all web address URLs

I've been considering posting some PHP coding tips and tricks. Here's a little one to get things started. If it's popular then I'll follow up with some more in the New Year. <?php $data ="To learn more about programming iOS apps you can visit directly or search for it on Google at"; $patterns = array('/(http:\/\/|https:\/\/)/','/([a-zA-Z0-9\-\.]+\.)(com|||org|net|mil|edu|CO.UK|ORG.UK|COM|ORG|NET|MIL|EDU)(\/.[A-Za-z0-9\.&%\/-]{1,}|)/'); $replace = array('','<a href="http://\0">\0</a>'); echo preg_replace($patterns, $replace, $data); ?> This code takes a variable $data, which can be changed to any text and then finds the URLs and converts them into hyperlinked text using preg_replace. It doesn't matter whether they begin http:// or www. but it isn't a complete implementation because

Working for the Elves

I'm breaking off from the blog for Christmas, but before I go there's one thing that I want to tell you about, and that's a book called The Waking Prince . It has just gone live on the iBookstore, and is a fabulous fully-illustrated fixed-layout iBook that I was lucky enough to work on in the role of eProduction editor. The Story Elves are a committed team. The book has been illustrated by the amazing Scott Brundage  and the story written by Zoe Roizen Soane. Book design is by Alexis Roizen, and additional editing and story ideas come from Joseph Hefta. It is a book for all ages and I highly recommend. You can grab a copy by following this link  where you can also download the free extended sample. I'd also recommend taking time to visit the Story Elves website , especially if you have children, because the site is all about inspiring children to write and draw, and with it improving the way that these skills are taught in schools, while also plugging a gap betw

Xcode from scratch for scaredy cats: Sharing variables between methods in the same class

Note: If this is the first post in the series you have read, you'll first need to follow steps 1-5 in this blogpost  to create the Xcode Project and also read this post on the insertion of code in an iOS app. We can set an instance variable and use it within a method. For example if we created a New Project of the type Single View Application called Variable with a class prefix Variable, then in the VariableViewController.m file we could write -(void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSString *prop = @"hello"; NSLog(@"%@", prop); } This would work fine and the app would return the expected result (the word "hello" displayed in the console, which pops opens at the foot of your Xcode window when the Simulator is running). But suppose we want to set the value of the NSString in viewDidLoad but then read this value out in another method, for example when the device

Finding droppings: WiFi on iMac and Android with Belkin Router

Note: This is a personal finding and not a comprehensive guide. I've found that newer Macs and Android share something. While older Macs seem capable of selecting their security settings from WPA or WPA2 or a conjoined WPA/WPA2 setting, newer Macs and Android appear to have one conjoined WPA/WPA2 setting. Now, the Belkin router that I use lets me select under its Security settings WPA-PSK or WPA2-PSK or WPA-PSK + WPA2-PSK. The final setting seems to work fine with all computers but the newer Mac, which was struggling to reconnect after sleep. Changing the setting to WPA2-PSK and manually setting IP addresses fixed this, but then an Android (v.2.2.1) phone refused to connect. Finally, I set the router to WPA-PSK and all on the network were happy. More on configuring wireless security on a Belkin Router can be found here .

Restore lost iOS data using Time Machine

Note: This article will only apply to you if you use Time Machine on OS X Lion to backup your system, and your device is backed up to your computer not the iCloud It is possible that when iTunes is syncing with an iPad it can hang or that a power cut or a force quit situation, or perhaps an update, has deleted some of the data that resides on your iPad local to the apps. I had this recently and found an answer on the Internet to my woes. I don't have a link to that article - it was on the iPad with the data that I reset (so the page history in Safari was lost for that day!) - but I can remember the steps, and will explain all here. The data for iOS apps - when you sync with your Mac - resides in a folder inside your User folder (i.e. Macintosh HD -> Users -> Your User Name -> Library -> Application Support -> MobileSync -> Backup). This folder is inside your personal Library folder, but you won't see the Library folder in Lion OS X because Apple have hid

Confessions of an Xcode scaredy cat

Before we proceed with this series of Xcode for iOS posts, I want to make clear the motivation behind them. Something that I'll be doing here as a stop gap between last week 's post and the next one. First and foremost, it is important to point out that I am not putting myself forward as an expert in programming Xcode for iOS. I am instead someone interested in becoming more proficient in coding for the platform. The motivation behind the "Xcode from scratch for scaredy cats" series, therefore, is somewhat self-centred, because in constructing the posts I am forcing myself to think in clear terms about the writing of code for iOS, and become better. But there is another reason as well, and that is because I wanted to help people like me who needed a foothold to start climbing the Xcode mountain. Although there are many excellent sites and tutorials for learning Xcode, as a beginner I all too often found that a long time was spent on explaining the user interf

Xcode from scratch for scaredy cats: Sending a message to a method (NSLog)

Last time we saw how to set up a subclass and reuse the object. This time we're going to send a message to a method contained in a subclass and the subclass will vary its output based upon the variable contained within that message. I'm keeping things brief, and you'll need to recreate the 'New Project' and 'New File' elements by looking back at last time . This time, however, we'll make the new file a subclass of NSObject instead of UIView. This will mean we don't have "drawRect:" waiting for us to uncomment. So instead here is what your method looks like inside the subclass .m file: - (void)performOperation:(NSString *)operation { if ([(NSString *)operation isEqual:@"can you hear me?"]) { NSLog(@"Yes I can hear you!"); } else { NSLog(@"nope!"); }} And because this is a public method we'll need to add it to the .h file of the subclass with this line of code: - (void)performOperation:(NSString *)oper

Xcode from scratch for scaredy cats: Hello with a little class (UIView subclass)

This time we're going to do two things: (1) write some text (2) subclass this text so that we can reuse it. In order to do this first we need to create a new project entitled: "ALittleClass" using the same method outlined in the first ' Xcode from scratch for scaredy cats ' post. We are then going to create a "New File ..." within this project and call it "ALittleClass" When creating this new file you will be prompted first to choose a template - select iOS -> Cocoa Touch -> Objective-C Class followed by the Next button. You will then be asked to insert a filename beneath which is written - "Subclass of" - in this second box you need to select or type UIView and press enter. Inside the new .m file ("ALittleClass.m") you'll find some code that is "commented out". You need to remove the comments around this. So that it looks simply like this: - (void)drawRe

Error "Licensing has stopped working"

I recently encountered a permissions problem with Adobe CS3 running on OS X Lion, where  the error message that is at the head of this post appeared, and all programs in the suite refused to open. The first step instructed by the error message was to reinstall. This didn't resolve the issue, so I went trawling the Internet for a solution, and although Adobe has published  this near perfect guide to fixing the issue, I did find one error that had me stuck for a short while and thought worth reporting. It comes in point 3 under ' Solution 2: Run the License Repair Tool', where having downloaded  Adobe Licensing Repair Tool  you are instructed in sub-points (e-g) to open Terminal and drag there after starting Python and press return. This just threw up a syntax error for me. So instead of typing "sudo python", I just typed "python" at the prompt that appears after opening Terminal. And then, before pressing enter, I added

Xcode from scratch for scaredy cats: A slight return (if ... else)

In this post we return to the app that we built last time . The reason for this is that once we've pressed the button it doesn't do anything else, which is rather dull. In this post we'll change this, so that when we push the button again the background returns to white. The user then gets some feedback and recognition of subsequent button pushes. We'll be using the "if ... else" statement, which will be familiar to those of you who have experimented or worked with Javascript or PHP among other languages. If it isn't then don't worry as promised in the previous post we'll move slowly and simply. In order to insert the code we need to open our file called "PushButtonViewController.m" and scroll to the bottom of the file to our piece of code ("method") from last time: - (IBAction)sender:(id)sender { self.view.backgroundColor = [UIColor blueColor]; } and this needs to be entirely replaced by this code: - (IBAction)send

Xcode from scratch for scaredy cats: Push the button (IBAction)

(1) We're going to put to one side our "StaticImage.xcodeproj" for this post, but we will return to it in later posts, so don't trash it just yet. (2) Following the steps laid down in the first " Xcode from scratch for scaredy cats " post we are going to create a "New Project..." called "PushButton". (3) We are then going to navigate once again to the .xib file, this time called PushButtonViewController.xib ( if it is called ViewController.xib, or something else, then you forgot to type "PushButton" in the "Class Prefixes" box when you named the app ) (4) Now create a button by displaying the right-hand column of the Xcode application window and dragging it from the list of objects at the bottom of the column (as we did with an "Image View" in the first blogpost) (5) Next we need to select the "Navigate" menu from the top menu bar in Xcode, and from here click "Open in Assistant Editor&q

Xcode from scratch for scaredy cats: Your first line of code (UIColor)

In the previous 'Xcode from scratch for scaredy cats' post I showed you how to create an app without any code at all. This time we're going to modify that app using some actual code. For this you'll need to open the project file from last time: " StaticImage.xcodeproj " ( return to point 5 of the previous post if you've forgotten how to view the project files in Xcode ). I'm going to approach this gently and only use one line of code in this entire post. Here's what the line of code looks like: self.view.backgroundColor = [UIColor yellowColor]; The question is: What does it do and where does it go? It changes (or "sets") the background colour of our view to yellow and it goes in the " StaticImageViewController.m " file right beneath the comment "// Do any additional setup after loading the view, typically from a nib." This comment is inside something called a "method". The method "viewDidLo

Xcode from scratch for scaredy cats: Ten easy steps to an iOS app (UIImageView)

You'll need to install Xcode from the Mac App Store or Apple Developer Connection if you haven't done so already. After which follow these ten easy steps to your first iOS app. (1) Open Xcode (2) From the welcome screen select "Create a new Xcode project" (3) Choose type of app: "iOS -> Application -> Single View Application" (4) Choose a name for your app, here we'll use "StaticImage". Insert this name in two places: "Product Name" and "Class Prefixes" boxes. Then select device family: choose iPad for this example (although iPhone would do equally well). (5) Click to expand "StaticImage" project in left-hand column, so everything looks like this (6) Go to Finder and find an image on your system, then drag and drop it into the "StaticImage" folder inside Xcode app. Here I use one called "crow.png". On the dialogue box that appears simply click on "Finish". (7)

Google ebookstore: UK launch

Google launched its ebookstore in the UK yesterday (6 October 2011). The advantages of which are that its eBooks (even when DRM protected by the publisher) run on most eInk Readers (with the major exception of the Kindle) thanks to the adoption of the ePUB format alongside Adobe's DRM. You can also view your books on the web, or in a web app using the Google Chrome browser. In addition to which there are iPad/iPhone and Android apps to access your content. Pages sync between devices, and the interface is clean and simple on the web and in the apps. Also, Google incorporates the PDF alongside the ePUB, so that you can check how the page rendered in the print book very easily by selecting the settings menu (which is denoted by "Aa") and changing from "Flowing text" to "Scanned pages" (where the publisher has enabled this feature). One thing that isn't present at the moment is the ability to take notes or highlight text inside the app, but no