Skip to main content

Posts

Showing posts with the label iPhone Game Development

How to convert a decimal number to binary in Swift?

You can convert the decimal value to a human-readable binary representation using the String initializer that takes a radix parameter:
let num = 22 let str = String(num, radix: 2) println(str) // prints "10110"
If you wanted to, you could also pad it with any number of zeroes pretty easily as well:
func pad(string : String, toSize: Int) -> String {     var padded = string     for i in 0..<toSize - countElements(string) {         padded = "0" + padded     }     return padded }
let num = 22 let str = String(num, radix: 2) println(str) // 10110 pad(str, 8)  // 00010110
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our N…

Swift - Integer conversion to Hours/Minutes/Seconds

Define
func secondsToHoursMinutesSeconds (seconds : Int) -> (Int, Int, Int) {   return (seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60) } Use
> secondsToHoursMinutesSeconds(27005) (7,30,5) or
let (h,m,s) = secondsToHoursMinutesSeconds(27005)
The above function makes use of Swift tuples to return three values at once. You destructure the tuple using the let (var, ...) syntax or can access individual tuple members, if need be.
If you actually need to print it out with the words Hours etc then use something like this:
func printSecondsToHoursMinutesSeconds (seconds:Int) -> () {   let (h, m, s) = secondsToHoursMinutesSeconds (seconds)   println ("\(h) Hours, \(m) Minutes, \(s) Seconds") }
Note that the above implementation of secondsToHoursMinutesSeconds() works for Int arguments. If you want a Double version you'll need to decide what the return values are - could be (Int, Int, Double) or could be (Double, Double, Double). You could try something like:
func secondsTo…

Convert Int to String in Swift

Converting Int to String:
let x : Int = 42 var myString = String(x) And the other way around - converting String to Int:
let myString : String = "42" let x: Int? = myString.toInt()
if (x != nil) {     // Successfully converted String to Int }
Or if you're using Swift 2:
let x: Int? = Int(myString)
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.

This article is related to


​Swift,​ iPad,iPhone,iPhone Resources,iPhone Articles,iPhone D…

Does Swift support implicit conversion?

There is no implicitly cast in Swift.
Easy way of conversion in swift is using constructor of particular type.
Like if you want to get Float from double then you can use Float(doubleValue) and Same way if you want to convert float to integer then you can use Int(floatValue).
Like:
let intValue = UInt8(doubleValue)
Beware that you will loose number after decimal point. So, choose a better way. Above conversion is just to help you in understanding.
Note that Swift always chooses Double (rather than Float) when inferring the type of floating-point numbers.
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID t…

Swift - How to convert String to Double

You can simply bridge it like this:
(swiftString as NSString).doubleValue
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.

This article is related to

​Swift,​ iPad,iPhone,iPhone Resources,iPhone Articles,iPhone Development,iPhone Game Development,iPhone Turorial,Mobile Development Tutorials,Mobile Developments

Convert Float to Int in Swift

You can convert Float to Int in Swift language such like,
var myIntValue:Int = Int(myFloatValue) println "My value is \(myIntValue)"
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.

This article is related to

​Swift,​ iPad,iPhone,iPhone Resources,iPhone Articles,iPhone Development,iPhone Game Development,iPhone Turorial,Mobile Development Tutorials,Mobile Developments

What is the difference between -viewWillAppear: and -viewDidAppear:?

In general, this is what I do:
1) ViewDidLoad - Whenever I'm adding controls to a view that should appear together with the view, right away, I put it in the ViewDidLoad method. Basically this method is called whenever the view was loaded into memory. So for example, if my view is a form with 3 labels, I would add the labels here; the view will never exist without those forms.
2) ViewWillAppear: I use ViewWillAppear usually just to update the data on the form. So, for the example above, I would use this to actually load the data from my domain into the form. Creation of UIViews is fairly expensive, and you should avoid as much as possible doing that on the ViewWillAppear method, becuase when this gets called, it means that the iPhone is already ready to show the UIView to the user, and anything heavy you do here will impact performance in a very visible manner (like animations being delayed, etc).
3) ViewDidAppear: Finally, I use the ViewDidAppear to start off new threads to things t…

Looking to understand the iOS UIViewController lifecycle

