<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6223976744110856384</id><updated>2026-09-20T05:28:05.206-07:00</updated><category term="qt"/><category term="QML"/><category term="Qt Quick"/><category term="application"/><category term="BB10"/><category term="game"/><category term="iPhone"/><category term="maemo"/><category term="iphone sdk"/><category term="BlackBerry"/><category term="Cascades"/><category term="c++"/><category term="N900"/><category term="animation"/><category term="iOS"/><category term="iphone application"/><category term="audiobookreader"/><category term="Unity3D"/><category term="sprite animation"/><category term="Audiobook Player"/><category term="sprite"/><category term="ubuntu"/><category term="Harmattan"/><category term="Ovi store"/><category term="Swift"/><category term="iphone game"/><category term="sprite sheet"/><category term="Code"/><category term="Nokia"/><category term="Audiobook"/><category term="MeeGo"/><category term="N950"/><category term="Ubuntu Touch"/><category term="Z10"/><category term="crazy chickens"/><category term="N9"/><category term="android"/><category term="games"/><category term="iOS6"/><category term="iPhone5"/><category term="Qt Quick Components"/><category term="Symbian"/><category term="custom view"/><category term="view switching"/><category term="Camera"/><category term="Data Structure"/><category term="Dev Alpha"/><category term="Gesture"/><category term="Unity 4.3 2D"/><category term="animation framework"/><category term="gamepad"/><category term="mobile application"/><category term="phonon"/><category term="3D animation"/><category term="3d videos"/><category term="Accelerometer"/><category term="GameKit"/><category term="Graphics view"/><category term="Invocation Framework"/><category term="QPainterPath"/><category term="Qt Ambassador"/><category term="Qt creator"/><category term="Sound"/><category term="Swipe gesture"/><category term="UIViewController"/><category term="Unity 4.3"/><category term="custom"/><category term="custom widget"/><category term="device"/><category term="iPod touch"/><category term="image"/><category term="iphone applicatio"/><category term="javascript"/><category term="long press"/><category term="puyo"/><category term="rotation"/><category term="symbian 3"/><category term="tablet"/><category term="3d glasses"/><category term="Amazon web service"/><category term="Audio"/><category term="Built for BlackBerry"/><category term="Color Detection"/><category term="Controller"/><category term="Enum"/><category term="Facebook"/><category term="IBOutlet"/><category term="Interface Builder"/><category term="Item delegate"/><category term="Meta type"/><category term="Multi touch"/><category term="Observer"/><category term="PlayBook"/><category term="QCamera"/><category term="QGraphicsView"/><category term="Screenshot"/><category term="State machine"/><category term="TextEdit"/><category term="UI"/><category term="UIView"/><category term="Unboxing"/><category term="curve"/><category term="custom class"/><category term="custom graphics item"/><category term="design pattern"/><category term="download manager"/><category term="gdb"/><category term="iPad"/><category term="intel"/><category term="list"/><category term="meta system"/><category term="package"/><category term="reaction"/><category term="reaction time"/><category term="remote compiler"/><category term="screen recording"/><category term="scroll"/><category term="scrolling"/><category term="showcase"/><category term="snake"/><category term="tap and hold"/><category term="vibration"/><category term="wine"/><category term="13"/><category term="3D Studio Max"/><category term="3d tv"/><category term="800"/><category term="AWS"/><category term="Animator"/><category term="Array"/><category term="Avtar"/><category term="Backup"/><category term="Bannerghatta"/><category term="Bluetooth"/><category term="Booster"/><category term="Browsing"/><category term="C7"/><category term="Calendar"/><category term="Callback"/><category term="Collection"/><category term="Collision Detection"/><category term="Crazy flight"/><category term="Custom Switch"/><category term="Dialog"/><category term="Drag"/><category term="Drag and Drop"/><category term="Drawing"/><category term="Drop"/><category term="E2742"/><category term="Event"/><category term="Fade effect"/><category term="File dialog"/><category term="Filtering"/><category term="Folder"/><category term="Formating"/><category term="Global Variable"/><category term="Headset"/><category term="Helicopter"/><category term="Image provider"/><category term="Installation"/><category term="Joiku"/><category term="Joikuspot"/><category term="KVO"/><category term="Keycode"/><category term="LED"/><category term="LG"/><category term="LVM"/><category term="MADDE"/><category term="Math"/><category term="Math Game"/><category term="MeeGo sdk"/><category term="Mesh"/><category term="Moga"/><category term="MogaPro"/><category term="Momentics IDE"/><category term="NDK"/><category term="NSLayoutConstraint"/><category term="NSNotificationCenter"/><category term="NSOperationQueue"/><category term="NSString"/><category term="NSUserDefaults"/><category term="NSValue"/><category term="Native code"/><category term="Network"/><category term="Nexus 4"/><category term="OAuth"/><category term="Opacity"/><category term="OpenShift"/><category term="Parallax"/><category term="PathLine"/><category term="PathQuad"/><category term="Phone"/><category term="Plug-in"/><category term="Port-A-Thon"/><category term="Priority Queue"/><category term="Priority Quque"/><category term="Property Change"/><category term="QDeclarativeListProperty"/><category term="QDir"/><category term="QGraphicsItem"/><category term="QListView"/><category term="QPainter"/><category term="QPropertyAnimation"/><category term="QScrollArea"/><category term="QStateMachine"/><category term="QTimer"/><category term="QWebView"/><category term="QmKeys"/><category term="QmSystem"/><category term="Qt SDK"/><category term="Qt plug-in framework"/><category term="Qvariant"/><category term="SD Card"/><category term="Scene"/><category term="Scope"/><category term="Search"/><category term="Segue"/><category term="SteelSeries"/><category term="String"/><category term="Touch"/><category term="UIButton"/><category term="UIResponder"/><category term="Unboxking"/><category term="Unity 2D"/><category term="Unity 5"/><category term="VMWare"/><category term="Web application"/><category term="adam tablet"/><category term="adaptor"/><category term="album art"/><category term="algorithm"/><category term="anna"/><category term="apk"/><category term="backtracking"/><category term="bar"/><category term="belle"/><category term="book"/><category term="border"/><category term="brain training"/><category term="c#"/><category term="chopper"/><category term="class"/><category term="color match"/><category term="colormatch"/><category term="constraint"/><category term="contest"/><category term="control panel"/><category term="cover art"/><category term="custom drawing"/><category term="custom object"/><category term="debian"/><category term="debugging"/><category term="dragon killer"/><category term="dual boot"/><category term="encryption"/><category term="fade"/><category term="font"/><category term="game play"/><category term="gimp"/><category term="gitorious"/><category term="google"/><category term="google maps"/><category term="google transit"/><category term="grub"/><category term="grub rescue"/><category term="help system"/><category term="hmacsha1"/><category term="hot key"/><category term="iPod"/><category term="image editor"/><category term="imuz"/><category term="joystick"/><category term="linux"/><category term="live cd"/><category term="live wallpaper"/><category term="local class"/><category term="login"/><category term="logitech"/><category term="logitech touch mouse"/><category term="lumia"/><category term="lzo"/><category term="mapkit"/><category term="maps"/><category term="marquee text"/><category term="masking image"/><category term="metadata"/><category term="metatype"/><category term="mirroring"/><category term="monitor"/><category term="movie"/><category term="n8"/><category term="n97"/><category term="national park"/><category term="nested function"/><category term="objective c"/><category term="operator overloading"/><category term="outlook"/><category term="pimp"/><category term="porting"/><category term="potraits"/><category term="print screen"/><category term="protocol"/><category term="puzzle"/><category term="qt webview"/><category term="rda"/><category term="recordmydesktop"/><category term="remote device access"/><category term="resize event"/><category term="root"/><category term="rootsh"/><category term="samsung"/><category term="screen cast"/><category term="sharing connection"/><category term="signature"/><category term="sis file"/><category term="speed match"/><category term="ssh"/><category term="stream operator"/><category term="svg"/><category term="the math game"/><category term="tien len"/><category term="tiger"/><category term="tmg"/><category term="touch mouse"/><category term="transit"/><category term="tx72"/><category term="ubuntu64"/><category term="video cutter"/><category term="video editor"/><category term="virtual"/><category term="wallpaper"/><category term="web service"/><category term="white tiger"/><category term="wifi"/><category term="window phone"/><category term="windows"/><category term="windows phone"/><category term="xaml"/><category term="youtube"/><title type='text'>Qt ,Maemo and some other stuff</title><subtitle type='html'>Sharing information related to Qt, Maemo development and some other information</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>217</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-3513138215701323882</id><published>2015-10-10T22:25:00.001-07:00</published><updated>2015-10-10T22:25:46.540-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Custom Switch"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone application"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone game"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone sdk"/><category scheme="http://www.blogger.com/atom/ns#" term="UI"/><category scheme="http://www.blogger.com/atom/ns#" term="UIView"/><category scheme="http://www.blogger.com/atom/ns#" term="UIViewController"/><title type='text'>Custom UISwitch in iOS</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I wanted to create Custom UISwitch in my iOS game. Initially I just waned to change size, font and color and for that I used UICustomSwitch from Hardy Macia found at &lt;a href=&quot;https://github.com/suoinguon/taogiaothong-ios/blob/master/TaoGiaoThong/UICustom/UICustomSwitch.m&quot;&gt;here&lt;/a&gt;. It&#39;s quite easy to use and customisable, but then I wanted to switch to use custom image instead of standard one. For that I need to modify code a bit, below is the code which use custom image to create UISwitch. BTW this is how it looks&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4xLQOhYqtHkzSJpCjUXWi1wKZe_EDwPS-_LlRVoAknDHpcBqOXA4MljQlsjd-3JgYp0X8OhRDOla7hC8uY5rvEOmjH30XbCmMiTWq_AS5qCE3qew4PXFw3apMuWViS-27lS6kGIahv84k/s1600/iOS_Custom_Switch.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;312&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4xLQOhYqtHkzSJpCjUXWi1wKZe_EDwPS-_LlRVoAknDHpcBqOXA4MljQlsjd-3JgYp0X8OhRDOla7hC8uY5rvEOmjH30XbCmMiTWq_AS5qCE3qew4PXFw3apMuWViS-27lS6kGIahv84k/s320/iOS_Custom_Switch.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Header is same as original implementation, but I removed unnecessary properties and added left and right images required to display on and off images for switch.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;@interface UICustomSwitch : UISlider {
    BOOL on;
    UIImageView* leftImage;
    UIImageView* rightImage;
 
    BOOL touchedSelf;
}

@property(nonatomic,getter=isOn) BOOL on;
@property (nonatomic, retain) UIImageView* leftImage;
@property (nonatomic, retain) UIImageView* rightImage;

- (void)setOn:(BOOL)on animated:(BOOL)animated;

@end
&lt;/pre&gt;
Now lets see implementation. Below is code for initialising the UISwitch with custom rect. You can also see we are adding On and Off image as left and right subview to switch.

&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;-(id)initWithFrame:(CGRect)rect
{    
    if ((self=[super initWithFrame:rect])) {
 [self awakeFromNib];
    }
    return self;
}

-(void)awakeFromNib
{
    [super awakeFromNib];
 
    self.backgroundColor = [UIColor clearColor];
    
    [self setThumbImage:[Util imageNamed:@&quot;switch&quot;] 
        forState:UIControlStateNormal];
    [self setMinimumTrackTintColor:[UIColor clearColor]];
    [self setMaximumTrackTintColor:[UIColor clearColor]];
    
    self.minimumValue = 0;
    self.maximumValue = 1;
    self.continuous = NO;
 
    self.on = NO;
    self.value = 0.0;
 
    self.leftImage = [[UIImageView alloc] initWithFrame:self.frame];
    self.leftImage.image = [Util imageNamed:@&quot;on&quot;];
    [self addSubview: self.leftImage];
    [self.leftImage release];
    
    self.rightImage = [[UIImageView alloc] initWithFrame:self.frame];
    self.rightImage.image = [Util imageNamed:@&quot;off&quot;];
    [self addSubview: self.rightImage];
    [self.rightImage release];
}
&lt;/pre&gt;
&lt;br /&gt;
Now you should be able to see UISwitch with custom images, we now need to add code required to on and off switch from code and change image accordingly.

&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;- (void)setOn:(BOOL)turnOn animated:(BOOL)animated;
{
    on = turnOn;
 
    if (animated) {
 [UIView beginAnimations:@&quot;UICustomSwitch&quot; context:nil];
 [UIView setAnimationDuration:0.2];
    }
 
    if (on) {
 self.value = 1.0;
        self.rightImage.hidden = YES;
        self.leftImage.hidden = NO;
    } else {
 self.value = 0.0;
        self.rightImage.hidden = NO;
        self.leftImage.hidden = YES;
    }
 
    if (animated) {
 [UIView commitAnimations]; 
    }
}

&lt;/pre&gt;
&lt;br /&gt;
Now finally we also have to add code to enable interaction.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    [super endTrackingWithTouch:touch withEvent:event];
    touchedSelf = YES;
    [self setOn:on animated:YES];
}

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    [super touchesBegan:touches withEvent:event];
    touchedSelf = NO;
    on = !on;
}

- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
    [super touchesEnded:touches withEvent:event]; 
    if (!touchedSelf) {
 [self setOn:on animated:YES];
 [self sendActionsForControlEvents:UIControlEventValueChanged];
    }
}
&lt;/pre&gt;
That&#39;s it, I hope this will help.
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/3513138215701323882/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/10/custom-uiswitch-in-ios.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/3513138215701323882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/3513138215701323882'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/10/custom-uiswitch-in-ios.html' title='Custom UISwitch in iOS'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4xLQOhYqtHkzSJpCjUXWi1wKZe_EDwPS-_LlRVoAknDHpcBqOXA4MljQlsjd-3JgYp0X8OhRDOla7hC8uY5rvEOmjH30XbCmMiTWq_AS5qCE3qew4PXFw3apMuWViS-27lS6kGIahv84k/s72-c/iOS_Custom_Switch.png" height="72" width="72"/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-2073138121799860269</id><published>2015-08-16T01:23:00.002-07:00</published><updated>2015-08-22T03:40:10.143-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="game"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="iPad"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone game"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone sdk"/><category scheme="http://www.blogger.com/atom/ns#" term="Math"/><category scheme="http://www.blogger.com/atom/ns#" term="Math Game"/><category scheme="http://www.blogger.com/atom/ns#" term="Swift"/><title type='text'>The Math Game for iOS</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
If you have read my previous posts, you might already know I was trying to learn Swift language. While doing so I tried to create a simple game.
&lt;br /&gt;
&lt;br /&gt;
Finally I was able to complete the app and was able to publish it as well. You can download &lt;a href=&quot;https://itunes.apple.com/de/app/the-math-game-by-niku/id1013678552&quot;&gt;app from here.&lt;/a&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGEsoPE_dmg6PIRVu4XXsakjyA8HDoAUu7Tp0wKMdA0i6M6VeHh09AVfi9uLeKVGeJL_1KCU80VOPHzrNBEFipqn8r12vALdj2DsBfHJo0YwdkiKuOwOerF_b0td4F_yY-Jpt-_jN2Vp18/s1600/the_math_game_menu.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: left;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGEsoPE_dmg6PIRVu4XXsakjyA8HDoAUu7Tp0wKMdA0i6M6VeHh09AVfi9uLeKVGeJL_1KCU80VOPHzrNBEFipqn8r12vALdj2DsBfHJo0YwdkiKuOwOerF_b0td4F_yY-Jpt-_jN2Vp18/s200/the_math_game_menu.png&quot; width=&quot;111&quot; /&gt;&lt;/a&gt;

&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPSDL7yVaBi5tIer31SNSx4LdafdN-Zi_dRsKnYScXydbI14jk-muNUdFRPY8ETeR3g_lmo1jwphREmHMOp0sDANMPZrw81GV0czth8pFNWEONbc4grjBy1xfuwH6PlGYQn8E5Ho5V-RsH/s1600/the_math_game_play1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPSDL7yVaBi5tIer31SNSx4LdafdN-Zi_dRsKnYScXydbI14jk-muNUdFRPY8ETeR3g_lmo1jwphREmHMOp0sDANMPZrw81GV0czth8pFNWEONbc4grjBy1xfuwH6PlGYQn8E5Ho5V-RsH/s200/the_math_game_play1.png&quot; width=&quot;111&quot; /&gt;&lt;/a&gt;

&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgszf_9twZZHTQKeBkrwEz31_ts44IN1x3DXWn7enf1iUQD-dWeHM9qQXIxz2jkcGgRyMdZDGWhsAZ47K-kYNUk0XOXSCNJn3H_NSRcXIF84N6b6b9ycfK23rJsQ-lFc5xrJBj_DUpAcEVk/s1600/the_math_game_startgame.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgszf_9twZZHTQKeBkrwEz31_ts44IN1x3DXWn7enf1iUQD-dWeHM9qQXIxz2jkcGgRyMdZDGWhsAZ47K-kYNUk0XOXSCNJn3H_NSRcXIF84N6b6b9ycfK23rJsQ-lFc5xrJBj_DUpAcEVk/s200/the_math_game_startgame.png&quot; width=&quot;111&quot; /&gt;&lt;/a&gt;

&lt;/div&gt;
&lt;br /&gt;
Below is demo of the game.
&lt;br /&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/eS_V6907xts&quot; width=&quot;420&quot;&gt;&lt;/iframe&gt;

&lt;br /&gt;
You can also get more information about &lt;a href=&quot;https://launchkit.io/websites/-AcznufSZUo/&quot;&gt;app here.&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/2073138121799860269/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/08/the-math-game-for-ios.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/2073138121799860269'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/2073138121799860269'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/08/the-math-game-for-ios.html' title='The Math Game for iOS'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGEsoPE_dmg6PIRVu4XXsakjyA8HDoAUu7Tp0wKMdA0i6M6VeHh09AVfi9uLeKVGeJL_1KCU80VOPHzrNBEFipqn8r12vALdj2DsBfHJo0YwdkiKuOwOerF_b0td4F_yY-Jpt-_jN2Vp18/s72-c/the_math_game_menu.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-797189891478581766</id><published>2015-07-17T20:09:00.000-07:00</published><updated>2015-07-17T20:09:02.421-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="GameKit"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone application"/><category scheme="http://www.blogger.com/atom/ns#" term="Swift"/><title type='text'>Displaying Game Centre Leaders board from Swift</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In last post, I showed how we can authenticate local player and how we can post score to default leader board.
&lt;br/&gt;&lt;br/&gt;

In this post, I will show how we can display leader board using swift gamekit API. Below code shows how we can display GKGameCenterViewController.
Game center viewcontroller needs delegate, which is called when view is dismissed. Also we need parent viewcontroller which will be used to display GKGameCenterViewController.

&lt;pre class=&quot;prettyprint&quot;&gt;
func showLeaderboard(viewController: UIViewController, 
    gameCenterDelegate: GKGameCenterControllerDelegate) {
    let gameCenterVC: GKGameCenterViewController = GKGameCenterViewController();
    gameCenterVC.leaderboardIdentifier = defaultLeaderBoard;
    gameCenterVC.gameCenterDelegate = gameCenterDelegate;
    viewController.presentViewController(gameCenterVC, animated: true, completion: nil);
}
&lt;/pre&gt;

Now we have code that can display leader board, but we need to make our class conform to GKGameCenterControllerDelegate protocol and implement required method. Below is code for delegate method. Which simply dismiss presented view controller.
&lt;pre class=&quot;prettyprint&quot;&gt;
func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController!) {
    gameCenterViewController.dismissViewControllerAnimated(true, completion: nil)
}
&lt;/pre&gt;
So, as you can see it&#39;s quite simple. Hope this will be helpful.
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/797189891478581766/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/07/displaying-game-centre-leaders-board.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/797189891478581766'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/797189891478581766'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/07/displaying-game-centre-leaders-board.html' title='Displaying Game Centre Leaders board from Swift'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-3451512891617367691</id><published>2015-07-10T21:14:00.000-07:00</published><updated>2015-07-10T21:14:49.798-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="constraint"/><category scheme="http://www.blogger.com/atom/ns#" term="IBOutlet"/><category scheme="http://www.blogger.com/atom/ns#" term="Interface Builder"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone application"/><category scheme="http://www.blogger.com/atom/ns#" term="NSLayoutConstraint"/><category scheme="http://www.blogger.com/atom/ns#" term="Swift"/><title type='text'>Creating array of IBOutlets of NSLayoutConstraint&#39;s from Swift in iOS</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
While working on my iOS app, I wanted to modify UI Constraint set from Interface Builder from Swift code.

&lt;br/&gt;&lt;br/&gt;
Below video shows how we can create Array of IBOutlets using Interface Builder. Here I am creating array of NSLayoutConstraint, which I want to modify from Swift Code.
&lt;br/&gt;&lt;br/&gt;
&lt;iframe width=&quot;420&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/-I2Y5zFSqbU&quot; frameborder=&quot;0&quot; allowfullscreen&gt;&lt;/iframe&gt;
&lt;br/&gt;&lt;br/&gt;
Now lets see how we can manipulate constraints from swift. First we need to define array of IBOutlet. Below code shows the same.
&lt;pre class=&quot;prettyprint&quot;&gt;
@IBOutlet var constraints: Array&lt;NSLayoutConstraint&gt;?
&lt;/pre&gt;

Now, once you connect IBoutlet from Interface Builder as shown in above video. You can use those. In below code I am modifying NSLayoutConstraint&#39;s constant value.
&lt;pre class=&quot;prettyprint&quot;&gt;
if( Utils.isIPad() ) {
    for constraint: NSLayoutConstraint in constraints! {
        if(Utils.isIPad()) {
            constraint.constant = 30
        }
    }
}
&lt;/pre&gt;
That&#39;s it, Thank you for reading.
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/3451512891617367691/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/07/creating-array-of-iboutlets-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/3451512891617367691'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/3451512891617367691'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/07/creating-array-of-iboutlets-of.html' title='Creating array of IBOutlets of NSLayoutConstraint&#39;s from Swift in iOS'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/-I2Y5zFSqbU/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-1475640575544141227</id><published>2015-06-28T22:37:00.001-07:00</published><updated>2015-06-28T22:37:26.387-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="GameKit"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone application"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone game"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone sdk"/><category scheme="http://www.blogger.com/atom/ns#" term="Swift"/><title type='text'>Posting score to Game Kit Leader board using swift</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
As you might already know, I recently started exploring Swift language and now I am trying out GameKit framework. While I have some experience in working with GameKit using Objective C. I wanted to do the same thing using swift. As such there are no API changes while using GameKit with Swift or Objective C. However there are some syntax change.

&lt;br/&gt;&lt;/br&gt;
In this post, I will show how to Authenticate local player using GameKit framework and post score to LeaderBoard defined in iTune Connect Application setting.

&lt;br/&gt;&lt;/br&gt;
Following is code snippet that shows how to Authenticate Local player. This function takes ViewController as argument. Login dialog will be displayed using this View controller. Rest will be taken care by GameKit framework.
&lt;pre class=&quot;prettyprint&quot;&gt;
func authenticateLocalPlayer(viewController: UIViewController) {
    let localPlayer: GKLocalPlayer = GKLocalPlayer.localPlayer()
    
    localPlayer.authenticateHandler = {(ViewController, error) -&gt; Void in
        if((ViewController) != nil) {
            // 1 Show login if player is not logged in
            viewController.presentViewController(ViewController, animated: true, completion: nil)
        } else if (localPlayer.authenticated) {
            // 2 Player is already euthenticated &amp; logged in, load game center
            self.isGameCenterEnabld = true                
        } else {
            // 3 Game center is not enabled on the users device
            self.isGameCenterEnabld = false
            println(&quot;Local player could not be authenticated, disabling game center&quot;)
            println(error)
        }
        
    }
    
}
&lt;/pre&gt;

Now we have authenticated local player. So when we are ready to post score to Leader Board. We can use below function. Here we are posting score to &quot;defaultLeaderBoard&quot;. Which is identifier of Leader board defined in iTune connect App setting.
&lt;pre class=&quot;prettyprint&quot;&gt;

func submitScore( score: Int) {
    if( !isGameCenterEnabld ) {
        return;
    }
    
    var sScore = GKScore(leaderboardIdentifier: defaultLeaderBoard)
    sScore.value = Int64(score)
    
    let localPlayer: GKLocalPlayer = GKLocalPlayer.localPlayer()
    
    GKScore.reportScores([sScore], withCompletionHandler: { (error: NSError!) -&gt; Void in
        if error != nil {
            println(error.localizedDescription)
        } else {
            println(&quot;Score submitted&quot;)
            
        }
    })
}
&lt;/pre&gt;

That&#39;s it. Hope this will be useful.
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/1475640575544141227/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/06/posting-score-to-game-kit-leader-board.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/1475640575544141227'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/1475640575544141227'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/06/posting-score-to-game-kit-leader-board.html' title='Posting score to Game Kit Leader board using swift'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-4665464368474258263</id><published>2015-06-27T18:42:00.001-07:00</published><updated>2015-06-27T18:42:46.755-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="design pattern"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone application"/><category scheme="http://www.blogger.com/atom/ns#" term="NSNotificationCenter"/><category scheme="http://www.blogger.com/atom/ns#" term="Observer"/><category scheme="http://www.blogger.com/atom/ns#" term="Swift"/><title type='text'>Using NSNotificationCenter in Swift</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
NSNotificationCenter is a convenient method to implement Observer pattern in iOS, something similar to what we say Signal/Slot in Qt framework.
&lt;br/&gt;&lt;br/&gt;

To register one self as observer to some event, you can use addObserver method form NSNotificationCenter. In below code you are adding self as observer, selector is method which will be called when event is triggered, name is name of event or notification in which we are interested in, and object is object from which we want to receive event from, nil means we are ready to receive event from any object.
&lt;br/&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
NSNotificationCenter.defaultCenter().addObserver(
    self, 
    selector: &quot;gameViewClosed&quot;, 
    name: &quot;gameViewClosed&quot;, 
    object: nil);
&lt;/pre&gt;

Now to trigger the notification, you can use postNotificationName method from NSNotificationCenter. Following code shows the same. Here we are sending notification for &quot;gameViewClosed&quot; event, object nil mean deliver event to all interested objects.
&lt;br/&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
NSNotificationCenter.defaultCenter().postNotificationName(
    &quot;gameViewClosed&quot;, 
    object: nil);
&lt;/pre&gt;

That&#39;s it, thanks for reading.
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/4665464368474258263/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/06/using-nsnotificationcenter-in-swift.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/4665464368474258263'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/4665464368474258263'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/06/using-nsnotificationcenter-in-swift.html' title='Using NSNotificationCenter in Swift'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-9190952322812417903</id><published>2015-06-25T19:11:00.000-07:00</published><updated>2015-06-25T19:11:25.154-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="Sound"/><category scheme="http://www.blogger.com/atom/ns#" term="Swift"/><title type='text'>Playing sound using Swift </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Posting small code snippet to that shows how to play sound using Swift in iOS.

&lt;br/&gt;&lt;br/&gt;
First we need to import AVFoundation.
&lt;pre class=&quot;prettyprint&quot;&gt;
import AVFoundation
&lt;/pre&gt;

Then we need to create instance of AVAudioPlayer. I created a small utility function like below for the same.

&lt;pre class=&quot;prettyprint&quot;&gt;

private static func createAudioPlayer
( sound: String, type: String ) -&gt; AVAudioPlayer {

    var error:NSError?;
    let soundUrl = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(sound, ofType: type)!);
    println(soundUrl)
    
    var player = AVAudioPlayer(contentsOfURL: soundUrl, error: &amp;error);
    player.prepareToPlay();
    return player;
}

&lt;/pre&gt;

