Skip to main content


Showing posts from February, 2016

Split-screen compatible iOS apps

Apple’s iOS split-screen compatible iOS apps AppStore: N AppleStore: N Camera: N Calendar: Y Clock: Y Contacts: Y FaceTime: Y FindFriends: Y Find My iPhone: Y Game Center: Y GarageBand: N iBooks: Y iCloudDrive: Y iMovie: N iTunes: N iTunesU: N Keynote: Y Mail: Y Maps: Y Messages: Y Music: N Music Memos: N News: Y Notes: Y Numbers: Y Photo Booth: N Photos: Y Podcasts: Y Reminders: Y Safari: Y Settings: N TestFlight: Y Tips: Y Videos: Y Other apps Adobe Acrobat: Y Adobe Capture CC: Y Adobe Captivate Draft: N Adobe Comp CC: Y Adobe Content Viewer: N Adobe Creative Cloud Tutorials: N Adobe Digital Editions: N Adobe Illustrator Draw: Y Adobe Lightroom: Y Adobe Photoshop Express: N Adobe Photoshop Fix: Y Adobe Photoshop Mix: Y Adobe Photoshop Sketch: Y Adobe Slate: N All 4: N Amazon Video: N Animation Creator HD: N Anim8: N ArtRage: Y Assembly: Y AstroPad: N Autodesk Sketchbook: Y BBC iPlayer: N BBC News: N BBC Weather: N Booki

Adding Dictionary operands to Swift

This post isn't about the rights and wrongs of using operands to combine or add to dictionaries. I was simply looking through StackOverflow and found a question on the subject , which was linked to a previous one and thought that the response could be expanded upon with a few more cases: func +=<K, V> (inout left: [K : V], right: [K : V]) { for (k, v) in right { left[k] = v } } func +<K, V> (left: [K : V], right: [K : V]) -> [K : V]{var new = [K : V](); for (k, v) in left { new[k] = v }; for (k, v) in right { new[k] = v }; return new } func -<K, V: Comparable> (left: [K : V], right: [K : V]) -> [K : V]{var new = [K : V](); for (k, v) in left { new[k] = v }; for (k,v) in right { if let n = new[k] where n == v { new.removeValueForKey(k)}}; return new } func -<K, V> (left: [K : V], right: [K]) -> [K : V]{var new = [K : V](); for (k, v) in left { new[k] = v }; for k in right { new.removeValueForKey(k)}; return new } func -=<K, V: Comparab

Swift: Going Around in Semicircles, Quarter Circles and Three-quarter Circles with UIBezierPath (Updated: now with pie chart drawing)

