Sunday, July 06, 2014

Building iOS Cocoa Touch Framework using Swift

With the XCode 6, comes the ability to develop "Cocoa Touch Framework" which is probably (not sure about how the DLL hell translates on to iOS) a better way to package the solution AND is the only way to create libraries in swift. The "Cocoa Touch Static library" AFAIK does not support swift language.

So far I have not been able to find anything standard step by step for this which is uses swift. This is just a post to capture my learning on this.

Most of the process should be inline with that identified in good post and detail as answer to stackoverflow question. Some additional points to consider

Swift based Frameworks

Ensure that you have selected Swift as language while creating new project.

I have been able to successfully run the framework as part of swift application on iPhone 5s with OS 7.1 which seems to indicate that older deployment targets may be supported. So, feel free to experiment with older target version. Based on the initial test the obvious issue is going to be support for new APIs (one of them being the UIAlertController and UIAlertAction APIs for generating alerts - I could not find any way to support this in swift using older APIs)

I have not been able to deploy the Archived file (ipa) through itunes (the installation process gets stuck in "Installing" and never completes). Need more research on that front.

Extending NSObject

As part of defining the swift implementation the system will create a corresponding <project name>.h file. I was able to define the @interface for my code in objective-c but when I tried to reference the same in Swift code later, I got following error
'<Class Name>' is not constructible with '()'
This was resolved by extending the @interface with NSObject (Reference). Looks like XCode does not do a good job of cleaning cache on "Cleanup" because of which when I tested later with a framework with missing NSObject, the system does not trigger any error.

By the way, there was no need to implement/extends the NSObject in swift class (given swift does not support root object concept).

Building project

As indicated in the various links, you need to additional work to create a universal binary for releasing your framework. The initial link has steps associated with a clean way to lipo the two builds. Based on my experience I have updated the script and that is available here for reference
# define output folder environment variable
# Step 1. Build Device and Simulator versions
xcodebuild -target ${PROJECT_NAME} ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos  BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
xcodebuild -target ${PROJECT_NAME} -configuration ${CONFIGURATION} -sdk iphonesimulator ARCHS="x86_64" ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
# make sure the output directory exists
# copy all the framework files. Just for convenience
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework""${BUILD_DIR}/${CONFIGURATION}-universal/"
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework""${BUILD_DIR}/${CONFIGURATION}-universal/"
# Step 2. Create universal binary file using lipo
Besides some basic generalization and framework specific folder structure changes, the following changes have been made
  1. ARCHS="x86_64" ONLY_ACTIVE_ARCH=NO was added to build process for iphonesimulator to create binary that can be used on 64bit machine. I am not sure why this does not trigger by default in my environment given Mac has been 64 bit for a long time. Please note that if the build was performed using UI then build was automatically 64 bit.

    ignoring file <file name>, missing required architecture x86_64 in file

    Undefined symbols for architecture x86_64:
  2. Copy both simulator and iphoneos files. Looks like the "compiled" swift object files are created for each of the platforms and without them linking will fail.
    Undefined symbols for architecture x86_64:

Importing frameworks

Basically, I tried Linking frameworks but that did not work because the application at runtime will expect the framework at specific location i.e. ~/Library/Developer/ (as defined in build process). So, I Embedded Binaries into the project. This hopefully is also a better way to avoid DLL nightmare. 

By the way I did not have to create any bridging header after importing the framework and so I am not sure whether it is needed.

Rest of the process was pretty standard. 

Tuesday, February 03, 2009


SUN is a great company when it comes to technological innovation but has failed to convert it into profits. Most of the people seem to blame their sales and marketing folks. I have seen this first hand in my domain also that for some reason they are unable to sell their products to non-technical folks even though their product is technically better than some of their competitor.
My thought is that they need to be acquired. I think there are two options
  • A technology company with strong sales and marketing that have complementary set of technologies and wants to provide top-to-bottom technology stack. A company like CISCO comes to mind.
  • A hosted solution company developing solution platform (currently called cloud platform) which can leaverage the deep hardware and software know how embedded in the firm to develop solutions on the specific stack.
Or hopefully SUN will be able to build a better sales and marketing team AND product designers rather than product engineers.

Tuesday, December 02, 2008


How do you jumpstart a blog that has been dead for almost 3 years. But there are times in life when you need to just shrug off and start doing what you want to without thinking for an explanation of past. In that sense, I think, India stands at the same juncture at this time.

Beyond the sadness, anger and frustration I have felt as an ex-mumbaikar (it being one of my favorite cities), Indian and human; it has been painful to see some of my close relatives feeling threatened for themselves and their kids lives.

At this point terrorists have explored various methods to terrorize Indians. They started with large bombs that created significant stir but not enough terror. This was probably because these were few and far in between due to amount of logistics and money involved. They then tried to attack the metropolitan cities with such big bangs but due to the nature of attacks it affected the class of people that did not have the luxury to feel terrified. In past one to two years, there has been significant attempt to develop the strategy of using small low intensity attacks in crowded areas of tier I and II cities. But I think beyond the simple element of surprise, increase in civil vigilance resulting from such an attack could make carrying out such attack significantly tougher going forward. This time (Nov 26th, 2008), it seems, there was an attempt to attack the strata of society that has felt somewhat safer so far. Even though attack tried to cover the entire cross-section of the society in Mumbai, due to the way it played out, coverage in media has become somewhat limited to the various hotels that were under seige.