And this function can be used like below.
&lt;pre class=&quot;prettyprint&quot;&gt;
public init() {
    // Removed deprecated use of AVAudioSessionDelegate protocol
    AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil);
    AVAudioSession.sharedInstance().setActive(true, error: nil);
    
    correctAns = MusicHelper.createAudioPlayer(&quot;correctAns&quot;, type: &quot;wav&quot;);
    wrongAns = MusicHelper.createAudioPlayer(&quot;wrongAns&quot;,type: &quot;wav&quot;);
}
&lt;/pre&gt;

Now we can use AVAudioPlayer&#39;s play API to play the sound. Like below.
&lt;pre class=&quot;prettyprint&quot;&gt;

public func playCorrectAnsSound() {
    correctAns.play();
}

public func playWrongAnsSound() {
    wrongAns.play();
}

&lt;/pre&gt;

That&#39;s it, thanks for reading.
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/9190952322812417903/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/06/playing-sound-using-swift.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/9190952322812417903'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/9190952322812417903'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/06/playing-sound-using-swift.html' title='Playing sound using Swift '/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-8795728612517111058</id><published>2015-06-07T02:23:00.000-07:00</published><updated>2015-06-07T02:23:33.212-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="custom view"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS6"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone applicatio"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone game"/><category scheme="http://www.blogger.com/atom/ns#" term="Segue"/><category scheme="http://www.blogger.com/atom/ns#" term="Swift"/><category scheme="http://www.blogger.com/atom/ns#" term="UIViewController"/><category scheme="http://www.blogger.com/atom/ns#" term="view switching"/><title type='text'>Performing Segue and Passing data in iOS</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I was trying to learn how to perform view switching using Segue for UI created by StoryBoard. Using Segue is quite easy and convenient. You can create Segue from Interface Builder, which associate action to view. Like if you click some button then you can associate this click action with view switch and you can select which view to switch to. This all is quite simple and can be done using simple drag and drop.

&lt;br/&gt; &lt;br/&gt;
In case you want to perform view switch manually without any user interaction, you can call &quot;performSegueWithIdentifier&quot;, like below. Here once my game is finished, I am calling &quot;GameOverSegue&quot;, which will switch view to GameOver view.

&lt;pre class=&quot;prettyprint&quot;&gt;
self.performSegueWithIdentifier(&quot;GameOverSegue&quot;, sender: self)
&lt;/pre&gt;

If you want to pass some data while performing Segue, your calling ViewController needs to override &quot;prepareForSegue&quot; function. In this function you can set data to called view. Like below, I want to pass score to my GameOver view.
&lt;pre class=&quot;prettyprint&quot;&gt;
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if( segue.identifier == &quot;GameOverSegue&quot;) {
        let gameOverVC: GameOverViewController = 
            segue.destinationViewController as! GameOverViewController;
        gameOverVC.setScore(self.score)
    }
}
&lt;/pre&gt;
Thanks, hope this will be helpful.
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/8795728612517111058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/06/performing-segue-and-passing-data-in-ios.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/8795728612517111058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/8795728612517111058'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/06/performing-segue-and-passing-data-in-ios.html' title='Performing Segue and Passing data in iOS'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-6232117267041018882</id><published>2015-06-06T19:20:00.000-07:00</published><updated>2015-06-06T19:20:05.486-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="border"/><category scheme="http://www.blogger.com/atom/ns#" term="Drawing"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS6"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone application"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone5"/><category scheme="http://www.blogger.com/atom/ns#" term="Swift"/><title type='text'>Drawing round border around UIView in iOS</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

I wanted to create a subview UIView with round border in iOS. I found following code works very well to draw round border around UIView. While this code is written swift you can easily write similar code in Objective C as well.

&lt;br/&gt;&lt;br/&gt;
Following is the code. As you can see, I selected subview UIView and made is IBOutlet using Interface Builder. Once that is done you can see round border around view.

&lt;pre class=&quot;prettyprint&quot;&gt;

@IBOutlet weak var contentView: UIView?
    
override func viewDidLoad() {
    super.viewDidLoad();
        
    contentView?.layer.borderWidth = 3.0
    contentView?.layer.borderColor = UIColor(red:102/255,green:102/225,blue:102/225, alpha:1).CGColor
    contentView?.layer.cornerRadius = 14
}
    
&lt;/pre&gt;

And following how it looks.

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj27ZbL915rIbFI11GYxx_VxqoZyDENoMrd6hDydrRKBJtGgwHl5dDj6iykXK6KuTw-dEsICBrHtnLqnSWpjiMdtGHF9wfcjTxJk6LBrbBdmfsNtdQxF2P7v9TDg1Ed2VCT46NNsBlmYeRF/s1600/round_+border_UIVIew.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj27ZbL915rIbFI11GYxx_VxqoZyDENoMrd6hDydrRKBJtGgwHl5dDj6iykXK6KuTw-dEsICBrHtnLqnSWpjiMdtGHF9wfcjTxJk6LBrbBdmfsNtdQxF2P7v9TDg1Ed2VCT46NNsBlmYeRF/s640/round_+border_UIVIew.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/6232117267041018882/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/06/drawing-round-border-around-uiview-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/6232117267041018882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/6232117267041018882'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/06/drawing-round-border-around-uiview-in.html' title='Drawing round border around UIView in iOS'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj27ZbL915rIbFI11GYxx_VxqoZyDENoMrd6hDydrRKBJtGgwHl5dDj6iykXK6KuTw-dEsICBrHtnLqnSWpjiMdtGHF9wfcjTxJk6LBrbBdmfsNtdQxF2P7v9TDg1Ed2VCT46NNsBlmYeRF/s72-c/round_+border_UIVIew.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-9113391449568881711</id><published>2015-06-05T20:18:00.000-07:00</published><updated>2015-06-05T20:18:52.828-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="game"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone application"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone game"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone sdk"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone5"/><category scheme="http://www.blogger.com/atom/ns#" term="Swift"/><title type='text'>Hiding status bar in iOS8 using Swift</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I recently started learning swift, while learning I started to create simple game. I wanted to make my game full screen, but I was unable to hide top status bar from Interface builder. No matter what I change that status bar was always visible.

&lt;br/&gt;&lt;br/&gt;

Buf I found following code snippet, if you add this code in your View Controller file, you can easily hide status bar.

&lt;pre class=&quot;prettyprint&quot;&gt;
override func prefersStatusBarHidden() -&gt; Bool {
    return true;
}
&lt;/pre&gt;

Following how my ViewController file looks after adding this code.
&lt;pre class=&quot;prettyprint&quot;&gt;
class ViewController: UIViewController {
        
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    override func prefersStatusBarHidden() -&gt; Bool {
        return true;
    }
}
&lt;/pre&gt;

That&#39;s it. Hope this will be hopeful.
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/9113391449568881711/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/06/hiding-status-bar-in-ios8-using-swift.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/9113391449568881711'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/9113391449568881711'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/06/hiding-status-bar-in-ios8-using-swift.html' title='Hiding status bar in iOS8 using Swift'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-8792620908045351724</id><published>2015-05-03T22:47:00.002-07:00</published><updated>2015-05-03T22:47:28.150-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="3D animation"/><category scheme="http://www.blogger.com/atom/ns#" term="animation"/><category scheme="http://www.blogger.com/atom/ns#" term="animation framework"/><category scheme="http://www.blogger.com/atom/ns#" term="Animator"/><category scheme="http://www.blogger.com/atom/ns#" term="sprite animation"/><category scheme="http://www.blogger.com/atom/ns#" term="State machine"/><category scheme="http://www.blogger.com/atom/ns#" term="Unity 2D"/><category scheme="http://www.blogger.com/atom/ns#" term="Unity 5"/><category scheme="http://www.blogger.com/atom/ns#" term="Unity3D"/><title type='text'>Color Animation using Animator with Unity3D</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I created a small demo application to demonstrate how Animation can be done using Animator and State Machine with Unity5. This demo creates a Blinking Animation on Mouse click.
&lt;br /&gt;
&lt;br /&gt;
Following is final output of this demo.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/DANGeHrYDVg&quot; width=&quot;420&quot;&gt;&lt;/iframe&gt;

&lt;br /&gt;
Below post shows, how above animation can be created.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;-&amp;gt;&lt;/b&gt; To begin, First create a simple cube and apply a material on the cube. Setup should look like below.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWrtgzD_eUE5r6KbwXu17panelDtP_LZMlUcXTMPzd067mm_H7VfI4MdD4eg_KP7QyUoX_QOZn3iUVKAzNtFFYFbJgje7KQ4JmFCGairQh1B3eLNGiBCc7qsdW38ELzw-KGnMwtDpBUg_h/s1600/Screen+Shot+2015-05-04+at+12.16.09+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;604&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWrtgzD_eUE5r6KbwXu17panelDtP_LZMlUcXTMPzd067mm_H7VfI4MdD4eg_KP7QyUoX_QOZn3iUVKAzNtFFYFbJgje7KQ4JmFCGairQh1B3eLNGiBCc7qsdW38ELzw-KGnMwtDpBUg_h/s640/Screen+Shot+2015-05-04+at+12.16.09+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;-&amp;gt;&lt;/b&gt; Then using &quot;Add Component&quot;, add Animator to this cube.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKunkYIq-exL7GsLKEbm9dWyWxHRGmbJN605dr4VnAhpeCXCg1JHQJYzhDqEOBeyGrpLmzcUcEoKpfBouY4-qUWiuZscvoi5Spgb-g9a3oEYClw4uqEwoSbp3jQ0QvDQudZJTdZLwtHY2p/s1600/Screen+Shot+2015-05-04+at+12.17.08+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKunkYIq-exL7GsLKEbm9dWyWxHRGmbJN605dr4VnAhpeCXCg1JHQJYzhDqEOBeyGrpLmzcUcEoKpfBouY4-qUWiuZscvoi5Spgb-g9a3oEYClw4uqEwoSbp3jQ0QvDQudZJTdZLwtHY2p/s640/Screen+Shot+2015-05-04+at+12.17.08+PM.png&quot; width=&quot;248&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;-&amp;gt; &lt;/b&gt;Once Animator is added, open Animation window using &quot;Window&quot; -&amp;gt; &quot;Animation&quot;, We will need to use while performing the animation. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgD_JOz8vZLrR__SQghhzw71Epr0QLItQlIReG7nUDSPgbgLGk5uX53UAKa69SGfc8l-quFzTe_JJxKfGXPLdOb24Vn_k_nhdaIav-Ksc5pT_eg_N5k5ov4PVoufqnOQgDW5sWbVk6TwikZ/s1600/Screen+Shot+2015-05-04+at+12.17.52+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;322&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgD_JOz8vZLrR__SQghhzw71Epr0QLItQlIReG7nUDSPgbgLGk5uX53UAKa69SGfc8l-quFzTe_JJxKfGXPLdOb24Vn_k_nhdaIav-Ksc5pT_eg_N5k5ov4PVoufqnOQgDW5sWbVk6TwikZ/s640/Screen+Shot+2015-05-04+at+12.17.52+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Animator performs animation using State Machine and this state machine should have default state. Animator will transit to this default State when object is created. In Animator, Animation clip is considered as a State, so lets add a Animation clip and name it default. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSkibHf2R53dxC6TUSGWOdXEzk_KeSaYztX5ZhYFGUGiNOcduW818bSDKxLyRpB2Xn5H8sPT_vXAo5AFMTCllm1cXC9TQUEHrVHdjysP9FVGtSqSFHGTxvdDrbPMForrJpaQ8rmqSbJ3VP/s1600/Screen+Shot+2015-05-04+at+12.19.19+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;474&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSkibHf2R53dxC6TUSGWOdXEzk_KeSaYztX5ZhYFGUGiNOcduW818bSDKxLyRpB2Xn5H8sPT_vXAo5AFMTCllm1cXC9TQUEHrVHdjysP9FVGtSqSFHGTxvdDrbPMForrJpaQ8rmqSbJ3VP/s640/Screen+Shot+2015-05-04+at+12.19.19+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;b&gt;-&amp;gt;&lt;/b&gt; Our default state will not have any animation, it should show just initial color. Let&#39;s just add one frame with current color. Like below.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTxW1bdpxuYk5_JsMn8iWK5xTwq1fJ8jlbleSgngyq0qK4iUMm7vxjPBInw9tHwKAQP-Iw0bfO2llBhw0IUffiWt4j8s0aUgILkWgLLWwPwiIwmSjxr8dZsHNOqPvxPwGKHnzhcjIafuBG/s1600/Screen+Shot+2015-05-04+at+12.20.15+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;198&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTxW1bdpxuYk5_JsMn8iWK5xTwq1fJ8jlbleSgngyq0qK4iUMm7vxjPBInw9tHwKAQP-Iw0bfO2llBhw0IUffiWt4j8s0aUgILkWgLLWwPwiIwmSjxr8dZsHNOqPvxPwGKHnzhcjIafuBG/s640/Screen+Shot+2015-05-04+at+12.20.15+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;-&amp;gt;&lt;/b&gt; Now we have default state, let&#39;s add another state which will perform &quot;Blinking&quot; animation. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZNbMdkNXN2oUZfQKz9TJK_xulXC1-8_nc97fAWw_QtppaKvVqnZLm3A4mNZ2ftT3DPJAkO63iGAPd645Odx4xLle7ml4XkbeemVNe2s2n5q1Sl4n3Ck7sOuqrDSTbUokThj0XEcuhBw55/s1600/Screen+Shot+2015-05-04+at+12.22.09+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;502&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZNbMdkNXN2oUZfQKz9TJK_xulXC1-8_nc97fAWw_QtppaKvVqnZLm3A4mNZ2ftT3DPJAkO63iGAPd645Odx4xLle7ml4XkbeemVNe2s2n5q1Sl4n3Ck7sOuqrDSTbUokThj0XEcuhBw55/s640/Screen+Shot+2015-05-04+at+12.22.09+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoOI-68fp52z5BxxAi8PR2brIe1n1DlEJHqc5gixOR1A8jasUNFXgLQLWjwB5dLTz3jALkfzJ8MoGwSnVJ1t451IRK_3h-VYjJ6Nqm6iTOK5LpFpblzJdWqVoC9RHAfyAD-QtoNKMXz5fF/s1600/Screen+Shot+2015-05-04+at+12.22.21+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;258&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoOI-68fp52z5BxxAi8PR2brIe1n1DlEJHqc5gixOR1A8jasUNFXgLQLWjwB5dLTz3jALkfzJ8MoGwSnVJ1t451IRK_3h-VYjJ6Nqm6iTOK5LpFpblzJdWqVoC9RHAfyAD-QtoNKMXz5fF/s640/Screen+Shot+2015-05-04+at+12.22.21+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;-&amp;gt;&lt;/b&gt; Now we should add frames, so let&#39;s add color property and frames to animate color. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibGiewuE2pW3cw01aM5yi4T3LGHrBc9oQeTU-4s7Vsv8OCgU9HkbatLu3h-iqiwoxYYddHF1Jtaf92zis5AyNPEJLpKdTNRZK0BmHFj8jiGikdDHtnQLBCyY-Ana8zIHblZBYdhR4E711D/s1600/Screen+Shot+2015-05-04+at+12.21.40+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;382&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibGiewuE2pW3cw01aM5yi4T3LGHrBc9oQeTU-4s7Vsv8OCgU9HkbatLu3h-iqiwoxYYddHF1Jtaf92zis5AyNPEJLpKdTNRZK0BmHFj8jiGikdDHtnQLBCyY-Ana8zIHblZBYdhR4E711D/s640/Screen+Shot+2015-05-04+at+12.21.40+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGTG3Nz2gS0HCRbXZpl_z2cNRczHmizAqhpMBQsfVcSSWxUV-fV9LfH_xxl1-4Lrb-rMJDSCKB1ZBW8K4nuoyKHHkEreP-Ncy4vpDU0uiDweqYexEX1ik42L7EowVoAjkDhABJL5h-J2H6/s1600/Screen+Shot+2015-05-04+at+12.23.13+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;286&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGTG3Nz2gS0HCRbXZpl_z2cNRczHmizAqhpMBQsfVcSSWxUV-fV9LfH_xxl1-4Lrb-rMJDSCKB1ZBW8K4nuoyKHHkEreP-Ncy4vpDU0uiDweqYexEX1ik42L7EowVoAjkDhABJL5h-J2H6/s640/Screen+Shot+2015-05-04+at+12.23.13+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
After adding these frames color should animate like below.
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/h1nTlFE6Tfo&quot; width=&quot;420&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;-&amp;gt;&lt;/b&gt; Now we have Blinking animation state, we are now ready to create a State Machine. Open Animator window by clicking on &quot;Animator&quot; object, it should look like below. &lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZxqHOLY-J9qnwwnOZxe7i8mVf5wnZHn2IiBJQUjzbR8qUuUS1vNCRoB_M6xLdZ4cnTa3FLF9fZHvD70jd6_QCPgxKv00tSbkjmHjgz4CUSQzxxAIYMFzdtBHUMjocmEtrj8Gr_4YRbDlX/s1600/Screen+Shot+2015-05-04+at+12.29.03+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZxqHOLY-J9qnwwnOZxe7i8mVf5wnZHn2IiBJQUjzbR8qUuUS1vNCRoB_M6xLdZ4cnTa3FLF9fZHvD70jd6_QCPgxKv00tSbkjmHjgz4CUSQzxxAIYMFzdtBHUMjocmEtrj8Gr_4YRbDlX/s640/Screen+Shot+2015-05-04+at+12.29.03+PM.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;-&amp;gt;&lt;/b&gt; We should now add a Parameter which will be used to Trigger animation. On &quot;Animator&quot; window add new boolean parameter and name it &quot;blink&quot;. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheENkqa3PpPhLbOaVUmx54Wm5wVUaqllMG1BZZ1aWX35-w4hP-lCW4wCTvVcaB-P6FtOyovcDt0gIpSAF5N5JmiU2Eoelnxu5S_AX9H9S-bIaB8nkLeVl_F3ahT3kjNdJerEPoWhns1Zn-/s1600/Screen+Shot+2015-05-04+at+12.32.07+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheENkqa3PpPhLbOaVUmx54Wm5wVUaqllMG1BZZ1aWX35-w4hP-lCW4wCTvVcaB-P6FtOyovcDt0gIpSAF5N5JmiU2Eoelnxu5S_AX9H9S-bIaB8nkLeVl_F3ahT3kjNdJerEPoWhns1Zn-/s640/Screen+Shot+2015-05-04+at+12.32.07+PM.png&quot; width=&quot;510&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj66e2zThbEjzyrBFROfaf8Akm7Xlh74k3S1m1J2SKbQeoYZ3MCREAd3JMTWo49b7JAenBnQb6lwXIe1iZRvd3Ki5J5kjOvIqbdT5v2tlnJG8lZdCuN33uq_jzCQ8qPAksIxxpZqFg4A5oD/s1600/Screen+Shot+2015-05-04+at+12.32.34+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;464&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj66e2zThbEjzyrBFROfaf8Akm7Xlh74k3S1m1J2SKbQeoYZ3MCREAd3JMTWo49b7JAenBnQb6lwXIe1iZRvd3Ki5J5kjOvIqbdT5v2tlnJG8lZdCuN33uq_jzCQ8qPAksIxxpZqFg4A5oD/s640/Screen+Shot+2015-05-04+at+12.32.34+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Following video shows how to create transition and how to add condition to those transition. &lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/3o9KLU-6Ks8&quot; width=&quot;420&quot;&gt;&lt;/iframe&gt;

