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.


Rejoice!

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.

Troubleshooting

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 'https://github.com/CocoaPods/Specs.git'  
 use_frameworks!  
 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!