Tag Archives: apple

Basic Swift for iOS: Core Syntax

Hi guys, I was given a Mac Book Pro recently and thought of learning some iOS development. So as a first step thought of going through the Basics first. And as you now sharing what I learn with other is the number one way of learning…! This blog will go in a format of short notes or points.
So here you go guys…!

Most of the basics are same as most other popular languages, but still there are some changes, Ill be high lighting the serous issues.

We don’t use semi colones at the end of the statements in Swift.
Also we avoid parenthesis when declaring a condition as much as possible, if there is a complex logic its advised you use it, other than that nope.

We follow the camel case naming convention in Swift

Playground

There is a tool called Play Ground in Xcode where you can write some code and observe the results soon as you write them. Its a great tool to learn the basics and to test some complex logics

Variables

In swift you don’t have to mention the type when you are creating a variable, it automatically decides itself according to the values you pass.

var myInt = 32
var myString = "cat"

But if you want to create a variable without assigning a value you can specify it like this

var myVariable :String
var myIntVariable :Int

Constants

Constants are variables with immutable values, so once a value is defined that value cannot be changed after that

So they are declared with the word “let”

let myConstVariable = 32
let myUnChangedVal = "car"

String Interpolation
Ooops don’t get scared by the word. Its basically a way of passing values or concatenating values in between strings.

var name = "Batzee"
var level = 11

just say you got 2 String values which u have to add in between a standard println() statement