&lt;br /&gt;
&lt;b&gt;-&amp;gt;&lt;/b&gt; Now we have state machine with transition and condition, but we want Blink Animation to terminate once its finished. Let&#39;s open &quot;Blink Animation&quot; and add Animation event line shown in below image. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOWdH5ssLfpM9LWxn53cyzLDJgVSWqqQ-9twUhwEXnNBlavaCdDc1EAf301XaPTYLvqFv9IWvM_HU7bf4mBZdSQGOZ04qGo1ajP4kgT_A34DTfzvsciDbXAVKnFWwJpJ6ohY-iwTsn_qk0/s1600/Screen+Shot+2015-05-04+at+12.44.37+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOWdH5ssLfpM9LWxn53cyzLDJgVSWqqQ-9twUhwEXnNBlavaCdDc1EAf301XaPTYLvqFv9IWvM_HU7bf4mBZdSQGOZ04qGo1ajP4kgT_A34DTfzvsciDbXAVKnFWwJpJ6ohY-iwTsn_qk0/s640/Screen+Shot+2015-05-04+at+12.44.37+PM.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
This will prompt you to select function to be invoked when Animation frame is reached. You can select function from attached Script. &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPY7q6ImuYL_sUXDmxnMxB3-hZpGzm53vcnNtExzhYm9_4qfMipuqZSclxLec7pzmSZ8wXmSU6eeJDGqQWQ-x4DvYKC24MrGGP41fwJJkRdfDiUcrM3UPgPEk62tiT7PQKzXEgx5i-rAAc/s1600/Screen+Shot+2015-05-04+at+12.44.44+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPY7q6ImuYL_sUXDmxnMxB3-hZpGzm53vcnNtExzhYm9_4qfMipuqZSclxLec7pzmSZ8wXmSU6eeJDGqQWQ-x4DvYKC24MrGGP41fwJJkRdfDiUcrM3UPgPEk62tiT7PQKzXEgx5i-rAAc/s640/Screen+Shot+2015-05-04+at+12.44.44+PM.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Following video shows the same process. &lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/9FobPk4nrYw&quot; width=&quot;420&quot;&gt;&lt;/iframe&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;-&amp;gt;&lt;/b&gt; Finally, We also need to add a script to Cube object. Following is code for the script. In script we are setting &quot;blink&quot; transition parameter of Animator to true on mouse click. While StopAnimation sets &quot;blink&quot; parameter to false when animation event is called.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;using UnityEngine;
using System.Collections;

public class MyAnimation : MonoBehaviour {

 private Animator animator;

 void Awake() {
  animator = GetComponent&lt;animator&gt; ();
 }

 void OnMouseUp() {
  startAnimation ();
 }

 public void startAnimation() {
  animator.SetBool (&quot;Blink&quot;, true);
 }

 public void stopAnimation() {
  animator.SetBool (&quot;Blink&quot;, false);
 }
}
&lt;/animator&gt;&lt;/pre&gt;
&lt;br /&gt;
And now if run project and click cube, you should see blink animation as per demo video. That&#39;s it hope this post will be helpful.
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/8792620908045351724/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/05/color-animation-using-animator-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/8792620908045351724'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/8792620908045351724'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/05/color-animation-using-animator-with.html' title='Color Animation using Animator with Unity3D'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://img.youtube.com/vi/DANGeHrYDVg/default.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-8934186517085239942</id><published>2015-04-12T04:25:00.000-07:00</published><updated>2015-04-12T04:25:30.448-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Drag"/><category scheme="http://www.blogger.com/atom/ns#" term="Drag and Drop"/><category scheme="http://www.blogger.com/atom/ns#" term="Drop"/><category scheme="http://www.blogger.com/atom/ns#" term="Multi touch"/><category scheme="http://www.blogger.com/atom/ns#" term="Touch"/><category scheme="http://www.blogger.com/atom/ns#" term="Unity3D"/><title type='text'>Handling Drag and Drop with Unity 3D</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Drag and Drop is quite useful and we need to implement this quite often in our project. While working on one of my Unity Project, I required to implement the same.

&lt;br/&gt;&lt;br/&gt;
There are some options but I found code described in this post quite simple to use with my project. In this post I will describe how I achieved the same.


&lt;br/&gt;&lt;br/&gt;
So, Let&#39;s first create a C# script, I named it Drag.cs and added following code to it. This script will enable touch interaction to added GameObject and will move object along with touch. Also add BoxCollider to GameObject, so we can detect collision.
&lt;pre class=&quot;prettyprint&quot;&gt;

using UnityEngine;
using System.Collections;
 
public class Drag : MonoBehaviour {
    private Plane plane;
    private Vector3 v3Offset;


    void OnMouseDown() {
 plane.SetNormalAndPosition
             (Camera.main.transform.forward, transform.position);
 Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 float dist;
 plane.Raycast (ray, out dist);
 v3Offset = transform.position - ray.GetPoint (dist);         
    }

    void OnMouseUp() {
    }

    void OnMouseDrag() {
 Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 float dist;
 plane.Raycast (ray, out dist);
 Vector3 v3Pos = ray.GetPoint (dist);
 transform.position = v3Pos + v3Offset;  
    }
}
&lt;/pre&gt;

Now, suppose we have another GameObject and we want to detect when GameObject we just created with above script, is dropped on it. To detect drop easily let&#39;s first add RigidBody to this GameObject and BoxCollider. After adding BoxCollider also check isTrigger is true. After doing this we need to add C# script to it which will handle drop. Let&#39;s name it to Drop.cs and add below code to it.
&lt;br/&gt;&lt;br/&gt;
Below script observe the Collision. When collision happens it checks which object is collided with it. 
If collided object is Drag object then do something.
&lt;pre class=&quot;prettyprint&quot;&gt;
using UnityEngine;
using System.Collections;

public class Drop : MonoBehaviour {


    void OnCollisionEnter2D (Collision2D other) {
    }
 
    void OnCollisionExit2D(Collision2D other){
    }
 
    void OnTriggerStay2D (Collider2D other) {
        if( other.gameObject.tag == &quot;Drag&quot; ) {
            // Object dropped, handle the drop
        } 
    }
} 
&lt;/pre&gt;

That&#39;s pretty much it, hope this helps.
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/8934186517085239942/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/04/handling-drag-and-drop-with-unity-3d.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/8934186517085239942'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/8934186517085239942'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/04/handling-drag-and-drop-with-unity-3d.html' title='Handling Drag and Drop with Unity 3D'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-7519381504826081372</id><published>2015-04-04T23:10:00.000-07:00</published><updated>2015-04-04T23:10:09.989-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="sprite"/><category scheme="http://www.blogger.com/atom/ns#" term="sprite animation"/><category scheme="http://www.blogger.com/atom/ns#" term="Unity 4.3 2D"/><category scheme="http://www.blogger.com/atom/ns#" term="Unity3D"/><title type='text'>Sprite with Text in Unity3D</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I am working on one game where I wanted to show text over sprite. With new Unity UI System, it&#39;s quite easy to create button as sprite and text over it.
&lt;br/&gt;&lt;br/&gt;
But if you want to create a traditional sprite and add text to it, this post describes the same. 

&lt;br/&gt;&lt;br/&gt;
Basic idea is to add 3D text component to sprite, but if you have tried it then you might know after adding 3D text component we need to move it to same sorting order as sprite. Also we need to layout text properly to set alignment.

&lt;br/&gt;&lt;br/&gt;
Before we begin, I assume you know how to create Sprite, how to create 3D text component and make it a Prefab object. If not you can refer &lt;a href=&quot;http://kunalmaemo.blogspot.kr/2013/10/dynamic-object-creation-in-unity3d.html&quot;&gt;this article&lt;/a&gt; to know how to make Prefab object.

&lt;br/&gt;&lt;br/&gt;
Finally, following is my script which I attached to Sprite. Once added to Sprite, It will create 3D text component from provided Prefab object and add the same to Sprite.

&lt;pre class=&quot;prettyprint&quot;&gt;
using UnityEngine;
using System.Collections;
 
public class TextScript : MonoBehaviour {
 
 public string text;
 public GameObject textPrefab;
    
