Wednesday, September 30, 2015

Deploy to iOS 9 devices with Xcode 6.4

If you like me have a large codebase app developed in Xcode 6.4 with Swift 1.2, with apple’s releasing of iOS 9, you might encounter problem when you run your app in your iOS device upgraded to iOS 9.x.

Likely you will get messing “iOS 9.01 is not supported by Xcode 6.4”

If you get this message, the first option ahead of you would be updating your Xcode  from 6.4 to Xcode 7.0, which also means upgrading form Swift 1.2 to Swift 2.0.  

Well, if you have a large codebase, and is scheduled to release the app to the store soon, this may not be the good time for you. The following is the process to bypass the problem. Thanks to Apple for not providing backwards compatibility.


  1. Upgrade your Xcode 6.4 to Xcode 7
  2. Download Xcode 6.4 from apple developer site again, and install it to different name , (e.g.  XCode2 in my case)
The goal is to make Xcode 6.4 and Xcode 7 available in your Mac, you may not need to Install Xcode 7, but you need Xcode 7 dmg file. You could stay with Xcode 6.4 and download Xcode 7 but do not even install it.

Then right click on the Xcode dmg file select "Show Package Contents” to browse the dmg file. Navigate to /Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport.  copied the folder named 9.0 (13A340) into the same location of your Xcode 6.4 installation folder. Then re-start your Xcode 6.4. 

With that, if you are as lucky as I am, you should be able to run deploy your app to iOS 9 devices with Xcode 6.4

Saturday, August 29, 2015

How to implement Delegate using Protocol in swift

More than often you, as an iOS app developer, are required to implement protocols then defining you own protocols and use them. However, defining your own protocols, delegates is an elegant way passing data from one class to another. This technic is especially useful in the context of view Controllers. I am giving a simple example below; you can test it in a playground. Once you understand the theory behind it, you can apply it anyway you want.

This example is created in the context of a smaller company who retrieves packages for its clients from specified locations and stores them in its warehouse waiting for client to pick up.  As part of the business operation, there are dispatchers and retrievers. Dispatchers tells retrievers where to pick up the packages, the retrievers retrieve the package and pass them back to dispatcher for to stock up. A important point to note is that the retrievers do not know the location of the warehouse, dispatchers do.

Let’s get it started


I start with defining a protocol as following:

protocol DispatcherDelegate {
    func stockUp (package : String)
    var  package : String { get set}

}

This is the simplest protocol you can get, only one method and one property. Yon can add more to it. E.g. add some properties, and/or add more methods.  But do remember that the implementers of the protocol need to implement all members it defines, though you can make some of them optional.


Then I process with defining Retriever class. It uses the protocol as its delegate and a method simulating the retrieving logic

class Retriever  {
     var dispatcherDelegate: DispatcherDelegate?
    func retrieve (location : String) {
        // go to the location to retrievbe the package
        switch location {
        switch location {
        case "location-1":
            dispatcherDelegate?.stockUp("Dell PC")
            dispatcherDelegate!.package = "Dell PC"
        case "location-2":
            dispatcherDelegate?.stockUp("Apple MacBook")
             dispatcherDelegate!.package = "Apple MacBook"
        default:
            dispatcherDelegate?.stockUp("something else")
             dispatcherDelegate!.package = "something else"
        }

    }
}

As the last step if the setting up, I define dispatcher class as following, the important part is it implements DispatcherDelegate protocol by proving the implementation of stockUp method.


class Dispatcher : DispatcherDelegate {
  
    func stockUp (package : String) {
       println("\(package) is stcoked in")
   
    }
    func dispatch (location : String) {
       var retriever = Retriever()
       retriever.dispatcherDelegate = self
       retriever.retrieve(location)
    }
}

This is class, I have a method call dispatch, which instantiates retriever class and set itself as the retriever’s dispatcherDelegate, then it calls the retrieve’s retrieve method.


Finally, let’s put them all in test by putting the following line of code in playground:


var testDispatcher = Dispatcher()
testDispatcher.dispatch("location-1")
testDispatcher.package
testDispatcher.dispatch("location-2")
testDispatcher.package
testDispatcher.dispatch("somewhere else")

testDispatcher.package

if you put this code block in playground you will see the result at the right panel, showing

{package "Dell PC"}
"Dell PC"
{package "Apple MacBook"}
"Apple MacBook"
{package "Something else"}
"Something else"



Bingo, they all work as expected for me, Hope they do the same for you.

Sunday, August 2, 2015

Cocoa pods and Alamofire

as a iOS app developer, more then likely, you would need to accessing resful service using swift 

if you are like me, do not want to write code if I do not have do, you would be happy to know there is a good framework which can help  you in a big way, it is Alamofire. you c an find it in Cocoa Pods and installed it from that.


The following resource are provide you with the information you need and step by step tutorials on how to use cocoa pods to install Alamofile and how to use alamofire  






Hope you find them informative and useful.

The Best way to demo your apps on your iO device

you and your team worked day and night got the app ready.  It is the show time with you clients.

you would want to walk around the conference room with the device in your hand, talking to your audience. they would see what happened on your device from a big projected listen to the audio from the best sound system the conference room is equipped with.

Yeah, that is what you are dreaming for. the Answer is AirPlay.

Install air server into your PC or Mac. download air server from apple app store into your devices. you are all set!

http://www.airserver.com/Download/Referrer/6288008

Sunday, January 11, 2015

iOS Storyboards

Scene : from visual representation point of view, scene is nothing but View Controller.  you add scenes into your storyboard by dragging view controllers into your storyboard.  There are many different type of view controllers provided to you by the framework.  The basic view controller is UIViewController.  All other view controllers are its sub-class. UITableViewController, UICollectionViewController are a few examples of various view controllers.

View Controller: once you added a view controller into your storyboard, you will see a visual representation of the controller, it is referred as "scene". however, more than likely, you need to create a class for the scene.  that is class you put you business logic for a specific scene.