Pages

Monday 24 November 2014

Serialization in iPhone

Archives and serializations are two ways in which you can create architecture-independent byte streams of hierarchical data. Byte streams can then be written to a file or transmitted to another process, perhaps over a network. When the byte stream is decoded, the hierarchy is regenerated. Archives provide a detailed record of a collection of interrelated objects and values. Serializations record only the simple hierarchy of property-list values.

In English, it means, you can write a NSArray directly to a file and read it back when you need.

By using serializations you can directly write NSArray, NSDictionaries, NSObjects or even your own custom objects to the file.

    NSArray *arr = [NSArray arrayWithObjects:@"Obj1", @"Obj2", @"Obj3", @"Obj4", nil];
    
    [NSKeyedArchiver archiveRootObject:arr toFile:[[self getApplicationsDirectory] stringByAppendingPathComponent:@"encodedFile"]];


You can simply regenerate them by using the NSKeyedUnarchiver class.
    NSData *readedData = [NSData dataWithContentsOfFile:[[self getApplicationsDirectory] stringByAppendingPathComponent:@"encodedFileData"]];
    NSArray *decodeObj = [NSKeyedUnarchiver unarchiveObjectWithData:readedData];


All of the Foundation value objects objects (NSString, NSArray, NSNumber, and so on) and most of the UIKit user interface objects adopt NSCoding and can be put into an archive.

For custom objects you have to implement the NSCoding protol.

I have created a sample application to show the working of this. You can find it here

WIKI is here:

NSArchiver Docs link is here:


Thursday 20 November 2014

Google Search Tricks

1. Identify Local Time for Any City in the World using Google
If you want to know current local time in a particular city, use the following method. To see the current local time in Los Angeles do the following. Go-ahead and try this yourself for your local city and see how it works.
Syntax: time in PLACE

time in New York

2. Identify Local Weather for Any City in the World using Google
To see the current weather in Los Angeles do the following. Go-ahead and try this yourself for your local city and see how it works.
Syntax: weather PLACE

weather New York


3. Exclude Keywords in the Search
If you want Google to exclude a word while searching the web page, use – (minus) before the search as shown below. This example searches for the pages which has the word ebooks, and without the word free.
ebooks -free

4. Search for Keywords with Similar Meaning. Include Synonym Keywords in Search
Instead of searching for only the given word, using ~ before the keyword you can instruct Google to search for webpages with the exact given word or the words which has same meaning. In the following example, giving ~tutorial also searches for keywords: guide, manual, reference etc.
ios ~tutorial

5. Match Any Single Word in the Search Using *
While searching, if you are not sure about which keyword to be placed in the phrase, you can match any single word using *.

For example, if you want to search for examples of vim substitution, and you are not sure whether to search for “vim editor find and replace examples”, or “vim editor search and replace examples”, then use * , which will match either find, search or any other word, as shown below.
vim editor * and replace examples
Note: You can also match multiple words by using multiple number of *’s respectively.

6. Use OR in Google Search
Using OR operator in between the words makes the following kind of search possible in Google. Following example will search for bash examples or bash programs.
bash examples OR programs
 
Note:
The keyword OR should be in uppercase

7. Identify Definition a Word
To view the definition of a word use the following method.
Syntax: define: <word>

define: big data

8. Search for a Range Using ..
If you are looking for a product in a specific price range use the following. It will search for the pages with text PDA, and $400 to $450 ranged text.
Syntax: text $100..$125

olympics 1900..2000

9. Searching within a Specific Website
You can search for a text in a specific website. The following example shows how to search only within our blog – www.thegeekstuff.com.

examples site:stackoverflow.com

Note: There is no space between site: and the website address.


10. Google Search for a Given Keywords (both without and with sequence)
Basic Search for a Given Keywords – Without Sequence
The very basic feature of Google which everybody is using today is searching for pages which has the given text as:
linux command line history examples

Note: Highlighted words are not in the order as we given in the search box.
Basic Search with Keywords In a Given Sequence
If you want Google to show only the pages which has the words in the given sequence, then double quote that search string as:
"linux command line history examples"

Note: Highlighted words are in the same order as we given in the search box.

11. Search Based on File Type
The following examples searches only the matching keywords inside a Power Point presentations. In the same way, you can search for the doc, pdf and other file types.
iphone filetype:pdf