 void Start() {
  GameObject text = Instantiate(textPrefab) as GameObject;
  text.transform.parent = gameObject.transform;
  text.transform.rotation = gameObject.transform.rotation;

  TextMesh textInstance = text.GetComponent&lt;TextMesh&gt;();
  textInstance.text = text;

  Renderer textRenderer = text.GetComponent&lt;Renderer&gt; ();
  Renderer thisRenderer = GetComponent&lt;Renderer&gt; ();

  textRenderer.sortingLayerID = thisRenderer.sortingLayerID;
  textRenderer.sortingOrder = thisRenderer.sortingOrder+1;
 
  Bounds textBounds = textRenderer.bounds;
  Bounds parentBounds = thisRenderer.bounds;
  
  float x = gameObject.transform.position.x 
                     - (textBounds.size.x/2); 
  float y = gameObject.transform.position.y 
                     + (textBounds.size.y/2);
  textInstance.transform.position = 
                     new Vector3(x, y, parentBounds.center.z + 1);
 }
}
&lt;/pre&gt;

That&#39;s it, you can add this script to any component and add text over it.
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/7519381504826081372/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/04/sprite-with-text-in-unity3d.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/7519381504826081372'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/7519381504826081372'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/04/sprite-with-text-in-unity3d.html' title='Sprite with Text in Unity3D'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-734762122931330896</id><published>2015-01-24T19:35:00.000-08:00</published><updated>2015-01-24T19:39:12.867-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Event"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS6"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone application"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone sdk"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone5"/><category scheme="http://www.blogger.com/atom/ns#" term="KVO"/><category scheme="http://www.blogger.com/atom/ns#" term="Observer"/><category scheme="http://www.blogger.com/atom/ns#" term="Property Change"/><title type='text'>Notification on property change in iOS SDK</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I have used QML quite a lot in my projects and there is one quite nice feature in QML that makes implementation quite easy. The feature is Property change notification.
&lt;br/&gt;&lt;br/&gt;

Apple iOS SDK also similar mechanism named Key-Value Observing mechanism. &lt;a href=&quot;https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html&quot;&gt;Here&lt;/a&gt; is Apple&#39;s documentation for the same.

&lt;br/&gt;&lt;br/&gt;

Following is simple code which demonstrate how we can use Key-Value Observer API to get notification on property changes.

First we need to register observer and in which property observer is interested in. Code shows, class &quot;self&quot; is interested in property change event from propertyOwner for &quot;isPlaying&quot; property.

&lt;pre class=&quot;prettyprint&quot;&gt;
[propertyOwner addObserver:self
    forKeyPath:@&quot;isPlaying&quot;
       options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
       context:NULL];
&lt;/pre&gt;

Now, we have registered observer for property change, we need to implement method which will be called in case of property is changed. Following code shows the same. We need to check which object sent event and for which property, then we can take appropriate action.
&lt;pre class=&quot;prettyprint&quot;&gt;
- (void) observeValueForKeyPath:(NSString *)path ofObject:(id) object change:(NSDictionary *) change context:(void *)context
{
    // this method is used for all observations, so you need to make sure
    // you are responding to the right one.
    if (object == propertyOwner &amp;&amp; [path isEqualToString:@&quot;isPlaying&quot;]) {
        // now we know which property is modified
    }
}
&lt;/pre&gt;

When we are done and don&#39;t need notification any more we can remove observer. Below is code for the same. It&#39;s safe to use try and catch as we might get exception if we try to remove observer when none is registered.
&lt;pre class=&quot;prettyprint&quot;&gt;
    @try{
        [propertyOwner removeObserver:self forKeyPath:@&quot;isPlaying&quot;];
    }@catch(id anException){
        //do nothing, obviously it wasn&#39;t attached because an exception was thrown
    }
&lt;/pre&gt;

Now whenever &quot;propertyOwner&quot; changes&#39;s &quot;isPlaying&quot; property then &quot;self&quot; will get notification and &quot;observeValueForKeyPath&quot; method will get called.
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/734762122931330896/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2015/01/notification-on-property-change-in-ios.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/734762122931330896'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/734762122931330896'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2015/01/notification-on-property-change-in-ios.html' title='Notification on property change in iOS SDK'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-6889268827332426381</id><published>2014-12-27T18:16:00.000-08:00</published><updated>2014-12-27T18:16:30.969-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="BB10"/><category scheme="http://www.blogger.com/atom/ns#" term="BlackBerry"/><category scheme="http://www.blogger.com/atom/ns#" term="Cascades"/><category scheme="http://www.blogger.com/atom/ns#" term="image"/><category scheme="http://www.blogger.com/atom/ns#" term="QML"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt Quick"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt Quick Components"/><category scheme="http://www.blogger.com/atom/ns#" term="Z10"/><title type='text'>Showing Remote Image using ImageView in BB10 Cascades</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
While working on my BB10 App update, I required to show Remote Image using ImageView BB10 cascades API. ImageView or Image component by default does not support loading image from URL on internet. I implemented a custom component which serve the purpose and also easily integrated with ImageView.&lt;br/&gt; &lt;br/&gt;

Following is implementation for the same, I hope it will be useful to someone.&lt;br/&gt;&lt;br/&gt;

Let&#39;s start by showing how my custom component works. Following code shows how to use ImageDownloader custom component along with ImageView to display Grid of images from internet. Data Model contains two kind of URL, url for low resolution image and url for high resolution image.
&lt;pre class=&quot;prettyprint&quot;&gt;
import my.library 1.0

ListView {
  id: listView
  
  layout: GridListLayout {}
  dataModel: model;
  
  listItemComponents: [
      ListItemComponent {                        
          ImageView {
              id: imgView
              imageSource: &quot;default_image.jpg&quot;  
                                        
              attachedObjects: [
                  ImageDownloader {
                      id: imageLoader
                      url: ListItemData.mediumImage
                      onImageChanged: {                 
                          if (imageLoader.isVaid) {
                              imgView.image = imageLoader.image
                          }
                      }
                  }
              ]
          }
      }
  ]
}
&lt;/pre&gt;

ImageDownloader component is available in QML because we imported &quot;my.library&quot;. We can make any C++ code available to QML by registering it to QML System, folloiwing snippet shows how we can register C++ component to QML system.
&lt;pre class=&quot;prettyprint&quot;&gt;

#include &quot;ImageDownloader.h&quot;

