Swift Programming : Future of Apple Softwares

From the starting decades of programming languages it were a discussion topic among developers to find best approaching programming language which could be fast , understandable, easy to handle and maintainable. In WWDC 2014 Apple introduced a new language ‘Swift Programming language ‘ a Object oriented programming language, which will going to be future of Apple Software development. From last two decades Apple uses Objective C for their Mac OS X Software developments as well as from last six years for iOS Software development too.

Swift feels familiar to Objective-C developers. It adopts the readability of Objective-C’s named parameters and the power of Objective-C’s dynamic object model. Objective-C was always a hard language to pick up for new developers. Apple Software developers will also have to see if Swift makes getting started with app development on Apple’s platforms easier, but from a first look at the documentation, it definitely feels more accessible than Objective-C. According to Apple, Swift will provide a number of significant speed advantages to developers. A complex object sort, for example, will run 3.9x faster than an implementation of the same algorithm in Python. That’s also faster than Objective-C, which is 2.8x faster than the Python version.

More About language :-

Like SCALA, Swift makes a distinction between immutable and mutable references. Whereas SCALA uses ‘var’ for mutable and ‘val’ for immutable references, Swift uses ‘var’ and ‘let’. 
Swift supports an enhanced case statement that implements pattern matching, similar to pattern matching in Haskell or Scala, but less powerful. Pattern matching appears to be able to match a test value against one or more cases by comparing values, but not by comparing structure (as is possible in Scala). Pattern matching cases can include conditional tests.
Like many modern languages, Swift supports functions as first-class objects and closures(as did Objective-C, in the form of blocks). Closure syntax in Swift is far less esoteric than block syntax for Objective-C. In addition, it is possible to define inline lambda functions using placeholder syntax for arguments, a bit of syntactic sugar that Objective-C’s blocks lacked.
To provide an example: in Objective-C, declaring a variable holding a block describing a function which took two NSNumber objects and returned an NSString would look like the following:
NSString *(^myBlock)(NSNumber *, NSNumber *);
In Swift, the following suffices:
var myClosure: (Int, Int) -> String
Features :-
Swift has many other features to make your code more expressive:
1.Closures unified with function pointers.
2.Functional programming patterns, e.g.: map and filter.
3.Tuples and multiple return values.
4.Fast and concise iteration over a range or collection.
5.Structs that support methods, extensions, protocols.
6.Generics.

Conclusion :-

Swift incorporates features that support a functional style of programming, such as first-class treatment of functions, closures, clear delineation between mutable and immutable references, and functions such as ‘map’ upon collection types. Like its predecessors, it is small and coherently designed, implementing a carefully selected set of features that contribute to concise yet readable code.

So I hope it will be too enjoyable to learn future of Apple development which will start a new era in the field of Mobile Application development .Let’s Learn..!!!

Posted in Uncategorized | Tagged , , , , | Leave a comment

iOS Development With Various Programming languages

In this competitive world of programming language, iOS and Mac Application Development not only tied with Objective C programming. It come up with a more explosion of other programming languages. After all, early on the iPhone Developer Program License Agreement stated that “no interpreted code may be downloaded or used in an Application except for code that is interpreted and run by Apple’s Documented APIs and built- in interpreters. Apple made changes to the developer license (circa April 2010) which forbade developing iOS applications in any language other than Objective-C and JavaScript (the JavaScript could be used either to build web apps or native apps via the UIWebView). (In September 2010), Apple again changed the developer license to allow the use of scripting languages.

Now , two question arises here :-
1.What programming languages can one use to develop iPhone, iPod Touch and iPad (iOS) applications ?
Ruby, Python, Lua, Scheme, Lisp, Smalltalk, C#, Haskell, action script, JavaScript, Objective-C, C++, C. That’s just the ones that pop into my head right now. I’m sure there’s hundreds if not thousands of others.
2. Also are there plans in the future to expand the amount of programming languages that iOS will support?
Pretty much every programming language community on this planet is currently working on getting their language to run on iOS.

I am going to discuss here different languages with their supportive environment for the iOS development. May be some of IDE’s are paid Or cost a lot rather than developing in Objective C / via Xcode but it beneficial for those who don’t want to learn new languages.

1. Java :- RoboVM translates Java byte code into native ARM or x86 code. Apps run fast directly on the CPU. No interpreter involved. RoboVM includes a Java to Objective-C bridge that makes it possible to call into the native iOS cocoa touch APIs. Objective-C objects can be used just like any other Java object.The compile time tools are GPLv2 licensed. Runtime code is licensed under business friendly licenses, mostly the Apache License v2.0. RoboVM comes with Eclipse and Maven integration. Use the tools you’re used to from the Java world. There are already a number of apps built with the help of RoboVM in the App Store. Easily share code between desktop, Android and iOS apps. The standard classes (java.lang.*, java.util.*, etc) included in RoboVM are based on Android’s runtime.
Reference URL :- http://www.robovm.org

