Posts

Showing posts from April, 2015

Optionals in SWIFT

In SWIFT, an interesting and a powerful feature that i liked mostly is "Optionals" . Can you imagine, how many times you have checked a variable in Objective-C for its Validness, (If it is nil or not) ? How many times do you think, you might have written the below code in Objective-C: NSString *string = someFun() if (string != nil){ //do some stuff with the returned string here } I can’t even count on this, since i do this often throughout my classes. Apple have done a great job to solve this issue with Optional variables. Let’s look into this feature more deeper with an example to understand its use and purpose. Consider, you have an array of strings of Phone Numbers as below: let numbers = [“9876543219”, “9898878890”, “9876556789”] We’ll write a simple function to see if we can find a phone number within the array.     func findNumber (number: String , numbers: [ String ]) -> String {         for tempNumber in numb

Exploring SWIFT

Should have posted this a long back, but just got the perfect time to get it done.  I got a chance to develop an e-Commerce mobile application targeted at iOS8. We decided to develop it using the latest technologies, so we chose to use the SWIFT language released by Apple in Conjunction with iOS8. SWIFT is a safe, modern and powerful Language, it has a lot of interesting, time saving features, which could allow us(Developers) to focus/work more on the Application’s logic rather than the coding itself. Swift’s shorthand syntax makes us to write less code when compared to Objective C. It was a great decision to remove the semicolons(At the end of each statement), Braces (In Control Flows), Subscripts, Enumerations, etc… Some of the very interesting stuff includes: Optionals Tuples Closures Access Control Going briefly into those interesting stuff, that mostly adds value to our code/time. Optionals: The most interesting and powerful featu