This is a short one (edit: well it started that way anyway). I'm simply posting some code that I wrote to solve a problem I was having. More on that problem in a later post. For now this is a semicircle extension for UIBezierPath that enables you to init a semi-circular path with one line of code: UIBezierPath(semiCircleMidpoint:, radius: 100, facingDirection: .RightFacing) To do so you'll need to add this extension: extension UIBezierPath { enum SemiCircleDirection { case RightFacing, LeftFacing, DownFacing, UpFacing var startAngle: CGFloat { switch self { case .RightFacing: return CGFloat(M_PI) * 1.5 case .LeftFacing: return CGFloat(M_PI_2) case .DownFacing: return 0 case .UpFacing: return CGFloat(M_PI) } } var endAngle: CGFloat { switch self { case .Rig

Send an Xcode project to Bitbucket

Sending a non-git Xcode Project to BitBucket from  GitHub is the most popular place to host your repos but if you are looking for a free service for teams that are 5 members or less then take a look at BitBucket. Here are instructions for moving a local Xcode project onto BitBucket. (Note: if you opted for a local Git when you created your project you should be able to skip steps 3 and 4.) Sign-up for BitBucket and create a repo In Xcode go to Source Control menu Select "Create a working copy ...." Select project and press Create in dialog window Return to Source Control menu and select <Project Name> -> Configure <Project Name> ... Click "Remotes" tab Press add "+" Copy and paste the https address you see at the top right of your repo page into the remote location in Xcode Go to Source Control menu and select Push... to upload the project Pushing code updates to BitBucket Now you have it set up whenever you want to push

Swift: Upload images using NSURLSession (NSInputStream)

This is a very simple example of using a stream to upload where all the parameters are known to us. PHP The PHP file looks like this: <?php // choose a filename $filename = "new_image.jpg"; // access the input stream via php://input $input = fopen('php://input', 'rb'); $file = fopen($filename, 'wb'); stream_copy_to_stream($input, $file); fclose($input); fclose($file); ?> Swift And the Swift looks like this: // delegate for receiving data class SessionDelegate:NSObject, NSURLSessionDataDelegate, NSURLSessionTaskDelegate { func URLSession(session: NSURLSession, task: NSURLSessionTask, needNewBodyStream completionHandler: (NSInputStream?) -> Void) { if let fileURL = NSBundle.mainBundle().URLForResource("image", withExtension: "jpg"), path = fileURL.path, inputStream = NSInputStream(fileAtPath: path) { completionHandler(inputStream) }

Swift: Download a file using NSURLSession

The most important part of downloading a file is the NSURLSessionDownloadDelegate, because this is where you will make sure you have access to the file and so on. class SessionDelegate:NSObject, NSURLSessionDownloadDelegate { func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingToURL location: NSURL) { // see: // First we obtain the path of the Documents directory if let documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first { // next we retrieve the suggested name for the file let suggestedName = downloadTask.response?.suggestedFilename ?? "new_file.pdf" // now we can create the NSURL (including filename) - a file shouldn't already exist at this location let newLocation = NSURL(fileURLWithPath: documentsDirectoryPath).U

Fear and Loathing in Auto Layout: Animating Auto Layout Constraints with a Tap, Drag, Pinch and Rotate in Swift (Xcode 7.2, iOS 9.2.1; updated Swift 3, Xcode 8 beta 6)

** Jump to Swift 3 code ** So you want to move things across the screen? But how is this done when we're using Auto Layout and not just frames and centres to place objects? Well this is something that I've started to look at following this StackOverflow response . Turns out the ordering of the code and the calling of layoutIfNeeded() is important although we're free to update constraint values before or within animation closures, as long as we do so before the second call to layoutIfNeeded(). (The first time is to clear out any layout that needs to happen first, the second is to make the new changes. So we end up with a kind of layoutIfNeeded() sandwich.) Tapping a view I'm first of all going to extract the methods that get called by each gesture recogniser. The code is not complete in these extracts. For example, here we are missing the code to attach the gesture recogniser and also the bool that is being checked and changed. But all the surrounding code is

Swift: From HTML to NSAttributedString and Back Again (iOS 9.2.1, Xcode 7.2)

I wrote a post about this ages ago, since when the method I used was deprecated in iOS 9. So here's an update on the code, this time in Swift. HTML to NSAttributedString if let htmlURL = NSBundle.mainBundle().URLForResource("page", withExtension: "html"), data = NSData(contentsOfURL: htmlURL) { do { let attrStr = try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType], documentAttributes: nil) print(attrStr) } catch { print("error creating attributed string") } } Here an NSURL of a local file is used to generate NSData and then this is converted into a NSAttributedString. What we should no longer do (due to deprecation) is initialise a NSAttributedString from a fileURL directly. NSAttributedString to HTML While on this topic it's worth noting how to turn a NSAttributedString into HTML ( Obj-C source , StackOverflow): let att

Resurrecting CommonCrypto in Swift for hashing, encrypting and obfuscating (iOS 9.2.1, Swift 2.1, Xcode 7.2)

The inability to simply import CommonCrypto into a Swift file has been an awkward moment for encrypting and hashing on Apple devices, but there is a simple way around its exclusion using a bridging header . The bridging header simply needs to include the following line of code: #import "CommonCrypto/CommonCrypto.h" Or if you prefer then you can use the constituent parts of CommonCrypto: #import "CommonCrypto/CommonCryptor.h" #import "CommonCrypto/CommonDigest.h" #import "CommonCrypto/CommonHMAC.h" #import "CommonCrypto/CommonKeyDerivation.h" #import "CommonCrypto/CommonSymmetricKeywrap.h" And I believe this isn't the only way to get CommonCrypto functionality back. According to iosdevzone you can run the following line from the Terminal to enable CommonCrypto to be used even within a playground: sudo xcrun -sdk macosx swift GenerateCommonCryptoModule.swift machos Whether this enables you to also build an app on a