2. Dot Net / C# :- Easily share code between iOS, Android and Windows devices. High-performance compiled code with full access to all the native APIs, including UIKit. Everything you love about .NET, including LINQ, Delegates and Events. Explore APIs as you type with code auto completion. Use your favorite .NET libraries in Xamarin iOS applications. Easily bind third-party native libraries and frameworks. Or use the Xamarin Component Store, which offers dozens of third-party libraries packaged for instant adoption. Xamarin iOS provides full access to iOS APIs. Take advantage of the entire spectrum of rich functionality supplied by the latest version of the platform. Xamarin iOS is frequently updated and ready with all of the latest iOS features—typically on the same day that Apple releases a platform update.
Reference URL :- http://xamarin.com/

3. C++ :- C++Builder iOS apps will have fast native CPU performance and better security than web-based or scripting language based apps. Full visual designer for iOS user interfaces with multiple device types, resolutions, and orientations. With C++Builder, you get a full range of pixel perfect native styled user interface controls, including buttons, list-boxes and combo boxes, to incorporate into your apps. New in XE6! Mobile apps are a revenue generating opportunity for application developers. Now you can monetize your mobile apps by integrating in app purchases and advertising. C++Builder includes iOS local database support for SQLite and embedded InterBase (ToGo and IBLite) via dbExpress, FireDAC and IBX.
Reference URL :- https://www.embarcadero.com/products/cbuilder/ios-development

4. Ruby :-  RubyMotion implements Ruby on top of the Objective-C runtime and Foundation classes. Thanks to this tight integration, Ruby can interface with iOS and OS X very naturally at no performance expense.RubyMotion transforms the Ruby source code of your project into optimized, blazing-fast machine code using a revolutionary, state-of-the-art static compiler, based on LLVM. It’s Ruby, you don’t need to think about managing memory. Ever. RubyMotion will by itself release the objects you create when they are no longer needed. Our memory model, similar to Objective-C ARC in design, does not require any extra memory or processor footprint to allocate and reclaim unused objects. Shipping iOS and OS X devices such as iPhone, iPad and Mac now feature multi core processors. RubyMotion was designed to be re-entrant and without a global lock in order to allow code to be concurrently executed. RubyMotion comes with a nice interface to Grand Central Dispatch that lets you balance heavy work very easily over CPU cores.
Reference URL :- http://www.rubymotion.com/features/

5. Python :- Pythonista comes with some very cool development friendly features like syntax highlighting and code auto-completion. Code completion can be deactivated in the Settings alongside other options enabled by default. he standard libraries are included for Python, but the developer of Pythonista has also created some handy libraries for things specific to the iPhone/iPad. The major problem with the app is the way to import scripts into it. Most of the blame goes to Apple for not allowing importing of scripts from Dropbox. Apple wants to keep the iOS out of the troubles of malicious code execution, and that’s understandable, but the apps are already jailed, so they can’t access files outside its own folders. Pythonista has an URL Scheme, so it can be called from other programs. This makes it perfect for apps on the iPhone like Launch Center Pro on iPhone that supports URL Schemes to start your Python scripts.
Reference URL :- http://toobler.com/blog/getting-started-with-pythonista-building-ios-apps-in-python/

6. Adobe Flash Professional CS6 :- You can use Flash Professional CS6 to create mobile apps for iOS by publishing projects with Adobe AIR. You can follow the same workflow to create mobile apps for Android. Also, using ActionScript, you can leverage native operating system functionality in your apps by adding features that leverage the device’s accelerometer, touch events, microphone, camera, or vibration. You can also integrate ad networks and in-app purchasing systems with your apps. Take example from here
Reference URL :-  http://www.adobe.com/inspire/2012/12/ios-apps-flash-cs6.html

7. Lua Programming :- Ansca Mobile’s Corona allows you to develop your iOS app entirely in Lua. And it’s not just for iOS. You can also develop apps for Android. In fact, you can use the same source code to build both an iOS and an Android app. This adds a compelling reason to use Lua (and, in particular, to use Corona): the ability to easily build cross-platform applications. Corona’s event system lets you handle touches (including multi-touch), access the GPS and the accelerometer, handle animation, and define custom events. There is a powerful graphics system which allows you to draw circles, rectangles and text. There’s a nice feature where you can overlay a web view for doing things like login screens and a sample application provides a library for connecting to Facebook.
Reference URL :- http://www.luanova.org/ioswithlua

8. Lisp Programming :- Creating mobile applications shouldn’t require you to do everything in Java and Objective-C. With mocl, you can put your application logic into a shared Lisp library that runs on both iOS and Android. Furthermore, since mocl runs an expansive subset of Common Lisp, an ANSI standard like C, you can re-use your CL code across many other Common Lisp implementations. Run your code everywhere — and at native speed. Mobile devices are slower and more resource-constrained than their desktop peers. Accordingly, mocl is a highly optimizing Lisp implementation, delivering tight native code via LLVM/Clang. In fact, mocl is so fast that on some benchmarks, it blows away Google’s own Dalvik JVM. With debugging enabled, mocl provides you stack traces that zero in on the source of errors when they occur. Plus, since mocl generates C/Obj-C code, profiling tools like Apple’s Instruments work great, helping you measure and diagnose performance issues, quickly.
Reference URL :- https://wukix.com/mocl