int main(int argc, char **argv) 
{
 Application app(argc, argv);

 qmlRegisterType&amp;lt;ImageDownloader&amp;gt;(&quot;my.library&quot;,1, 0, &quot;ImageDownloader&quot;);

 QmlDocument *qml = QmlDocument::create(&quot;asset:///main.qml&quot;).parent(&amp;app);

 AbstractPane *root = qml-&gt;createRootObject&lt;AbstractPane&gt;();
 app.setScene(root);

 return Application::exec();
}
&lt;/pre&gt;
Now that custom component is ready to be used with QML, let&#39;s see how its implemented. Below if header file for ImageDownloader class.
We are defining few properties like url, image and isValid. By setting &quot;url&quot; we can initiate download of image, when &quot;image&quot; download is finished downloaded image can be accessed by using &quot;image&quot; property. We can check if image is valid or not by checking &quot;isValid&quot; property. we are also defining few signal like &quot;urlChanged&quot; and &quot;imageChanged&quot;, which are emited when url is changed or image is downloaded. And we are using QNetworkAccessManager to download image from internet.

&lt;pre class=&quot;prettyprint&quot;&gt;
#ifndef IMAGEDOWNLOADER_H_
#define IMAGEDOWNLOADER_H_

#include &lt;QObject&gt;
#include &lt;bb/cascades/Image&gt;

class QNetworkAccessManager;

class ImageDownloader: public QObject
{
    Q_OBJECT
    Q_PROPERTY(QVariant image READ image NOTIFY imageChanged)
    Q_PROPERTY(QString url READ url WRITE setUrl NOTIFY urlChanged)
    Q_PROPERTY(bool isVaid READ isValid CONSTANT);
public:
    ImageDownloader( QObject* parent = 0);
    virtual ~ImageDownloader();

signals:
    void urlChanged();
    void imageChanged();

private slots:
    QString url() const;
    void setUrl( const QString&amp; url);

    QVariant image() const;
    bool isValid() const;

    void startDownload();
    void onReplyFinished();

private:
    QNetworkAccessManager mNetManager;
    QString mImageUrl;
    bb::cascades::Image mImage;
    bool mIsValid;
};

#endif /* IMAGEDOWNLOADER_H_ */
&lt;/pre&gt;

Implementation is also quite simple, let&#39;s see how its implemented. On URL change, we are initiating the image download using QNetworkAccessManager. When download is finished, we are reading image data in to buffer and creating Image using BB10 Image API. 
&lt;pre class=&quot;prettyprint&quot;&gt;
#include &quot;ImageDownloader.h&quot;

#include &amp;lt;QNetworkAccessManager&amp;gt;
#include &amp;lt;QNetworkRequest&amp;gt;
#include &amp;lt;QNetworkReply&amp;gt;

ImageDownloader::ImageDownloader(QObject* parent):
    QObject(parent), mIsValid(false) {}

ImageDownloader::~ImageDownloader() {}

QString ImageDownloader::url() const {
    return mImageUrl;
}

void ImageDownloader::setUrl( const QString&amp; url)
{
    if(url != mImageUrl) {
        mImageUrl = url;
        mIsValid = false;
        mImage = bb::cascades::Image();
        emit urlChanged();
        emit imageChanged();
        startDownload();
    }
}

QVariant ImageDownloader::image() const {
    return QVariant::fromValue(mImage);
}

bool ImageDownloader::isValid() const {
    return mIsValid;
}

void ImageDownloader::startDownload() {
    QNetworkRequest request(mImageUrl);
    QNetworkReply* reply = mNetManager.get(request);
    connect(reply, SIGNAL(finished()), this, SLOT(onReplyFinished()));
}

void ImageDownloader::onReplyFinished() {
    QNetworkReply* reply = qobject_cast&lt;QNetworkReply*&gt;(sender());
    QString response;
    if (reply) {
        if (reply-&gt;error() == QNetworkReply::NoError) {
            const int available = reply-&gt;bytesAvailable();
            if (available &gt; 0) {
                const QByteArray data(reply-&gt;readAll());
                mImage = bb::cascades::Image(data);
                mIsValid = true;
                emit imageChanged();
            }
        }
        reply-&gt;deleteLater();
    }
}
&lt;/pre&gt;
That&#39;s all we have to do to do display remote image in BB10, hope you liked it.
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/6889268827332426381/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2014/12/showing-remote-image-using-imageview-in.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/6889268827332426381'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/6889268827332426381'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2014/12/showing-remote-image-using-imageview-in.html' title='Showing Remote Image using ImageView in BB10 Cascades'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-8364268181500775947</id><published>2014-12-20T20:17:00.000-08:00</published><updated>2014-12-20T20:17:40.115-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="game"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS6"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone game"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone sdk"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone5"/><category scheme="http://www.blogger.com/atom/ns#" term="Unity3D"/><title type='text'>Resolving &quot;_clock$UNIX2003&quot;, referenced from&quot; error</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I was trying to build Unity 3D project for simulator SDK. I wanted to get different  screen size screen shot.
But when I tried to build it I got following build error.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;_clock$UNIX2003&quot;, referenced from
&lt;/pre&gt;
I found one work around to resolve this issue. We need to add following patch to main.mm file.

&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;#include &amp;lt;time.h&amp;gt;

// &quot;_clock$UNIX2003&quot;, referenced from:
//Temporary hack for building Simulator Project for Unity
extern &quot;C&quot;
{
    clock_t
    clock$UNIX2003(void)
    {
        return clock();
    }
}
&lt;/pre&gt;

Once I added above patch build started working fine for me and I was able to run project on Simulator.
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/8364268181500775947/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2014/12/resolving-clockunix2003-referenced-from.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/8364268181500775947'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/8364268181500775947'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2014/12/resolving-clockunix2003-referenced-from.html' title='Resolving &quot;_clock$UNIX2003&quot;, referenced from&quot; error'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-3937932935518377213</id><published>2014-11-23T03:38:00.003-08:00</published><updated>2014-11-23T03:38:51.289-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="QML"/><category scheme="http://www.blogger.com/atom/ns#" term="qt"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt Quick"/><category scheme="http://www.blogger.com/atom/ns#" term="Scope"/><category scheme="http://www.blogger.com/atom/ns#" term="Ubuntu Touch"/><title type='text'>Your Shot Ubuntu Touch Scope</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
You might have heard about Ubuntu Touch, and one of unique feature of Ubuntu Touch is Scope. Recently they also announced Ubuntu Touch Scope competition.
This got me interested, I wanted to learn about Scope development, so I thought to take part as well in the competition.&lt;br /&gt;
&lt;br /&gt;
You can get more information about competition &lt;a href=&quot;http://developer.ubuntu.com/2014/10/scope-development-competition/&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Recently I discovered &lt;a href=&quot;http://yourshot.nationalgeographic.com/&quot;&gt;Your Shot photo community&lt;/a&gt;, I like pictures uploaded there and I visit site every day to checkout newly updated photos, so I thought it is good candidate for Scope development and I decided to write score for Your Shot photo community.&lt;br /&gt;
&lt;br /&gt;
Your Shot has nice Jason based web API and I was able to create scope quite easily using Ubuntu Touch socpe&#39;s Jason template. In fact I was able to get decent working scope in few hours using template. Documentation is also quite good and rich with &lt;a href=&quot;http://developer.ubuntu.com/scopes/tutorials/write-a-json-scope-in-cpp/&quot;&gt;API Reference, Guide and Tutorials.&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is demo for the same running on my desktop.&lt;br /&gt;
&lt;br /&gt;
&lt;center&gt;&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;//www.youtube.com/embed/KwmMtaOW8H8&quot; width=&quot;420&quot;&gt;&lt;/iframe&gt;&lt;/center&gt;

&lt;br /&gt;
And Few snapshot.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFAUxvHwYRNoo5OaM4uj6iYIgPWILBpdtrtOEY5w9BZA_prZTswy7dzN2rO5HxApOQ0IduIDX8joO4Mc6znFMwsQn2-ETQDWsB5UvACfc8SERjR5HvMnOuAdoKn4DWXEIzeG6GyO0nZAOG/s1600/main.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFAUxvHwYRNoo5OaM4uj6iYIgPWILBpdtrtOEY5w9BZA_prZTswy7dzN2rO5HxApOQ0IduIDX8joO4Mc6znFMwsQn2-ETQDWsB5UvACfc8SERjR5HvMnOuAdoKn4DWXEIzeG6GyO0nZAOG/s1600/main.png&quot; height=&quot;400&quot; width=&quot;365&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaKn7a6Lhri3V70RK0rv2dVcW9gNXxAdzL68u5S-w6TpR3vcZQAqp0rFn5IIDUkiO9UONLTxjfB2OZKaFSqC0JDWRk1I0epku5dfYp1CpppuJjdADBvTPT1wnhBJf-fPzuXY8ygVscVv8W/s1600/preview.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaKn7a6Lhri3V70RK0rv2dVcW9gNXxAdzL68u5S-w6TpR3vcZQAqp0rFn5IIDUkiO9UONLTxjfB2OZKaFSqC0JDWRk1I0epku5dfYp1CpppuJjdADBvTPT1wnhBJf-fPzuXY8ygVscVv8W/s1600/preview.png&quot; height=&quot;400&quot; width=&quot;365&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2HYHN49_fwex3Q12rVrs8JZ1c-msIuG8Yv732AVC9Pd4497O9zlqcpRInNwAhrZ4VGs04ZXpD1cHQdMHf6GgmR-EqIXLHQqkKseaFdPAzl1ueq1ACmoeBgajsPI4QOqLbV7fqWqaOPnSt/s1600/search.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2HYHN49_fwex3Q12rVrs8JZ1c-msIuG8Yv732AVC9Pd4497O9zlqcpRInNwAhrZ4VGs04ZXpD1cHQdMHf6GgmR-EqIXLHQqkKseaFdPAzl1ueq1ACmoeBgajsPI4QOqLbV7fqWqaOPnSt/s1600/search.png&quot; height=&quot;400&quot; width=&quot;365&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
It looks like now I am ready to write more complex Scope but may be later.
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/3937932935518377213/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2014/11/your-shot-ubuntu-touch-scope.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/3937932935518377213'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/3937932935518377213'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2014/11/your-shot-ubuntu-touch-scope.html' title='Your Shot Ubuntu Touch Scope'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFAUxvHwYRNoo5OaM4uj6iYIgPWILBpdtrtOEY5w9BZA_prZTswy7dzN2rO5HxApOQ0IduIDX8joO4Mc6znFMwsQn2-ETQDWsB5UvACfc8SERjR5HvMnOuAdoKn4DWXEIzeG6GyO0nZAOG/s72-c/main.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-4390539570556217471</id><published>2014-10-30T07:44:00.000-07:00</published><updated>2014-10-30T07:44:43.960-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="QML"/><category scheme="http://www.blogger.com/atom/ns#" term="qt"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt Quick"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt Quick Components"/><title type='text'>Creating dynamic QML object asynchronously</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
We can create QML object dynamically by using createComponent and createObject API.&lt;br/&gt;&lt;br/&gt;

Like follow,
&lt;pre class=&quot;prettyprint&quot;&gt;
var component = Qt.createComponent(&quot;Button.qml&quot;);
if (component.status == Component.Ready)
    component.createObject(parent, {&quot;x&quot;: 100, &quot;y&quot;: 100});
&lt;/pre&gt;
You can find more information regarding same &lt;a href=&quot;http://kunalmaemo.blogspot.kr/2011/04/creating-qml-element-dynamically-on.html&quot;&gt;here&lt;/a&gt;. &lt;br/&gt;&lt;br/&gt;

Latest Qt release added new API named incubateObject. This allows object to be created in asynchronously.
You can find more information about this API &lt;a href=&quot;http://qt-project.org/doc/qt-5/qml-qtqml-component.html#incubateObject-method&quot;&gt;here&lt;/a&gt;.
&lt;br/&gt;&lt;br/&gt;

Following code I written for Ubuntu touch calendar application, which uses the same. Here thing to remember is that incubateObject returns the incubator and not created object itself. You need to get object from incubator by incubator.object call.
&lt;pre class=&quot;prettyprint&quot;&gt;
var incubator = delegate.incubateObject(bubbleOverLay);
if (incubator.status !== Component.Ready) {
    incubator.onStatusChanged = function(status) {
        if (status === Component.Ready) {
            incubator.object.objectName = children.length;
            assignBubbleProperties( incubator.object, event);
        }
    }
} else {
    incubator.object.objectName = children.length;
    assignBubbleProperties(incubator.object, event);
}
&lt;/pre&gt;

&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/4390539570556217471/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2014/10/creating-dynamic-qml-object.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/4390539570556217471'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/4390539570556217471'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2014/10/creating-dynamic-qml-object.html' title='Creating dynamic QML object asynchronously'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-7947450864377461092</id><published>2014-09-13T20:13:00.001-07:00</published><updated>2014-09-13T20:13:44.804-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Array"/><category scheme="http://www.blogger.com/atom/ns#" term="Collection"/><category scheme="http://www.blogger.com/atom/ns#" term="IBOutlet"/><category scheme="http://www.blogger.com/atom/ns#" term="Interface Builder"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone application"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone game"/><category scheme="http://www.blogger.com/atom/ns#" term="iphone sdk"/><category scheme="http://www.blogger.com/atom/ns#" term="iPhone5"/><category scheme="http://www.blogger.com/atom/ns#" term="UIButton"/><title type='text'>Creating array of IBOutlet</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span id=&quot;goog_1351415343&quot;&gt;&lt;/span&gt;&lt;span id=&quot;goog_1351415344&quot;&gt;&lt;/span&gt;Sometimes you want to enable/disable bunch of buttons together or perform other such activities on bunch of UI elements created using Interface Builder. &lt;br /&gt;
&lt;br /&gt;
I recently needed to perform similar operation on bunch of button for iOS game I am working on. For this kind of operation, its easier to create array of IBOutlet which can be created using IBOutletCollection.

Following is my code, which create IBOutletCollection of UIButtons and then enable/disbale them together.

&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;@interface MyViewController : UIViewController {
    IBOutletCollection(UIButton) NSArray *buttons;
}
&lt;/pre&gt;
in MyViewController.m, we can use buttons as below.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;-(void) enableUI:(BOOL) enable {    
    for( UIButton* button in buttons){
        button.enabled = enable;
    }    
}
&lt;/pre&gt;
Only thing missing now is, connecting UIButtons created using Interface Builder to IBoutletCollection. We need to do this from Interface Builder, process is similar to connecting UI Elements from Interface Builder to IBOutlet.&lt;br /&gt;
&lt;br /&gt;
Following snaps describes the required process. I created three buttons on view.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHZ8XANCn0Almm23Qm5ngo0TwpjWZX9zDHK37ZtoxPfy9QtLmcsxdNAdozX8tHRimaNfbjxj2wyNa26IkaKjXytfGwL8eMlRtZ7-ybYgDJXUI3z8t7T16WLpFLO1GQh8fCrg6AdAG0LZ48/s1600/IBOutlet_array_0.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHZ8XANCn0Almm23Qm5ngo0TwpjWZX9zDHK37ZtoxPfy9QtLmcsxdNAdozX8tHRimaNfbjxj2wyNa26IkaKjXytfGwL8eMlRtZ7-ybYgDJXUI3z8t7T16WLpFLO1GQh8fCrg6AdAG0LZ48/s1600/IBOutlet_array_0.png&quot; height=&quot;400&quot; width=&quot;235&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
You can connect IBoutletCollection to UIButton as shown in below snap.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGZwXROKG_ZSdisUjrcneJCMT4YF1-vaMhf9xx5c9wu700NdI3KJHycLaBhY7lcH1YNhXVn8fSoDBAsfzlnJbkov76ghyphenhypheniVI1RC-mD1oZQABSnhFVekRbNFKK9j8VP9zXLvlFQt8DxB9bG/s1600/IBOutlet_array_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGZwXROKG_ZSdisUjrcneJCMT4YF1-vaMhf9xx5c9wu700NdI3KJHycLaBhY7lcH1YNhXVn8fSoDBAsfzlnJbkov76ghyphenhypheniVI1RC-mD1oZQABSnhFVekRbNFKK9j8VP9zXLvlFQt8DxB9bG/s1600/IBOutlet_array_1.png&quot; height=&quot;344&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
And you can repeat above process to connect more UIButton with IBOutletCollection.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfp69erC20aplXeHknn_nyu5-2-eaanFGglxZBleskVZHaH_IIyARGT17hIglpRqpy11m4sAKNQud6y6QTcFv0vCg-EIUKAQaBiN20lKuLS_GJWhTv1RGpmW0Y_HfqTGZakN0hBHwv3Kkp/s1600/IBOutlet_array_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfp69erC20aplXeHknn_nyu5-2-eaanFGglxZBleskVZHaH_IIyARGT17hIglpRqpy11m4sAKNQud6y6QTcFv0vCg-EIUKAQaBiN20lKuLS_GJWhTv1RGpmW0Y_HfqTGZakN0hBHwv3Kkp/s1600/IBOutlet_array_2.png&quot; height=&quot;298&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
That&#39;s it.
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/7947450864377461092/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2014/09/creating-array-of-iboutlet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/7947450864377461092'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/7947450864377461092'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2014/09/creating-array-of-iboutlet.html' title='Creating array of IBOutlet'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHZ8XANCn0Almm23Qm5ngo0TwpjWZX9zDHK37ZtoxPfy9QtLmcsxdNAdozX8tHRimaNfbjxj2wyNa26IkaKjXytfGwL8eMlRtZ7-ybYgDJXUI3z8t7T16WLpFLO1GQh8fCrg6AdAG0LZ48/s72-c/IBOutlet_array_0.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-4506105075057208061</id><published>2014-09-10T01:03:00.001-07:00</published><updated>2014-09-10T01:03:57.844-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="GameKit"/><category scheme="http://www.blogger.com/atom/ns#" term="games"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><category scheme="http://www.blogger.com/atom/ns#" term="iOS6"/><title type='text'>Matching custom NSObject with isEqual and hash</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
While working on one multiplayer game for iOS using GameKit, I faced issue while comparing object.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
For single player version I was not facing this issue but while running multiplayer version I was facing this issue. After debugging a little I realised condition for comparing object&#39;s value is failing and it turned out that I was comparing object&#39;s address rather then its value. As for Multiplayer game I was creating object using data from server/host, I needed to compare object&#39;s value and not its address.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
For objectiveC, if you want to compare object&#39;s value using &quot;==&quot; operator, you need to overload isEqual and hash method as shown like below.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;-(BOOL)isEqual:(id) other {
    if (other == self)
        return YES;
    
    if (!other || ![other isKindOfClass:[self class]])
        return NO;
    
    Card* otherCard = other;
    return ( mSuit == otherCard.mSuit &amp;amp;&amp;amp; mRank == otherCard.mRank);
}

