Pages

Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Monday, 2 February 2015

#warning pragma in XCode

#pragma's are one of the interesting part of the XCode, which helps to organise your code.
When your .m file contains thousands of line and hundreds of methods, the file becomes clumsy.

You can avoid this by structuring the code by grouping methods with pragma marks. When you give pragma directive over a method, all the methods under this pragma are grouped together in the document items. You can see that in the following screenshot.




But the fun part doesn't end here.

Have you ever hard-coded something in your code for testing something, and you forget that completely. Well, that happens a lot. What if something reminds you to fix this when you finish your work?

XCode have a pragma directive particularly for this. It is the #warning pragma. Whenever you give a warning pragma anywhere in your code, the XCode compiler gives a real warning (yellow triangle that appears near the line number). You can see the compiler warning in the line navigator, Issue navigator like the other XCode warnings.

But this doesn't stop your code from executing, you can use the #error pragma if you want to stop the code from execution.


You can also make use of some comments that start with the following keywords.
// FIXME:, // ???,  // !!!, // MARK

The comment you enter after these will appear in the document items (Option + 6).

Tuesday, 20 January 2015

Using Souce Control in the projects. (Xcode, Eclipse and Visual Studio.)

Souce Control is available with Xcode, Eclipse and Visual Studio.
Visual Studio: http://blogs.msdn.com/b/visualstudioalm/archive/2013/01/30/getting-started-with-git-in-visual-studio-and-team-foundation-service.aspx
Eclipse: http://www.vogella.com/articles/EGit/

What is Souce Control?
 Souce Control is the management of changes to documents, computer programs, large web sites, and other collections of information.
https://en.wikipedia.org/wiki/Revision_control‎

Why Use Souce Control?
When working on a software project, it can be very useful to use software control management (SCM) to keep track of changes in the code and coordinate work groups. An SCM system, also referred to as source control, saves multiple versions of each file on disk, storing metadata about each version of each file in a location known as an SCM repository.

Uses of Souce Control:
1) Keep the track of changes made to your project
2) Revert back to your old code in case of major issues.
3) When working with a team, source control is very useful.
4) Can push the new code to someone's machine
5) Can work with the major changes without affecting the current code.
6) Always keep the clean master copy of your project.
7) No need to take back-ups
8) We can get to know each and every line is added by who/when
9) Can store a secure copy of the project in the server.
http://msdn.microsoft.com/en-us/library/vstudio/ms181368.aspx

There are a lot of Source Control software available as free source as well as paid.
http://en.wikipedia.org/wiki/Comparison_of_revision_control_software

Of all these, Xcode have the built in Source Control systems : Git and Subversion (SVN).
Subversion (SVN) need a remote server whereas Git can be worked in local itself (but also can be connected with server when need).

How to create Git for a Xcode project?
1) If you are creating a new project, the Xcode will ask something like "Create  local git repository for this project" when you choose your project location. Check that check box to create git for your project
2) If you want to create Git for your existing project, then you have to do something in the terminal. Run the following commands in the terminal.
   cd drag/your/project/folder/in/the/terminal
   git init (Create local git in the folder)
   git add . (Add all the files to the Git)
  git commit - m "Initial Commit (You can enter anything here)"

The following terms are used in Xcode while using the Git

Clone:
Use this when the master project is in the remote server and you want to download a copy of the project (called working copy) into your system
Commit:
You have done working with the local project (working copy) and you want to add all the changes with the Git (local repository)
Push:
You have done committing, and now you have to push the latest commits to the server.
Pull:
Someone in your team have pushed the latest commits and you want to download the latest changes to your local working copy.
Track Branch
Clone a particular branch into your local Git from remote Git
Merge:
When you have done working with your temporary branch you can now merge all the changes to the  master branch
 or any other branches

For more details about this topic, please refer the following links.
http://www.raywenderlich.com/13771/how-to-use-git-source-control-with-xcode-in-ios-6

https://developer.apple.com/library/mac/#documentation/ToolsLanguages/Conceptual/Xcode_User_Guide/085-Save_and_Revert_Changes_to_Projects/manage_project_changes.html

Tuesday, 30 December 2014

Application's own spotlight

Have you ever searched for a menu in an application, i.e, you know the name of the menu and you know it's somewhere in the menu hierarchy, but you don't know where it is.

It's not that complicated, actually it's very easy to find a menu of an application.

You know about the spotlight of the Mac which is a great utility to search for all the files and stuffs in your machine. Fortunately, in Mac, most of the applications have their own spotlight. You can find it in the help menu of an application.