All these commands are called automatically at the appropriate times by iOS when you load/present/hide the view controller. It's important to note that these methods are attached to UIViewController and not to UIViews themselves. You won't get any of these features just using a UIView.
There's great documentation on Apple's site here. Putting in simply though: ViewDidLoad - Called when you create the class and load from xib. Great for initial setup and one-time-only work.ViewWillAppear - Called right before your view appears, good for hiding/showing fields or any operations that you want to happen every time before the view is visible. Because you might be going back and forth between views, this will be called every time your view is about to appear on the screen.ViewDidAppear - Called after the view appears - great place to start an animations or the loading of external data from an API.ViewWill/DidDisappear - Same idea as WillAppear.ViewDidUnload/ViewDidDispose - In O…

How to set iPhone UI View z index?

UIView siblings are stacked in the order in which they are added to their superview. The UIView hierarchy methods and properties are there to manage view order. In UIView.h:
@property(nonatomic,readonly) UIView *superview; @property(nonatomic,readonly,copy) NSArray *subviews;
- (void)removeFromSuperview; - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index; - (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;
- (void)addSubview:(UIView *)view; - (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview; - (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
- (void)bringSubviewToFront:(UIView *)view; - (void)sendSubviewToBack:(UIView *)view;
The sibling views are ordered back to front in the subviews array. So the topmost view will be:
[parentView.subviews lastObject];
and bottom view will be:
[parentView.subviews objectAtIndex:0];
[parentView bringSubviewToFront:view] will bring the view to the top, but this is only the …

Physics Joints in Unity 2D

The cross-platform game engine Unity has powerful support for creating 2D and 3D games. It's a great choice for aspiring game developers, since it works for most mobile, desktop and console platforms, and even better, it's free to use for lower-revenue developers and studios. One of the key components of Unity are physics joints, which let you create various connections between objects in Unity. Using joints, you can describe a connection between two objects, which means you can simulate the physics of almost any multi-part object you can think of, including doors, sliding platforms, chains or even wrecking balls! :] This tutorial will focus on using joints in Unity 2D, although Unity supports joints in its 3D engine as well.
✔ Read More...
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows th…

iOS : How to sort a NSArray alphabetically?

We can use this line to sort an NSArray,

sortedArray = [anArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

This works great for an array of NSString, however if you want to extend this to another type of object, and sort those objects according to a 'name' property, you should do this instead:

NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
sortedArray=[anArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];

Your objects will be sorted according to the name property of those objects.

If you want the sorting to be case insensitive, you would need to set the descriptor like this

NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:)];

I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just …

How to get list of all founts available in iOS SDK

T
o get list of all founts available in iOS SDK, use the following code,

// List all fonts on iPhone
NSArray *familyNames = [[NSArrayalloc] initWithArray:[UIFontfamilyNames]]; NSArray *fontNames; NSInteger indFamily, indFont; for (indFamily=0; indFamily<[familyNames count]; ++indFamily)     { NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);         fontNames = [[NSArrayalloc] initWithArray:                      [UIFontfontNamesForFamilyName:                       [familyNames objectAtIndex:indFamily]]]; for (indFont=0; indFont<[fontNames count]; ++indFont)         { NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);         }         [fontNames release];     } [familyNames release];
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful t…

Build Missile Command with Sprite Kit: User Interaction

In the previous tutorial, we laid the foundation of our Missile Command game by creating the project, setting up the single-player scene, and adding user interaction. In this tutorial, you'll expand the game experience by adding a multi-player mode as well as physics, collisions, and explosions.
✔ Read More...
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.

This article is related to

iPad,iPhone,iPhone Resources,iPho…

Build Missile Command with Sprite Kit: Project Setup

In this tutorial, you'll learn how to use Apple's Sprite Kit framework to recreate a Missile Command game for the iPad. Along the way, you'll learn more about several core concepts such as, sprites, touches, physics, collisions, and explosions. The goal of the second tutorial is to add physics, collisions, and explosions. The second tutorial also expands the game experience by adding a multi-player mode.
✔ Read More...
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not …

Floaty Balloon: How to Build a Flappy Bird Clone in 2 Hour

Unless you've been living under a rock, you'll have probably heard of a little iOS game called Flappy Bird. Whilst users went nuts over it, the iOS developer community's response to Flappy Bird was a bit less enthusiastic; many criticised it for its poor implementation and relative crudeness. But though several developers declared that they could have built Flappy Bird in an hour, others quietly confessed that, although they could see it was simplistic, they actually wouldn't have the first clue where to begin with writing a game for iOS – even one as simple as Flappy Bird. Games are a hugely popular genre of app, but making games is a somewhat different process to traditional application development. There are dozens of ways to build games on iOS, from cross-platform tools such as Unity, to 3rd party frameworks such Cocos2D, to built-in APIs such as SpriteKit and GLKit. Most app developers have heard of these, but many have never have tried using them. In thi…