So if you are not interested in Objective C / Objective C++ then go for above IDE’s and their respective languages to make Native iOS applications for Apple app store.

Posted in Uncategorized | Leave a comment

Secure Sockets Layer Handling in iOS

Secure Sockets Layer  – SSL is the standard for encrypting and authenticating messages and identifying users and servers.

iOS mainly Supports SSL with built in commonly trusted root certificate authorities. It means, if certificate was released by a trusted CA installed on iOS and certificate was not revoked (Certificates can be revoked by OCSP – Online certificate Status Protocol ) , the connection is established very easily.

Problem Statement

If you want to buy something from Amazon server and you connect to a server that your DNS server says is amazon.com and send them your order with your credit card details. There may be number of failures :-

  •  You might not connect to actual Amazon server which looks like Amazon, say amezon.com
  •  Someone might be watching packets of your order so they can steal your card details.
  •  Someone change your order details in sender packets.
  •  There may be chance of “Man in the Middle Attack” ( Setting the connection’s proxy server to     his own server on the attacked device then attacker is able to monitor the communication via     the proxy server).

Solution 

In iOS we have mainly two options to solve above problem statement : -

  1. Add server’s  certificate to the App’s sandbox keychain .
  2. Perform Validation Manually.

For both options you need to include a DER – encoded X.509 public certificate in your app OR you may choose to have it on the server and take it via URL scheme in iOS at run time. If your server’s certificate is part of a chain of existing root certificate authority, you should install the root certificate rather than your server’s certificate.

NSBundle *bundle = [NSBundle bundleForClass:[self class]];

NSData *iosTrustedCertDerData =

[NSData dataWithContentsOfFile:[bundle pathForResource:@"ios-trusted-cert"

ofType:@"der"]];

SecCertificateRef certificate =

SecCertificateCreateWithData(NULL,

(CFDataRef) iosTrustedCertDerData);

1. Add server’s certificate to Keychain :-  We can add a certificate to our app’s keychain. This is mainly appropriate when we want iOS to trust certificate for every new socket which creates in application.

- (void) useKeychain: (SecCertificateRef) certificate {

OSStatus err =

SecItemAdd((CFDictionaryRef) [NSDictionary dictionaryWithObjectsAndKeys:

(id) kSecClassCertificate, kSecClass,

certificate, kSecValueRef,

nil],

NULL);

if ((err == noErr) || // success!

(err == errSecDuplicateItem)) { // the cert was already added.  Success!

// create your socket normally.

// This is oversimplified.  Refer to the CFNetwork Guide for more details.

CFReadStreamRef readStream;

CFWriteStreamRef writeStream;

CFStreamCreatePairWithSocketToHost(NULL,

(CFStringRef)@"localhost",

8443,

&readStream,

&writeStream);

CFReadStreamSetProperty(readStream,

kCFStreamPropertySocketSecurityLevel,

kCFStreamSocketSecurityLevelTLSv1);

CFReadStreamOpen(readStream);

CFWriteStreamOpen(writeStream);

} else {

// handle the error.  There is probably something wrong with your cert.

}

}

2. Perform Validation Manually :- If our requirement is only to verify the certificate for the socket which we are creating and for no other sockets in our app. then we can verify our trust in the vert manually. firstly we disable its certificate chain validation in its SSL settings. After that in five simple steps we can evaluate this process.

  • Create a client SSL policy with the hostname of the server.
  • Take out actual certificate from a chain of certificates.
  • Create a trust object from it.
  • Set the anchor certificates, which are the certificates you trust.
  • By comparing anchor certificate and trust object ,we can evaluate the trust object and discover whether the server can be trusted or not.

Self Generated certificates in iOS 

It’s a universal problem in iOS that for Self generated certificates app will generates the result error message “Error Domain=NSURLErrorDomain Code=-1202 “The certificate for this server is invalid..”. To bypass the built-in SSL digital certificate authentication, you need to add the following NSURLConnection delegates.The delegates in short will accept the so called invalid certificate as genuine certificate.

-(BOOL)connection:(NSURLConnection *)connection              canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace {          return [protectionSpace.authenticationMethod      isEqualToString:NSURLAuthenticationMethodServerTrust];

-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {

[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];

[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];

}

How can we create .DER file  – For creating .der you must have a working installation of the OpenSSL software in your mac. And use the openSSL command to convert between formats as follows :-                                                                                                                                           To convert a certificate from PEM to DER:                                                                                         x509 -in input.crt -inform PEM –out output.crt -outform DER

How much differ SSL handling in iOS from other mobile platforms – In iOS every application have it’s own sandbox keychain which have the chain of root certificates. So if we install a certificate in app then it will be specific only to this app rather than other mobile platform as android install certificate in OS, so it will be accessible to other than that app for which we are installing that certificate.

Posted in iOS Development | Tagged , , , , , , | Leave a comment