For e.g., I need to find a menu named "Create SuperClass" in the XCode, but I forgot the exact location of it in the menu bar. What I will do is, I simply open the XCode's spotlight (under the Help menu) and start to type "Create SuperClass". When I start to type, the XCode matches my search string and shows the matched menus in a list. When I hover the mouse over each item, I can see the exact location of the menu.


Friday, 19 December 2014

Google Easter Eggs

Google have some amusing Easter Eggs. Type the following words in the google search bar and see the magic. You will be amazed.

1) google Leet   "goto www.google.com enter 'google leet' and press I am feeling lucky"

2) recursion (shows "Did you mean: "recursion"->same word)



3) do a barrel roll (will rotate the results page a full 360 degrees)

4) tilt (makes the page 'lean' to the right a bit.)




5) let it snow (simulates snowfall and frost on the search results.)

6) binary (changes the number of found results to read out in binary)

7) zerg rush (returns a search page with 'O's eating the search results. Clicking each 'O' a few times kills it.)

8) conway's game of life (shows the the results along with a set of controls to play, pause, maximize/restore, and step.)

9) Search "timer" in the google. The google will initiate a timer for you.




10) Search any number in the google followed by "=english". You will find the typed number in words. For example if you search "123456=english", you will see the following output.



Thursday, 18 December 2014

iOS8 - Easter eggs

With the latest update, the iOS began the best OS ever. With the iOS8, apple introduced many feature which you may not aware.

