Configuring and compiling VTK 6.1 on Mac OS X 10.9.2 + simple example of VTK usage

Hello. In this short post I will explain how to build static libraries of VTK.
Main reason why it needs: Because official “How to” has just 2 lines without any explanations. And by default will be builded dynamic libraries. With which I had a problem like link to vtkCocoaGLView was not found, but it actually was in a library.

Let’s start. You will need CMake to build and VTK sources.

- Launch CMake from your Application folder. In main menu go to “Tool” -> “Install for Command Line Use”, in case if you did not install yet.
- Unpack VTK to some directory, working place.
- Enter to VTK directory and create directory with name build

Now you can configure and generate makefile or Xcode project file from console or User interface of CMake application.
If you would like to build with makefile in terminal go to next steps, if not jump to Build with Xcode section.
Continue reading

Simple way to implement multi-thread

I want show you simple way to create multi-thread calculations in few strings of code.

Simple collection of operations. But remember about blocks specifications and use proper storage type.

1
2
3
4
5
6
7
NSMutableArray *operations = [NSMutableArray array];
    for (...) {
        NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
           // calculation
        }];
        [operations addObject:operation];
    }

If you don’t like blocks, you can easily make a subclass of NSOperation and overwrite main function.

Now time to create queue for operations, so just create instance of NSOperationQueue.
And in maxConcurrentOperationCount property you need setup proper value. For example 2, if you want to use just 2 concurrent threads for your calculations and continue in normal state with others operations in another threads.
In this case waitUntilFinished should be NO.

But if you want to use max threads of CPU, setup NSOperationQueueDefaultMaxConcurrentOperationCount to maxConcurrentOperationCount and YES to waitUntilFinished. Like in example below:

1
2
3
4
5
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [queue setMaxConcurrentOperationCount:....];
    [queue addOperations:operations waitUntilFinished:YES];
    [queue waitUntilAllOperationsAreFinished];
    [operations removeAllObjects];

If this is set, it will choose an appropriate value based on the number of available processors and other relevant factors.

1
2
3
enum {
  NSOperationQueueDefaultMaxConcurrentOperationCount = -1
};

NSOperationQueueDefaultMaxConcurrentOperationCount: The default maximum number of operations is determined dynamically by the NSOperationQueue object based on current system conditions.

That it! It’s so simple today.

How to add Push Notifications to your iOS application

Hi guys!

Welcome to 5 Min Guide about how to integrate Push Notifications into your application.

Push notification allows App to notify you of new messages or events without need to open the application in fact, they are similar to usual text message which appears like a popup on your screen with a sound.

This is a great way for apps to interact with us in the background, whether it is a game that notifies us of some event occurring in our game world or simple mail application that is beeping when a new message appears in our inbox.

As you know, Push Notifications require server side (3rd party server), e.g. for storing device tokens and for sending push notifications:

Some people still have problems with this – they  think that they should develop this server by themself, lots of hard work, time, money, etc.

But stop! We live in the mobile era! All this hard work is already done by another people. All you need – just use ready made products.  Do not reinvent the wheel!

And, one such product is QuickBlox. QuickBlox is a cloud hosted platform to simplify your mobile app backend development. It has lots of Great Features for any platform such Push Notifications, Location, Content, Ratings features, Social integration, Chat and lots of other mobile killer features!

Today we are going to talk about how to integrate one of these great feature to your iOS mobile application – Push Notifications, provided by QuickBlox Messages module. So, let’s start!

Continue reading

Getting symbolicate stack call in logs

In last version of Xcode we can’t see full crash log.

For resolving this issue we can use next solution:
1. add function to your main class

1
2
3
4
5
void uncaughtExceptionHandler(NSException *exception) {
    NSLog(@"CRASH: %@", exception);
    NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
    // Internal error reporting
}

2. And last thing

1
2
3
4
5
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{  
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
    // Normal launch stuff
}

Or you can use commands

if you use GDB

1
(gdb) info line *0x2658

or

1
(gdb) bt

And One more Beautiful solution

1. Open the breakpoint navigation in XCode 4 (This looks like a rectangle with a point on the right side)
2. Press the ‘+’ button at the bottom left and add an ‘Exception Breakpoint’. Ensure you break ‘On Throw’ for ‘All’ exceptions.

Now you should get a full backtrace immediately prior to this exception occurring. This should allow you to at least zero in on where this exception is being thrown.

And one tip for LLDB:

Posted in Xcode
Tagged Debugger, GDB, LLDB

Mountain Lion SVN

Good or not, but SVN moved to Xcode.app
If you want access like before in previous OS X, you should make a link to /usr/bin/svn.

1
sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/svn /usr/bin/svn