Programming Game Controllers in iOS 7

The iOS platform has been somewhat handicapped when it comes to games due to the twin stick interaction paradigm prevalent on games consoles. Even having physical buttons that give tactile feedback about what control the player has used existed on the first Atari consoles which hard glass screens cannot recreate. On screen twin stick controls have improved over the years, but still don't offer the responsive feedback of dedicated hardware controls, and will always have the problem of obscuring part of the user interface and the action going on in the game. All this has changed in iOS7, with Apple quietly announcing the Made For iOS (MFi) Game Controller specification at WWDC 2013 and the first three controllers having come to market 7 months later.
✔ Read More...
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to…

How To Make A Simple iPhone Game with Cocos2D 3.0 Tutorial

What better way to celebrate the brand new 3.0 release of Cocos2D than with a fresh update to a classic tutorial! Cocos2D 3.0 is the latest version of the hugely popular open source iOS framework for developing 2D games, including thousands of App Store games and many top 10 hits. It has great sprite support, a deeply integrated version of the excellent Chipmunk2D physics library, OpenAL sound library, fun effects, and loads more. In this Cocos2D 3.0 tutorial for beginners, you will learn how to create a simple and fun 2D game for your iPhone from start to finish. If you've previously followed the Cocos2D 2.0 Tutorial, then this may feel familiar however you will be utilizing the integrated physics engine to take it to the next level. You can either follow along with this tutorial or just jump straight to the sample project source at the end. And yes, there will be blood, I mean ninjas!
✔ Read More...
I guess you came to this post by searching similar kind of issues in…

Today iOS Development Resources, Open Sources, Articles, Tutorials and Samples

Today iOS Development Resources, Open Sources, Articles, Tutorials and Samples

1- Open Source Component For Easily Creating Customizable Animated Pop-Out Widget Menus



An open source component allowing you to easily create animated pop out menus with a customizable layout (linear, arch, and circular layouts built in), and support for a number of different gestures:

You can find DLWidgetMenu on Github here.
A great component for making animated curved menu.

2- Tutorial: Building A Weather App With Functional Objective-C Programming Using ReactiveCocoa


A tutorial explaining the basics of functional programming in Objective-C using ReactiveCocoa in the creation of a stylish weather app:

You can find the tutorial in two parts here: Part 1, Part 2.
A nice tutorial for those interested in functional programming, and learning some best practices from an experienced iOS developer.

3- Customizable iOS Action Sheet Component With Support For Titles, Images, Maps And More


An open source customizable act…

Today iOS Development Resources, Open Sources, Articles, Tutorials and Samples

Today iOS Development Resources, Open Sources, Articles, Tutorials and Samples 

1- Tutorial: Getting Started With The iOS 7 Speech API

A tutorial demonstrating how to use the iOS 7 speech synthesize API explaining how to choose a voice from the many languages and accents, and speak at a chosen pitch and speed:

You can find the tutorial on the Use Your Loaf site here, and the example code can be found on Github here.
A nice tutorial and example on using the new speech API.
2- Open Source Component For Easily Creating A Custom Progress Indicator From An Image

An open source component allowing you to easily create custom progress views using an image:
You can find TWRProgressView on Github here.
A nice component for custom progress indicators.


3- Example Source Code: An iOS App Allowing You To Find The Nearest Starbucks And Get Directions

An open source example example app allowing the user to find the nearest Starbucks demonstrating how to use core location, maps, and more:

You can find the source…

Today iOS Development Resources, Open Sources, Articles, Tutorials and Samples

Today iOS Development Resources, Open Sources, Articles, Tutorials and Samples 

1- Open Source iOS Contact Picker Control Inspired By The iOS 7 Mail App

An open source control providing a contact picker similar to the  contact selector found in the iOS 7 mail app:

You can find MBContactPicker on Github here.

A nice control for adding a contact picker to your forms.

2- Handy UIImage Category Allowing For Easy Image Blurring, Colored Image Creation And Screenshots


A handy UIImage addon category providing easy image blurring, colored image creation, and app screenshots:
You can find UIImage-Helpers on Github here.

A nice simple category for performing some common uiimage tasks.

If you have an iOS developer resources that you'd like to share you can submit them in below comment section.
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share th…