println("\(name) is a Level \(level)" Agent in Ingress")

So the out put will be

"Batzee is a Level 11 Agent in Ingress"

So here instead of using ‘+’ operator we are using ‘\()’ operator

Functions

Functions in Swift are created with the key word ‘func’

func eatBurger(){
}

and called using the function name with the paranthesis

eatBurger()

If the function has a return type then the function is written as

func eatBurger() -> Int{
var burgerNo = 3
return burgerNo
}

‘->’ followed by the return type must follow the function before the curly braces starts.

if Statements

if statement is same as you have written an ‘if’ statement anywhere else, but there are certain things you have to consider when writing in Swift.
As always the Swift says it’s best practice if you can avoid the parenthesis around the condition
And on statements that has one line of executable line of code on success also must have it self surrounded by the curly braces unlike other languages, where you can avoid using the curly braces around the single line code.

if  x<500  {
return x
}

Loops

So there are 4 kinds of loops in Swift

The 1st one is the traditional for loop there is not much difference, only thing you have to consider is to remove the parenthesis around the condition

for  var x = 0; x<10 ; x++  {

}

The 2nd one is the for in loop this is something like foreach loop you specify a collection to loop through. Whatever you pass it converts it in to a collection. If you give a range, it loops through the range. If you pass an Array, it loops through the array element, and if you pass a string it converts the String in to character array and loops through the character array elements

Example 1

var total = 0

for x in 1...100{
total = total+x
println()
}

So the x will loop from 1 to 100

Example 2

var name  = "cat"

for y in name{
println(y)
}

here the variable name will be taken as a string array and the out put will be

c
a
t

The 3rd one is the While loop, it is same as any other while loops in other languages, only considerable change is, not necessarily to add the parenthesis around the condition

while condition {
// do if the condition is true
}

The 4th one is the Do While loop, in this there is some noticeable change, the condition is added at the end of the body, this is to run the code inside the body at least once before it checks on the condition

do{
//runs for the 1st time and runs for the second time and after, if the condition is satisfied
}while condition

Range

Range operator is something new in Swift

which is defined by ‘…’ this says to consider the number mentioned in the left of the operator and all the numbers in between it and the number mentioned in the right of the operator.
Also in the Range operator you can control the 1st and the last dot, like ‘..<‘ , ‘>..’ so this basically will work like a for loop

for  x in 1...100 {
println(x)
}

this will print 1 to 100

similarly

for y in 1..<100{
println(y)
}

will print 1 to 99

Switch Cases

So the Switch Statement in Swift has some points to consider .

The case range must be Exhaustive, unlike other languages you cant check only for a handful of conditions but for all the possible values.
for example if you are checking for integer cases, integer is never ending so u have to handle it. In that case you will use the default case to catch all the situations that you don’t want than what u actually wanted.

let chocoCount = 7
Switch chocoCount{

case 0:
//in case 0 do this
case 1:
// in case 1 do this
case 12:
//in case 12 do this
default:
// do this if the cases dont match the given cases

}

Also in Swift’s Switch statements they don’t have the ‘fall through’ option, which automatically falls into another case for a range of cases. In that case we can use the range case, We have already seen what is a range operator does above.
This is how it is done.

switch chocCount{

case 1...7:
//if the case is between 1 and 7 do this
case 8...15:
// if the case is between 8 and 15 do this
default:
break

}

This post is written after learning from a video, so there are some chances that I may have made some mistakes, so please feel free to comment them down, Ill me more happy to correct them. And stay tuned in for more blogs on Swift and iOS development.

Reference: Notes are taken by studying the Swift Essentials from Lynda.com

iBeacon

What is iBeacons?
iBeacon is Apple’s implementation of Bluetooth low-energy (BLE) wireless technology to create a different way of providing location-based information and services to iPhones and other iOS devices. iBeacon arrived in iOS7, which means it works with iPhone 4s or later, iPad (third generation and onwards) iPad mini and iPod touch (fifth generation or later). It’s worth noting the same BLE technology is also compatible with Android 4.3. and above.

Any iOS device that supports sharing data using Bluetooth low energy can beam signals to an iBeacon app. For example, an iPad can both emit and receive an iBeacon signal.

Whether you’ll pick up a signal from a beacon will also vary: walls, doors, and other physical objects will shorten signal range (as Apple notes the signals are also affected by water, which means the human body itself will affect the signals.)

Who will make the beacons?
Apple doesn’t make the beacons itself – these come from third-party manufacturers – for example the Virgin Atlantic trial is using hardware from Estimote.

What is Bluetooth Low Energy?
Thanks to its innovative design, Bluetooth low energy wireless technology consumes only a fraction of the power of Classic Bluetooth radios. Bluetooth low energy technology extends the use of Bluetooth wireless technology to devices that are powered by small, coin-cell batteries such as watches and toys.

Is iBeacons only good for shopping and coupons?
It’s early days for iBeacon – Apple has only been testing it since December last year in its US retail stores. Virgin Atlantic is also conducting trial of iBeacon at Heathrow airport, so that passengers heading towards the security checkpoint will find their phone automatically pulling up their mobile boarding pass ready for inspection. In the London area retail giant Tesco has been testing it in a store, as is Waitrose, while Regents Street is working with retailers to test the technology too.

What’s the difference between iBeacons and NFC?
NFC and iBeacon use different technologies for communication, NFC using near field communication as found in a contactless bank and transit cards (such as the London Oyster Card) whilst iBeacon uses BLE (Bluetooth low energy) which is commonly found in wireless headphones or used for transferring files between phones. Importantly the technologies have very different wireless ranges, NFC being typically 1-5cm and BLE being up to 50m. And NFC needs a light tap from the NFC sensor device so a power will be emitted on the tap and activates the tag to get the information out of it. iBeacon will be emmiting signals periodically to check if a bluetooth signal is available in the surrounding. and if if it finds one and if the conditions match it invokes the app from the phone.

How-Mobile-Payments-Should-Be-Done-Apples-iBeacon-vs.-NFC

Will iBeacon be more expensive than NFC?
iBeacon costs around $20+ and NFC costs $0.20 per tag.

Why does iBeacons matter?
The technology could be a big step towards mobile payments, something smartphone makers have been looking at for a long time without getting it right. Running the technology which breaks through and becomes the standard is going to be very lucrative. As such iBeacon is not the only game in town – PayPal is working on its own ‘PayPal Beacon‘ technology – expected next year – which will allow shoppers to ‘check-in’ and pay for goods from the PayPal account on their phone.

Reference:
http://www.zdnet.com/what-is-apple-ibeacon-heres-what-you-need-to-know-7000030109/
http://rapidnfc.com/blog/100/what_is_difference_between_ibeacon_and_nfc

My Life with Google Play Store

Hi Guys, this time I am back with some experience to share. Due to many requests I got from my developer community fans, I have decided to share my Google Play Store Experience…!

Google_Play_Games

As you know Google Play store is the Official Android App Store, where almost all the android users get their apps from.

So in this article I’ll write some points, in the forms of tips, based on my 2 years of experience with Google Play Store, where I have published more than 36 apps, with total of more than 1 Million User Base(apps downloaded more than 1 000 000 times), lost 7 apps, lost 2 of my play store accounts and running my 3rd account.

Hope the qualifications in the above paragraph will urge you to read the article 😉

Good to Know
Creating a Google Play Store account costs you one time payment of 25 USD.
You can publish unlimited apps till 3 of your apps get suspended for violating their privacy policy and BLA BLA things…!
After market get suspended, they will not allow you to start a Google Play app store from the same account. So you have to start another Account.
😀

Tip 1
When you are planning to publish an app for money(Selling an app for money in app store), unless you have a good client info tracking system don’t do it. Because one guy can buy your app, create backup which gives him the apk of your app, which he will publish in the Open Internet for everyone to get it and have it for Free. So always build free apps with Ads, so whatever happens you will still get money out of the ads.

Tip 2
Before you name your app please check if the word you are going to use in your app is allowed in United States of America. Because USA is the number one android market place with more than 75% of the app downloads happen, also they ban apps which has certain words or names. For example if ‘country x’ is in their black list, they block the apps with ‘country x’ in their names. Which will end up in a big loss to your app and expectations.

Tip 3
One of the easiest way to gain lots of download is to use a brand name(example: batman, Spiderman, Google), or a similar name to a popular app that’s available on that season(example: flappy bird, flappy tin man). But be warned that your app will be suspended sooner or later, even without giving you a warning. And there is no way of getting the app online.
Best tip on this will be use the brand name for sometime and replace them with your own after getting enough rating so your app is visible in the search(Not Recommended, you don’t know when they will suspend the app).

Tip 4
Add some relevant and popular tags in the description before publishing the app, it generates some traffic for your sites.
example: And have fun sharing with your friends on social network. #facebook #instagram

Tip 5
When developing an app always try to set the maximum possible min SDK value, so you will get a wide audience which results in increased download rate. Also if possible take screen shots from 7 inch and 10 inch tablets screen shots of your app and add them(There is a specific section for it in the app publication form), so that will enable the app to be downloaded by the tab owners too.  Don’t care about the ugly interface when installed to a tab(if it is not designed for tabs ), even you can take a normal phone screen shot and create a tablet sized image with image editing tools.
😀

Tip 6
Whenever you publish an app try to get it some 5 star rating with your friend’s help, people think that we are cheating, but the truth is you are actually pushing your app in to the Google play store search a bit so that it gets visible to all the users, so then it is up to the true down loaders to give the real rating for your app.(There are some of the Marketing Strategies I tried and succeeded)
😀

You must understand, publishing apps in the app store is my hobby and not my profession, and I have lots of fun with the play store.

I have written all that came to my mind, this article will be constantly updated.
So tune in…
🙂