- (NSUInteger)hash {
    NSUInteger hash = 0;
    hash += [[NSNumber numberWithInt:mSuit] hash];
    hash += [[NSNumber numberWithInt:mRank] hash];
    return hash;
}
&lt;/pre&gt;
Note that you need to overload both method together, overloading only one will not work. Once I overloaded above method my multiplayer version started working as normal.
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/4506105075057208061/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2014/09/matching-custom-nsobject-with-isequal.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/4506105075057208061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/4506105075057208061'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2014/09/matching-custom-nsobject-with-isequal.html' title='Matching custom NSObject with isEqual and hash'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-2530023078491063000</id><published>2014-07-04T23:14:00.002-07:00</published><updated>2014-07-04T23:14:50.262-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="3D animation"/><category scheme="http://www.blogger.com/atom/ns#" term="animation"/><category scheme="http://www.blogger.com/atom/ns#" term="animation framework"/><category scheme="http://www.blogger.com/atom/ns#" term="fade"/><category scheme="http://www.blogger.com/atom/ns#" term="Fade effect"/><category scheme="http://www.blogger.com/atom/ns#" term="Opacity"/><category scheme="http://www.blogger.com/atom/ns#" term="sprite"/><category scheme="http://www.blogger.com/atom/ns#" term="sprite animation"/><category scheme="http://www.blogger.com/atom/ns#" term="Unity 4.3"/><category scheme="http://www.blogger.com/atom/ns#" term="Unity3D"/><title type='text'>Creating simple fade animation with Unity3D</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
I recently used fade animation or opacity animation with one of my Unity game, it was used to fade then earned points during game play. Initially I struggled a bit to achieve opacity animation due to confusion between using Animation or Animator. Look like from Unity version 4.3 we need to use Animator to animate the properties. I was trying to use Animation instead of Animator, was not able to perform opacity animation properly.
&lt;br /&gt;
In this post I will show, how I accomplished the Fading animation. below is video of final effect and whole process to achieve animation.&lt;br /&gt;
&lt;iframe allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;360&quot; src=&quot;//www.youtube.com/embed/k1X_RAPs2lo&quot; width=&quot;480&quot;&gt;&lt;/iframe&gt;&lt;/div&gt;
First create a initial setup of scene. Following is how my scene looks like.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIk6ylOENtyjKwgJ5FL9rswXI9bSgV6HxBg5BvEgkAgels4VHnBomq0Ztb9b9ROI2ZESn5W0CtXwLNNq3d5IdCteIuEXeXlP6Muo2IGIm0cwXLkCp6ytLaYB9G36GnVYjH7j_pn_ByRhAz/s1600/initial_Setup.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIk6ylOENtyjKwgJ5FL9rswXI9bSgV6HxBg5BvEgkAgels4VHnBomq0Ztb9b9ROI2ZESn5W0CtXwLNNq3d5IdCteIuEXeXlP6Muo2IGIm0cwXLkCp6ytLaYB9G36GnVYjH7j_pn_ByRhAz/s1600/initial_Setup.JPG&quot; height=&quot;304&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
I wanted to add fading effect to 3D text, which signifies the points earned during game play. Now scene looks like below.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-IImon4b-DnP6T_PmGoyASSkrczscrwVjaLfIawmWLrR66XxN7UXuNSj2GRQLYrE7OwIaHjqsublwOsprhXyjk4MdDhw09m-gY4_49t1PQFe-fmIFtD4QkkLZPQcFoBF-_jucX5UqVJLM/s1600/create_3d_text.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-IImon4b-DnP6T_PmGoyASSkrczscrwVjaLfIawmWLrR66XxN7UXuNSj2GRQLYrE7OwIaHjqsublwOsprhXyjk4MdDhw09m-gY4_49t1PQFe-fmIFtD4QkkLZPQcFoBF-_jucX5UqVJLM/s1600/create_3d_text.JPG&quot; height=&quot;298&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now we need to add animator component to text.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhruoLBT0RkRvfZUmZ0fFg613hxa-ZFn1RYsjBvAu3vC9zJpn0CQ2uZZafRb3iX4juTCZPtcuKe3aMJt2oL_qrEJYDcAcLQWKge58_l8MaZjJByOA1Y9Moq7pCpmMMmY3fCGnlXDlSoePSS/s1600/animator_adding.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhruoLBT0RkRvfZUmZ0fFg613hxa-ZFn1RYsjBvAu3vC9zJpn0CQ2uZZafRb3iX4juTCZPtcuKe3aMJt2oL_qrEJYDcAcLQWKge58_l8MaZjJByOA1Y9Moq7pCpmMMmY3fCGnlXDlSoePSS/s1600/animator_adding.png&quot; height=&quot;282&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLinBhtIS005xVtX-snAkmWw7km3KEdcTMtDdPDAhlT1XPwqDVqoGeCS7V4aoLOEmjjZopsgte89BztjDFR4pkMKUqebzSYdOz2X8WKqUwwBPa10wjQ4AaxncG-DRHI_GJMNaQmBMCO_hh/s1600/add_animator.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLinBhtIS005xVtX-snAkmWw7km3KEdcTMtDdPDAhlT1XPwqDVqoGeCS7V4aoLOEmjjZopsgte89BztjDFR4pkMKUqebzSYdOz2X8WKqUwwBPa10wjQ4AaxncG-DRHI_GJMNaQmBMCO_hh/s1600/add_animator.JPG&quot; height=&quot;324&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now, that we have added animator, we can go to Animation windows and setup our first key.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0AmasWm0sI1sAI3sYNgYqD5w2bCYwXnoYzVvncaKkrANEj0-K2yRvh7y_MZ8ywVN0UY78B65ZGehc2x6SH3m7cgN5kSnGSwXCbDGBDUxMe6mnLo1xi9VL8MQY_-XqC9VbPrRmLCo6Zw8M/s1600/add_first_key.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0AmasWm0sI1sAI3sYNgYqD5w2bCYwXnoYzVvncaKkrANEj0-K2yRvh7y_MZ8ywVN0UY78B65ZGehc2x6SH3m7cgN5kSnGSwXCbDGBDUxMe6mnLo1xi9VL8MQY_-XqC9VbPrRmLCo6Zw8M/s640/add_first_key.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
First key is from where our animation will start, we need to setup second key where animation will end. Create a second key at desired location and move text at appropriate location.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihvfFJ5k9fu8s6xj1FPWGjM_6jflf5M5AmAZ5ZTw0wfJGRVmLAr60aNgBRs80ZmxyUUSY6F4X6mZmTb6E-DVrorvq0pvG67nGbWj6A9BsiX5Q0oyJ0AL8xSVbG81QOdLJOU_aKzqLQ6KbF/s1600/add_second_key.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihvfFJ5k9fu8s6xj1FPWGjM_6jflf5M5AmAZ5ZTw0wfJGRVmLAr60aNgBRs80ZmxyUUSY6F4X6mZmTb6E-DVrorvq0pvG67nGbWj6A9BsiX5Q0oyJ0AL8xSVbG81QOdLJOU_aKzqLQ6KbF/s640/add_second_key.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
I also wanted to animate opacity with size and location. So lets add new curve for color animation.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG2KHhdZtdXPYULXbREzCvHh6TS_LNg23LGK2C6MSt6j4YT7MpuWc8y19tE2rlZ_lJ4JE_zNC4j5SRWKLrQjqOCUNZSKkQndYXPxbcbtgQGlQfE1hPRxQ7hfdW1VPm0uPh0SydIDlkoIkR/s1600/color_animation.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjG2KHhdZtdXPYULXbREzCvHh6TS_LNg23LGK2C6MSt6j4YT7MpuWc8y19tE2rlZ_lJ4JE_zNC4j5SRWKLrQjqOCUNZSKkQndYXPxbcbtgQGlQfE1hPRxQ7hfdW1VPm0uPh0SydIDlkoIkR/s640/color_animation.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Setup the opacity value for color curve for both first key and second key. Following is how my keys looks like.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKZQyHDoOEX0fHoNx74rVB1fAUtiX7fYl7ej6iHSxQuRdxuJw8sH3096sQmy21v9VCZLD6VP7skeUMQLE2bViiFRDdGUFzpQQrlwafcY7SszcaoQ8955ueiNzMS5djNw1PBXc5yCOoCXjT/s1600/first_key.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKZQyHDoOEX0fHoNx74rVB1fAUtiX7fYl7ej6iHSxQuRdxuJw8sH3096sQmy21v9VCZLD6VP7skeUMQLE2bViiFRDdGUFzpQQrlwafcY7SszcaoQ8955ueiNzMS5djNw1PBXc5yCOoCXjT/s640/first_key.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuDSpy4BVrRu4USMBFb4gDu8G91WpnB9tNiM1jY0G24wRngj59xpZD6jhSua67elFxmjFjFJe8ygKX1bCr6udw9ZzX3QRvEMS7dWn95NCLTDZQT2gj3t4pi7C_r_zh4xK7DGk1BGxPH-XV/s1600/second_key.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuDSpy4BVrRu4USMBFb4gDu8G91WpnB9tNiM1jY0G24wRngj59xpZD6jhSua67elFxmjFjFJe8ygKX1bCr6udw9ZzX3QRvEMS7dWn95NCLTDZQT2gj3t4pi7C_r_zh4xK7DGk1BGxPH-XV/s640/second_key.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now if you press play button or play animation you will be able to see fade animation. Thanks for reading my blog.
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/2530023078491063000/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2014/07/creating-simple-fade-animation-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/2530023078491063000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/2530023078491063000'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2014/07/creating-simple-fade-animation-with.html' title='Creating simple fade animation with Unity3D'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIk6ylOENtyjKwgJ5FL9rswXI9bSgV6HxBg5BvEgkAgels4VHnBomq0Ztb9b9ROI2ZESn5W0CtXwLNNq3d5IdCteIuEXeXlP6Muo2IGIm0cwXLkCp6ytLaYB9G36GnVYjH7j_pn_ByRhAz/s72-c/initial_Setup.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-3579746831456290518</id><published>2014-07-04T20:32:00.000-07:00</published><updated>2014-07-04T20:32:09.088-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Global Variable"/><category scheme="http://www.blogger.com/atom/ns#" term="Scene"/><category scheme="http://www.blogger.com/atom/ns#" term="Unity 4.3 2D"/><category scheme="http://www.blogger.com/atom/ns#" term="Unity3D"/><title type='text'>Creating global variable in Unity3D</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Sometime you want to create Global object that you can access from whole project.
Recently while working on my unity game, I also needed the same.
&lt;br /&gt;
&lt;br /&gt;
While method is quite simple to achieve the same, but its quite confusing if you are just started with Unity3D just like me.
Finally I now understand the process, and in this post I am describing how we can create global variable with Unity3D.

&lt;br /&gt;
&lt;br /&gt;
In Unity we work with Scene and when scene is unloaded all its objects are unloaded as well. 
To make global variable, we need to create a game object in first scene and attach a script to it which prevent it from unloading when scene is unloaded. Now we can access this game object from newly loaded scene and other scenes as well.
&lt;br /&gt;
&lt;br /&gt;
Let&#39;s start with simple project and create a scene, I called this scene as first scene.
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglTS4Tyl2a243sCn3jnxuBvmGctgLfPq4zwZlyHHsh1eFFV2EeUtL61Wl9kCn0FPJY4S0sYkZ0ExNN_i95s1eSWYBwwvjjzAmSs2-H5zLpX2LJMMMXcmR8XG4LmUrXh5dyRUCB2RlBDMnv/s1600/initial_setup.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglTS4Tyl2a243sCn3jnxuBvmGctgLfPq4zwZlyHHsh1eFFV2EeUtL61Wl9kCn0FPJY4S0sYkZ0ExNN_i95s1eSWYBwwvjjzAmSs2-H5zLpX2LJMMMXcmR8XG4LmUrXh5dyRUCB2RlBDMnv/s400/initial_setup.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now we need to create a empty object which we treat as a global gameobject. This object will not be destroyed when first scene is unloaded.
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJu-Otr_k229S6uW05h7AslxnLqjvrTbzzB7yyfDv30mxOAsRLWJneDZySnV7xR1ffQoXo_8PCzdHKFi-h84G2qW2D3XGwbuMMWW_mTCIO2GycjxaRP2zJabI3TTRIwUtEua_rtxY4juYz/s1600/create_global_go.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJu-Otr_k229S6uW05h7AslxnLqjvrTbzzB7yyfDv30mxOAsRLWJneDZySnV7xR1ffQoXo_8PCzdHKFi-h84G2qW2D3XGwbuMMWW_mTCIO2GycjxaRP2zJabI3TTRIwUtEua_rtxY4juYz/s400/create_global_go.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
To preserve this gameobject when First scene is unloading, we need to attach a script, I named it MakeGlobal and added following code to it.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJivkcF3U0kr-7hwirrdEN7VgXwV2oT5vkSo2r3PgYft0IIfE1PuI_KtJFjtgBikVrvRsdypKK438EQCCAVl6YiYXgtHpPZs7z_rj8jtZ_svk7R1mknYkjJR3P1LCy0GeK-YZQebHcZG7h/s1600/create_makeglobal_script.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJivkcF3U0kr-7hwirrdEN7VgXwV2oT5vkSo2r3PgYft0IIfE1PuI_KtJFjtgBikVrvRsdypKK438EQCCAVl6YiYXgtHpPZs7z_rj8jtZ_svk7R1mknYkjJR3P1LCy0GeK-YZQebHcZG7h/s400/create_makeglobal_script.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;using UnityEngine;
using System.Collections;

public class MakeGlobal : MonoBehaviour {
 void Awake () {
  DontDestroyOnLoad (transform.gameObject);
 }
}
&lt;/pre&gt;
By using DontDestroyOnLoad, we ask Unity engine not to destroy this gameobject when its scene is getting unloaded, now we can assign a new script to this global gameobject, which holds global variables.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmuUwIoafHSQBpdad7XIsNDAM7UEtvCZKRm76PxUvMbB0-PiQJIFC-5QsktjFguSNb9X_3HUTi5B4ZK-BsnFI8GJiPMv6Q37Y39S2P9KXNmut6kKUaBrdeEE4lY-krCdi-VUCvYACfkcNd/s1600/create_global_variable.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmuUwIoafHSQBpdad7XIsNDAM7UEtvCZKRm76PxUvMbB0-PiQJIFC-5QsktjFguSNb9X_3HUTi5B4ZK-BsnFI8GJiPMv6Q37Y39S2P9KXNmut6kKUaBrdeEE4lY-krCdi-VUCvYACfkcNd/s400/create_global_variable.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
This script is simple, it just holds a variable which can be accessed from any scene by any game object.
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;using UnityEngine;
using System.Collections;

public class GlobalVariables : MonoBehaviour {
 public string globalVar;
}
&lt;/pre&gt;
&lt;br /&gt;
Now we have a GameObject which we can treat as a Global Object and it has a script which holds global variables. But till now we have not used it. To use it we can assign a script to Background element and that assign some value to globalVar variable.
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJfmZKL1PprXViVdyhvSU-LviZt1lk1Z8fEWhJyLGh4h1IVnuor7BYxQn3fvXupU1V47M3_BdTe92yEunxAjvXp1DaISTQr_xH5tWw6bpmQteFsD8K2DVoN7PvM-3fmf3Qurc1wVNlTv5r/s1600/script_to_background.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJfmZKL1PprXViVdyhvSU-LviZt1lk1Z8fEWhJyLGh4h1IVnuor7BYxQn3fvXupU1V47M3_BdTe92yEunxAjvXp1DaISTQr_xH5tWw6bpmQteFsD8K2DVoN7PvM-3fmf3Qurc1wVNlTv5r/s400/script_to_background.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;using UnityEngine;
using System.Collections;

public class background : MonoBehaviour {
 // Use this for initialization
 void Start () {
  GameObject globalGO = GameObject.Find(&quot;global_gameObject&quot;);
  GlobalVariables globalVars  = globalGO.GetComponent&lt;globalvariables&gt;();
  globalVars.globalVar = &quot;String from 1st Scene&quot;;
 }
}
&lt;/globalvariables&gt;&lt;/pre&gt;
&lt;br /&gt;
Now our global variable has value which is assigned by script attached to background object. To see its value on screen I created a 3D Text Object and assigned a simple script which update text object&#39;s text to global variable.
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;using UnityEngine;
using System.Collections;

public class TextUpdate : MonoBehaviour {
 // Update is called once per frame
 void Update () {
  GameObject globalGO = GameObject.Find(&quot;global_gameObject&quot;);
  GlobalVariables globalVars  = globalGO.GetComponent&lt;globalvariables&gt;();
  gameObject.GetComponent&lt;textmesh&gt; ().text = globalVars.globalVar;
 }
}