Some of this reminds me of the way things took to worst in 80s between separatists in Punjab and India. The capital of New Delhi was converted into a big battleground with small intensity blasts in public places. I still remember public service ads telling people to stay away from unclaimed/stray goods. This whole thing reached a turning point when the PM Indira Gandhi was gunned down by her own security guards. This incident put the Indian govt on offensive like never before and resulted in significant clampdown on the separatists.

I sincerely hope that our government and we as citizens treat the Mumbai attack at that level and make a significant attempt to raise the bar before the next set of attacks. I am sure in next few days the media will be filled with concerned people who would be sharing thoughts and ideas on how to make things better. But the real challenge, as always, will be to go to next level and attempt to continue to convert the thoughts and ideas into actions. In that sense, this act of terrorism seems to have happened at a time when the govt is under significant pressure due to the elections. In addition to that, there seems to have been an attempt by the influential people (with the help from media) in various verticals to push for reforms at various levels to ensure that such a thing does not happen going forward.

Only the time will tell whether this day would be just another day in the the list of days on which terrorists won or a day on which India resolved to never let others take the Indian concept of "chalta hai" attitude for granted.

Tuesday, January 10, 2006

x86 Virtualization: Keep moving

The virtualization process on the x86 platform has really taken off in the market. The best part is that this process has taken place in both directions.
The hardware virtualization process has been moving at a fast pace (especially in development environment, production environment seems to be a different story or may be I do not know the story) with availability of both vendor products like VMWare ESX, Microsoft Virtual Server and opensource products like Xen 3.0 (on Intel IVT and AMD's Pacifica chips - still looking for a big yes from the community on whether it works). I guess when something like this becomes an important part of the development environment for a small company like mine, I think it really has moved far along.
At the same time, the virtualization has been developing from top to bottom starting with language (like Java and .NET). This means that at the moment we have two virtualization environment i.e. at the top and at the bottom with Operating System in the middle.
Isn't it time to start the virtualization process for the OS itself? The product like Azul seems to have taken some steps toward that but being language dependent and properitory designs, they do not fit the bill of OS virtualization. Is this time to really start thinking about completely moving away from the monolithic kernels like Microsoft Windows and Linux and start adopting the Micro-kernel architecture (or that version of existing OS) so that people can pick and choose the components to build the environment such that if you are running servers, you can remove all the User Interface components from the operating system without the need of recompiling the kernel of the Operating System. This way you can pick and choose the components that you need to build the OS environment and hence different components for each of the part of the OS so that systems can leaverage built-in features of chips to make a smaller memory and storage footprint and more efficient systems.

Thursday, December 01, 2005

Protegrity: Database Encryption

Need to get more information about what is really going on and how this technology can help in data privacy initiatives.

Application Dependency Scanner

May be worth something to look at for basic applications. But, my basic problem still remaind dynamic dependencies added due to configurable class names, etc. So it probably may not help. Another thing to look at!!

Wednesday, November 30, 2005

A Recipe for Newspaper Survival in the Internet Age

  1. Some of the readers know more about the subject, so allow them to contribute
  2. Others know less about the subject or may have personal agenda. Let "community" handle them via "moderating system" (I think editors also must play a big role in the moderation till the community is not big enough to be self-regulating)
  3. Malicious, obscene content should not be reason for not opening up to readers. Let moderation or editor take care.
  4. reader vs advertiser - well if reader make the medium trustworthy, in long run you will have more revenue. besides that allow advertisers to reply to the things.
  5. Go "Local" and advertise local
  6. Think internet as mainstream medium to grow since all others are being reduced.

Thursday, November 17, 2005

Java XML Tech


(Better) -



- XStream
- Jaxen

James Strachan: Is Ajax gonna kill the web frameworks?

Good Discussion!! The major points seems to be
  • When Client needs to receive remote events (obviously not by polling since that adds burden on server)
  • A very complex "windowing" GUI with a lot of local event generation, validation, etc which can be too much for javascript which is an interpreted (thus slower) language. - My interpretation
  • If the processing rely too much on the business state/session which contains sensitive data (hence needs to be stored some where safe) and in world of SOA there is no place to save them!! - My interpretation
  • Too much pain w.r.t. browser incompatibility and immature frameworks and tool support
  • In-house applications do not need them since the customer is on uniform platform.
  • Debuggin Javascript on browser is terrible - But faster since no compile step and also firefox has good tools(I think)
    • JSEclipse - Not good Enough

    • Thoughts!!
      Browser synched with the latest version of java.
      Standard Browser APIs for accessing Web Page DOM + Object Model
      Swing Platform and layout manager compatible with HTML
      That's JavaStart??