12. Use Google as a calculator.
Google has a built-in calculator — try entering a calculation like 110 * (654/8 + 3). Yes, your computer also has a calculator, but if you spend most of your day inside a browser, typing your calculation into the browser’s search box is quicker than firing up your calculator app.

Also type the following in the search box and hit enter.
online money converter
online conversion
online calculator


Also, you can do all the above things in the google advanced search

Monday 17 November 2014

Asset Catalogue in Xcode

Apple introduced a new concept called "Asset Catalogue" with the XCode5. It is even better with the latest XCode. 

Asset Catalogue

Asset Catalogue is the collection of all the icons, app images, launch images of your application. When creating a new project in Xcode 5 (or later version), the asset catalogue will be automatically created for you. We can add the asset catalogue for the older projects too. The Xcode asks a confirmation to add the Asset Catalogue while converting older projects to the latest Xcode.

Advantages of Asset Catalogue:
1) All the icons, splash images are listed under a single hood. You can easily spot the missed images.
2) You don't need to follow the naming conversion when using 2 images for the normal and retina(@2x) displays.
3) However, if you have two images like button_bg.png, button_bg@2x.png and if you drag them into the asset catalogue, the XCode will automatically identify that the two images are the two version of a single image. So XCode will group them into a single asset called "button_bg". You can use this image simply by passing "image" to the [UIImage:imageNamed:@"button_bg"] method.
4) We can use patch images like Android. Previously we have to do all these in code by the resizableimagewithcapinsets method. Now we can do this in Xcode by Slicing.

Even if you have device specific images (separate images for iPad) you can select them in the file inspector of the asset.

Device Specific Images


Slicing Images:
Resizing images using slicing is a common technique for creating visual elements such as buttons - where the center of the image should be stretched or tiled to the new size, and the corners should remain the same size.
When adding a new image to the Asset Catalogue of the Xcode project, you can do your slicing by clicking the "Show Slicing" button. This will give you the options to slice horizontally/vertically/both. You can select according to the image.

You have to adjust the slicing according to your image. According to your image you can select the slicing options in the preview pane. You can edit the values manually in the file inspector also.




The main advantage of the slicing is we can use patched images instead of using a big image. This will help us to reduce the size of the application.
Also when using the asset catalogue, the Xcode converts them into a binary format which increases the speed of our app.

Have a look at the following images, which shows the magic of slicing.


Before Slicing
After Slicing


Apple Docs link is here.

Friday 14 November 2014

Mac Spotlight tips and tricks

This post is especially for the new Mac users.
One of the amazing feature that the Mac have is the Spotlight application, the system wide searching tool.
You can open the spotlight application by clicking the Search icon in the top right of the screen or by pressing Command+Space keys.
1) You can use the Spotlight application to search any files in your system. The Spotlight not only searches the file name but also searches the contents of the files also.
2) Spotlight2: You can use the spotlight as a simple calculator. Commands like sqrt, pi.. also works in spotlight.
3) Spotlight3: You can use the spotlight to know the meaning of any word
4) Spotlight4: Use quotes while searching multiple words or phrases.
5) Spotlight5: Use keywords like kind to search a particular category.
6) Spotlight6: You can use operands like OR, AND.

Promoting Apps with Smart App Banners

Safari has a new Smart App Banner feature in iOS 6 and later that provides a standardised method of promoting apps on the App Store from a website.

Note: Smart App Banners only show on iOS, not OS X.
Smart App Banners vastly improve users’ browsing experience compared to other promotional methods.
If the app is already installed on a user’s device, the banner intelligently changes its action, and tapping the banner will simply open the app. If the user doesn’t have your app on his device, tapping on the banner will take him to the app’s entry in the App Store. When he returns to your website, a progress bar appears in the banner, indicating how much longer the download will take to complete. When the app finishes downloading, the View button changes to an Open button, and tapping the banner will open the app while preserving the user’s context from your website.
Smart App Banners automatically determine whether the app is supported on the user’s device. If the device loading the banner does not support your app, or if your app is not available in the user’s location, the banner will not display.
To add a Smart App Banner to your website, include the following meta tag in the head of each page where you’d like the banner to appear:
<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
Note: You cannot display Smart App Banners inside of a frame.
For example, please open this link in your iPhone Safari.
I have added the meta like this
<meta name="apple-itunes-app" content="app-id=313192737">