Monday, December 29, 2014

Black Bars Issue in iOS 7 Simulator

I stumbled on to this issue recently when I started a project which I was asked to support from iOS 7 upwards. I setup my Xcode project and took it for a spin in the simulator in both iOS 7 and iOS 8.

In iOS 8, everything looked good and normal.

But in iOS 7, a weird UI issue surfaced.

The UI seemed shrinked and two black bars appeared at the top and bottom. After pulling my hair for a good hour or two, I found the solutions.

To fix this, you need to add two launch images. Now in iOS 8, you can use an xib file in the place of launch images thus eliminating the need to create a bunch of images in different sizes to support each device, orientations and screen resolutions. But we get this luxury only in iOS 8. If we're supporting iOS 7, you still need to include launch images the old way.

I added these two launch images.

Default@2x.png              640 x 960
Default-568h@2x.png     640 x 1136

And the above issue was fixed!

Saturday, December 27, 2014

Finally! CocoaPods with Swift!

UPDATE: As of version 0.36, Swift support has officially been added to CocoaPods.


This is what we all have been waiting for! CocoaPods, our beloved dependancy manager for iOS and Mac projects finally supports Swift in their latest release 0.36. But hold your horses because 0.36 is still in beta. In this very short tutorial I'll show you how to give it a go. Mind you this is not a beginner's guide to CocoaPods. I assume you have have prior experience with using CocoaPods.

To use SwiftPods (I like the sound of that), first you need to install the latest version which is 0.36 beta of CocoaPods. Open up the terminal and type this.
 sudo gem install cocoapods --pre
This will install CocoaPods 0.36 beta. To confirm run the below command,
 pod --version  
It will output something like this 0.36.0.beta.1.

That's actually pretty much it. There are third party Swift libraries already supporting SwiftPods out there like EVCloudKitDao. You can include them in the Podfile and run pod install just like you would do in the good old days.


However when I first tried to use it, I hit a few bumps. Here I'm going to include the issues I came across and how I resolved them.

1. Even after successfully installing the 0.36 beta version, when you run pod --version you might see it outputs an old version (like 0.35). To resolve that I completely uninstalled CocoaPods using sudo gem uninstall cocoapods and reinstalled it again as I have shown you above.

2. If you're using third party libraries only written in Objective-C in a Swift project, when you install them using CocoaPods, you'll see them as static libraries instead of frameworks as it should. Otherwise you won't be able to use them in Swift.

 To resolve this you need to include the line use_frameworks! in your Podfile. Like so,
 source ''  
 platform :ios, '8.0'  
 pod 'MagicalRecord/Shorthand'  
Now run pod install again and voilĂ !

That's it! Say bye bye to the hassle of manually dragging and dropping project files yadda yadda. Enjoy using CocoaPods in Swift projects!

Sunday, November 16, 2014

Hello World....Again


I'm back with a new blog. I thought of removing my old blog and starting over and here's why. When Apple released Swift last June, my initial reaction was a groan. I was just starting to get better at Objective-C and the last thing I wanted was to throw it all away and go back to square one with a whole new programming language. I debated with myself over and over whether to stick with Objective-C until Swift matures or just dive right in.

In the end, I caved and thought of giving Swift a try. And I was pleasantly surprised. The syntax is clean and concise. And there are some very cool features like generics, tuples and supercharged enums! My initial impressions about the language started to change and slowly I began to like coding in Swift. The transition wasn't difficult as I thought it would be.

Anyway now I'm developing iOS apps in Swift full time both at work and home. Even though the initial phase with Swift and Xcode 6 (although Xcode 6.1 still functions like a beta version) betas was a very bumpy ride, I enjoyed learning it and still am. A lot of resources are flowing in every day on Swift. Its exciting times.

Since I'm working with Swift completely now, I thought of starting a new blog. I will be posting tips/hints/workarounds and small tutorials on various software related stuff, not just iOS. The code will be in Swift only. Not that I hate Objective-C but because I think Swift will be the future of iOS development and it is an investment to start learning it starting right now.

Well that's it for this intro.

Happy coding!