1. With iOS8, you can continue sharing your current location to someone (let's say your friend) forever or for a particular time.

2. iOS introduced extension with helps you do actions without opening the entire app. For example, you can send a quick reply to an incoming mail without leaving the current app. You can accept/reject an iCal invitation without opening the Calender app. Almost all the apps from the apple have this feature. In future, third party apps will make use of this feature and we will get some amazing extensions.

3. Battery status is available in iOS8, although the android have this feature already. The battery status option will list the apps based on their battery usage, you can kill an app which takes so much battery usage.

4. You can hide few photos/videos from your photo library, so that your friend/family members can't see them. You can see your hidden photos from the hidden photos folder.

5. You don't have to enter your credit card info everytime in your iPhone. You can just scan your card, the iPhone will scan the details from your card.

6. If you delete a photo by mistake you can easily recover them. You can recover the photos which are deleted in the past 30 days.

7. HandsOff: Apple introduced a new feature called HandsOff with iOS8 and OS X 10. You can start a work in any apple device and finish it in your another apple device. For example, you can start to compose a mail from your iPhone and finish and send it from your iPad/Mac when they are nearby. Apple also makes these API's public, so third party apps can make use of this.

8. You can send a mail with attachments upto 5GB in iOS8. In apple devices, the attachments are loaded with the mail itself, and in other devices the links of the attachments will be added with the body of the mail.

9. Interactive actions within the app. For e.g when you swipe a mail from right to left, in previous iOS, you will see only the delete menu. Now apps can have multiple menus when you do that swipe action. For e.g., the mail app have delete, reply, Flag...

10. Widgets are introduced like android. Although, they are only limited to the notification center (the UI appears when you swipe from top in the iPhone), not in the home screen like android.

11. Custom keyboards. Third party apps can supply their own keyboard which you can use in your device. These keyboards will appear throughout the iPhone, and you can control these from the settings app like the inbuild keyboards. Apple also updated their keyboard with swipe feature, predictive text...

12. Your recent contact list will appear when you use the app switcher (when you double click the home button). Although this feature is not available for the third party apps.

13. iCloud Keychain: The passwords stored in your all the apple devices are synchronised. But Google Chrome has this feature already.


Not only these, apple has introduced so many API's with iOS8 like HealthKit, Photo Editing, Extensions... Third party apps will use these features and give us some amazing apps in the future.

Wednesday, 17 December 2014

XCode Snapshots

When you are going to start a major milestone, it is very important to keep the backup of the current final source. Using source control is one of the best solution here. But I have seen people who take manual copies of the project when they start a major work. Basically, they copy the entire project's root folder and paste it somewhere else. At a point of time, these backups occupies over GB's of space, and it is also very difficult to restore to the backup.  But the XCode has a amazing feature which will take of this.

It is none other than "SnapShots". You should have already seen this. When you do some major editing processes such refactoring the project, whole find or replace and some other processes. We can also take manual snapshots when we start some major change. You can take snapshots by selecting File->Take Snapshot





Also if you want the XCode to take automatic snapshots when the build succeeds or finishing some other processes, you can do that by enabling a checkbox in the XCode->Behaviour->Select option->Create Snapshot.



You can restore the project to these snapshots at any time in the future. This will update the current source code to its origin source during the time of the snapshot. This may be very helpful than taking manual copies. File->Restore Snapshot->Choose the snapshot to be restored->Restore.



The XCode will open an interface comparing the files before and after restoring the snapshot. You can manually select any change and discard it if you don't want it.




Git Vs Snapshot
If you are using Git or some other source control software, you may confuse both of them. Git and Snapshot are not same and they cannot be used interchangeably. Snapshot saves the changes of a file in a format only the XCode will understand but the Git is an universal technology. But in some situations you may have to use both of them. Using Git is a must one for the project, but using Snapshot will help you to do restore temporary backups.

When you start work on a milestone, you can discard all local change in Git at any time. But you can't have many commits like "Temp Commit", "temp commit2"... Because when working with a team, you can't commit a project often. So in this case you can use the snapshots. Because the snapshots are local copies which will not affect the remote source.

Also you can share the snapshots to other people. All your snapshots are located under the folder
~/Library/Application Support/Developer/Shared/SnapshotRepository.sparseimage

Monday, 15 December 2014

iPhone tips and tricks

There are many hidden features in iPhone which are not mentioned anywhere in the apple website, but works.

1. Swipe left on the Compass app and your iPhone will work as a level meter.

2. You can see the timestamps of your text messages by sliding your texts over to the left.

3. As long as the camera app is open, you can use the volume buttons to take a photos.

4. Double-tapping the spacebar will automatically end the sentence with a period and start a new one for you.

5. There is an undo function that allows you to go back if you make a mistake writing a text message, email, or editing a photo. Simply shake your phone and this option will pop up.

6. By holding down the capture button in the camera app, your phone will take a series of photos so you can get the perfect shot.

7. You can enable the emoji keyboard that appears in the whatsapp for all your apps.
Go to Settings > General > Keyboard > Add New Keyboard and select Emoji.

8. HeadPhones: Double click the volume button in of the head phone to play the next songs, and triple click to play the previous song. When the camera app is open, you can use the volume buttons to take the photographs.

9. Triple click the Home button to enable/disable the assistive touch.

10. If you press and hold the dot (.) button in the Safari when entering the web address, you will see multiple options like .org, .net. .com…

11. Double tap the shift button in the keyboard will do the “Caps Lock”. Double tap again to disable Caps Lock.

12. Press the home button and the Off button of the iPhone at the time to take screenshot of the current iPhone’s screen. But few apps can block their screens while taking screenshot to protect their sensitive information.

Wednesday, 10 December 2014

Selecting a control among multiple in Interface Builder.

When you are working on the Interface Builder, you will find it hard to select a particular control when lot of controls are near by it. Also it is hard to select a control which is beneath another control.

For e.g., if you have a text field over a UIView, then you can't select the UIView directly sometimes. You may to select that view from the Document Outline.

Instead, you can use this shortcut which is provided with the XCode. 

Hold the "Shift" button, and right click over the control. 
(Or Hold the "Shift" and the "Option" button and click over the control)



Now XCode will list all the subviews and super views present at the clicked location, like in the above image. You can easily select your desired control from this menu. This is like selecting a layer in the Photoshop.


Sunday, 7 December 2014

XCode Snippets - How to use?

If you are an iOS developer, you would be spending most of your time with the XCode. One of the most advanced feature of XCode is Code Completion, which is available now with most of the SDKs.

But the sad part is, many SDKs provide the code completion only for their inbuild functions/methods. But in the XCode, we can create our own code completion shortcuts with the help of snippets. Snippets are the small piece of code saved with the XCode, which can be used whenever needed without having to type the same piece of code again and again.

By default the XCode have many code snippets. You can see that in the bottom of the Utilities panel.

Snippets Menu


To create your custom snippet, prepare the piece of code you want, and drag it to the utilities panel. The XCode will open a popup, in which you have to enter the title, description, scope, shortcut. You have to do this only once. Once you finish this, you don't have to type the same piece of code ever. You can make the code appear in the editor either by typing the shortcut or by dragging the snippet to the editor.



The snippets are basic XML and they can be shared to other people. You can find all your snippets in the following path.
/Users/<Your_Name>/Library/Developer/Xcode/UserData/CodeSnippets
Just copy the desired snippet and paste in the same path in another machine.





Monday, 1 December 2014

How to convert an existing iPhone project into an ARC enabled project?

It's very simple as it looks like. All you have to do is select a menu from the XCode menu bar, and the XCode do all the stuffs for you.

The menu is,

Edit -> Refactor -> Convert to Objective-C ARC...



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

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">