&lt;/textmesh&gt;&lt;/globalvariables&gt;&lt;/pre&gt;
Now if you run first scene, you can see text is displaying global variables value.
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOTjPm7Pmp6tpV9nG6HwqDpRGAeCAPZgjMsMkvk4QEGVKl2xP8V46kAfSDwirAF6WGQPyix9pUrqzP6hH437PdiB5ZxaeWfgWPZcAtKd34GU6ldymmGlNXbfhKz80VABTZPrslNHlCgr2T/s1600/first_Scene_running.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOTjPm7Pmp6tpV9nG6HwqDpRGAeCAPZgjMsMkvk4QEGVKl2xP8V46kAfSDwirAF6WGQPyix9pUrqzP6hH437PdiB5ZxaeWfgWPZcAtKd34GU6ldymmGlNXbfhKz80VABTZPrslNHlCgr2T/s1600/first_Scene_running.JPG&quot; height=&quot;263&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
To test if global variable really retaining its value, we should create another scene and destroy first scene. So I created a another scene, which has 3D text object which displays global variables value, using the same TextUpdate script. You will can see it still preservs value from first scene and we can use global variable in second scene as well.
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB187k0ape19i5urEsMXOrtNZ9pNnzJuH-ZinaME-JyEo_pyXJ_kODIV1NpDfn234OqY417-jgQB36kKNwnKeHTKvNrBgJm80ZCuw1U_zlpmygJQOonZtJeYD8GYWC2FJnBBV-iXQJzUr6/s1600/second_scene_running.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB187k0ape19i5urEsMXOrtNZ9pNnzJuH-ZinaME-JyEo_pyXJ_kODIV1NpDfn234OqY417-jgQB36kKNwnKeHTKvNrBgJm80ZCuw1U_zlpmygJQOonZtJeYD8GYWC2FJnBBV-iXQJzUr6/s400/second_scene_running.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
That&#39;s all, Thanks for reading my blog.
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/3579746831456290518/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2014/07/creating-global-variable-in-unity3d.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/3579746831456290518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/3579746831456290518'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2014/07/creating-global-variable-in-unity3d.html' title='Creating global variable in Unity3D'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglTS4Tyl2a243sCn3jnxuBvmGctgLfPq4zwZlyHHsh1eFFV2EeUtL61Wl9kCn0FPJY4S0sYkZ0ExNN_i95s1eSWYBwwvjjzAmSs2-H5zLpX2LJMMMXcmR8XG4LmUrXh5dyRUCB2RlBDMnv/s72-c/initial_setup.JPG" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-267532996218864956</id><published>2014-06-28T04:34:00.002-07:00</published><updated>2014-06-28T04:34:28.225-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Audiobook"/><category scheme="http://www.blogger.com/atom/ns#" term="Audiobook Player"/><category scheme="http://www.blogger.com/atom/ns#" term="audiobookreader"/><category scheme="http://www.blogger.com/atom/ns#" term="BB10"/><category scheme="http://www.blogger.com/atom/ns#" term="BlackBerry"/><category scheme="http://www.blogger.com/atom/ns#" term="Browsing"/><category scheme="http://www.blogger.com/atom/ns#" term="Built for BlackBerry"/><category scheme="http://www.blogger.com/atom/ns#" term="Cascades"/><category scheme="http://www.blogger.com/atom/ns#" term="Folder"/><category scheme="http://www.blogger.com/atom/ns#" term="Formating"/><category scheme="http://www.blogger.com/atom/ns#" term="QDir"/><category scheme="http://www.blogger.com/atom/ns#" term="SD Card"/><title type='text'>Resolving Folder reading issue from SD Card in BB10</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
There was a tricky bug in Audiobook Reader BB10 version for quite a some time which I was trying to resolve. Issue was that, for some folder in SD card, I was not able to browse it using QDir Qt API or Posix API. Though API was showing the folder, but when I try to find out folder&#39;s content, it reports folder as empty. &lt;br /&gt;&lt;br /&gt;

This was causing serious usability issue with Audiobook Reader application, as user were not able to add book from SD card. I debugged it long and tried to use various approach to resolve the issue but could not find any satisfactory solution.&lt;br /&gt;&lt;br /&gt;

I read it somewhere it causes issue if SD card was formatted with PC software and issue is resolved if you format SD card with BB10 setting. But this also looks hassle to user.&lt;br /&gt;&lt;br /&gt;

Finally, I decided to see how directory structure looks like and what is folders permission using SSH to device. When I used linux command like ls and cd, I was able to see folder&#39;s content fine. And I decide to use those command to resolve directory browsing issue.
&lt;br /&gt;&lt;br /&gt;

Following is my code, if someone else is also facing similar issue. First I am escaping special character in filepath, else linux command will not work. Then I am creating &quot;ls&quot; command with sorting and with output which list directory content in absolute file path. Once we have proper command I am using popen API to run command and then using IO api to read command&#39;s output.
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;QStringList BookListModel::getFileList(const QString&amp;amp; dir) {

 QString filePath(dir);
 filePath.replace(&quot; &quot;,&quot;\\ &quot;);
 filePath.replace(&quot;&#39;&quot;,&quot;\\&#39;&quot;);
 filePath.replace(&quot;`&quot;,&quot;\\`&quot;);
 filePath.replace(&quot;!&quot;,&quot;\\!&quot;);
 filePath.replace(&quot;$&quot;,&quot;\\$&quot;);
 filePath.replace(&quot;&amp;amp;&quot;,&quot;\\&amp;amp;&quot;);
 filePath.replace(&quot;*&quot;,&quot;\\*&quot;);
 filePath.replace(&quot;\&quot;&quot;,&quot;\\\&quot;&quot;);
 filePath.replace(&quot;(&quot;,&quot;\\(&quot;);
 filePath.replace(&quot;)&quot;,&quot;\\)&quot;);
 filePath.replace(&quot;[&quot;,&quot;\\[&quot;);
 filePath.replace(&quot;]&quot;,&quot;\\]&quot;);

 qDebug() &amp;lt;&amp;lt; filePath;
 QString cmd = QString(&quot;ls -1 %1/*&quot;).arg(filePath);
 qDebug() &amp;lt;&amp;lt; cmd;

 QStringList files;
 char path[1035];
 FILE* fp = popen(cmd.toStdString().c_str(), &quot;r&quot;);
 if (fp == NULL) {
  qDebug() &amp;lt;&amp;lt; &quot;Failed to run command&quot;;
  return files;
 }

 while (fgets(path, sizeof(path)-1, fp) != NULL) {
  QString file = QString(path).trimmed();
  QFileInfo fileInfo(file);
  if (fileInfo.isFile() &amp;amp;&amp;amp; FileModel::isSupportedMedia(fileInfo.fileName()) ){
   files &amp;lt;&amp;lt; file;
  }
 }

 qDebug() &amp;lt;&amp;lt; files;

 pclose(fp);
}
&lt;/pre&gt;
That&#39;s all, hope it will be helpful to someone.
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/267532996218864956/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2014/06/resolving-folder-reading-issue-from-sd.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/267532996218864956'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/267532996218864956'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2014/06/resolving-folder-reading-issue-from-sd.html' title='Resolving Folder reading issue from SD Card in BB10'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-2613372341397883048</id><published>2014-06-26T07:17:00.000-07:00</published><updated>2014-06-26T07:17:24.093-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Audio"/><category scheme="http://www.blogger.com/atom/ns#" term="Audiobook"/><category scheme="http://www.blogger.com/atom/ns#" term="Audiobook Player"/><category scheme="http://www.blogger.com/atom/ns#" term="audiobookreader"/><category scheme="http://www.blogger.com/atom/ns#" term="BB10"/><category scheme="http://www.blogger.com/atom/ns#" term="BlackBerry"/><category scheme="http://www.blogger.com/atom/ns#" term="Built for BlackBerry"/><category scheme="http://www.blogger.com/atom/ns#" term="Cascades"/><category scheme="http://www.blogger.com/atom/ns#" term="qt"/><title type='text'>Audiobook Reader for BB10 now got Built for Blackberry status</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Recently I upgraded my Audiobook Reader application pro version for BB10.&lt;br /&gt;
&lt;br /&gt;
This version contains many UI related changes and now it is more aligned to Blackberry design guideline and now it is also awarded Built for Blackberry status.
&lt;br /&gt;
&lt;br /&gt;
Apart form UI related changes, this version contains two major changes.

&lt;br /&gt;
&lt;br /&gt;
Now it Book auto pauses in case it detect phone call activity.
&lt;br /&gt;
&lt;br /&gt;
And there was a very critical bug in application which prevents book to be added from SD card. Though issue was related to BB10 OS, I found one work around and now adding books from SD card works as expected.
&lt;br /&gt;
&lt;br /&gt;
Full list of features in current version is as below.
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;
Allows adding single file or whole folder with book audio data&lt;/li&gt;
&lt;li&gt;
Supports adding custom bookmark&lt;/li&gt;
&lt;li&gt;
Supports browsing mp3 chapter files and play selected mp3 chapter file&lt;/li&gt;
&lt;li&gt;
Supports chapter skip&lt;/li&gt;
&lt;li&gt;
Supports 2 min, 1 min, 30 sec skip option&lt;/li&gt;
&lt;li&gt;
Supports auto pause on call&lt;/li&gt;
&lt;li&gt;
Supports Play/Pause using HW buttons&lt;/li&gt;
&lt;li&gt;
Supports custom cover art download&lt;/li&gt;
&lt;li&gt;
Advance file browser&lt;/li&gt;
&lt;li&gt;
Supports sleep timer&lt;/li&gt;
&lt;li&gt;
Supports shuffle&lt;/li&gt;
&lt;li&gt;
and some more...&lt;/li&gt;
&lt;/ul&gt;
Following is demo for current version.&lt;br /&gt;
&lt;br /&gt;
&lt;object height=&quot;315&quot; width=&quot;420&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;//www.youtube.com/v/9cORHuNkQ1E?hl=en_US&amp;amp;version=3&amp;amp;rel=0&quot;&gt;&lt;/param&gt;
&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;
&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;
&lt;embed src=&quot;//www.youtube.com/v/9cORHuNkQ1E?hl=en_US&amp;amp;version=3&amp;amp;rel=0&quot; type=&quot;application/x-shockwave-flash&quot; width=&quot;420&quot; height=&quot;315&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot;&gt;&lt;/embed&gt;&lt;/object&gt;
&lt;br /&gt;
Hope you will like the updates.

&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/2613372341397883048/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2014/06/audiobook-reader-for-bb10-now-got-built.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/2613372341397883048'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/2613372341397883048'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2014/06/audiobook-reader-for-bb10-now-got-built.html' title='Audiobook Reader for BB10 now got Built for Blackberry status'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6223976744110856384.post-8980726692417918900</id><published>2014-06-12T18:35:00.000-07:00</published><updated>2014-06-12T18:35:13.215-07:00</updated><title type='text'>Using WorkerScript from QML</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
As you might know, I am contributing to Ubuntu Touch Calendar core application. Those application are pure QML application with no C++ backend or we aim to avoid it as much as possible. This is done to make sure application are portable across device.&lt;br /&gt;
&lt;br /&gt;
For simple use-case you can just use javascript code as backend logic and it should work fine without any problem. but if you need to some intensive calculation in application then its better to move those calculation to WorkerScript.
&lt;br /&gt;
&lt;br /&gt;
While working on one calendar feature, Calculating layout for overlapping events, I also needed to use WorkerScript.
But one major problem with WorkerScript is that, it does not have access to QML Engine. 
So you will not be able to send your Declarative object to worker script to offload intensive task to threads.&lt;br /&gt;
&lt;br /&gt;
In calendar application I am getting Events declarative object from model and I needed to process events time to decide position and size of events in view.
&lt;br /&gt;
&lt;br /&gt;
As such I can not send those Events to WorkerScript, but to overcome that limitation, I created temporary Javascript object which has required data like start time, end time and id, which I can use to decide position, size and Id can be used to map temp object to original object from model and rest of logic then can be implemented in WorkerScript.&lt;br /&gt;
&lt;br /&gt;
Code wise using WorkerScript is quite easy. Following code creates WorkerScript object and sends array of events to script. 
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;
    WorkerScript {
        id: eventLayoutHelper
        source: &quot;EventLayoutHelper.js&quot;

        onMessage: {
            //recevied process data, which we can use to layout events
            layoutEvents(messageObject.schedules);
        }
    }

    function createEvents() {

        var eventMap = {};
        var allSchs = [];

        var startDate = new Date().midnight();
        var endDate = new Date().endOfDay();
        var items = model.getItems(startDate,endDate);
        for(var i = 0; i &lt; items.length; ++i) {
            var event = items[i];
            var schedule = {&quot;startDateTime&quot;: event.startDateTime, &quot;endDateTime&quot;: event.endDateTime,&quot;id&quot;:event.itemId };
            allSchs.push(schedule);
            eventMap[event.itemId] = event;
        }

        intern.eventMap = eventMap;
        //here we are asking worker script to process all the events
        eventLayoutHelper.sendMessage(allSchs);
    }

&lt;/pre&gt;
&lt;br /&gt;
Following is script code, it will process these events and will send back location and size information back.
&lt;pre class=&quot;prettyprint&quot;&gt;
WorkerScript.onMessage = function(events) {

    //do some pre-processing like sorting and converting the data type more comfortable to algorithm
    var allSchs = processEvents(events);

    while( allSchs.length &gt; 0) {
        var sch = allSchs.shift();

        //finds all schedules overlapping with current schedule and remove from original array
        var schs = findOverlappingSchedules(sch, allSchs);

        //insert original schedule first, so array remain sorted
        schs.unshift(sch);

        //send processed events back to GUI thread so we can render it
        WorkerScript.sendMessage({ &#39;schedules&#39;: schs});
    }
}
&lt;/pre&gt;

&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://kunalmaemo.blogspot.com/feeds/8980726692417918900/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://kunalmaemo.blogspot.com/2014/06/using-workerscript-from-qml.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/8980726692417918900'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6223976744110856384/posts/default/8980726692417918900'/><link rel='alternate' type='text/html' href='http://kunalmaemo.blogspot.com/2014/06/using-workerscript-from-qml.html' title='Using WorkerScript from QML'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/18433786928656006467</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>