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.

List of Anti-Aliasing techniques in 3D

I know about next Anti-Aliasing techniques:
MSAA – Multi-Sampled Anti-Aliasing
SSAA – Super-Sampled Anti-Aliasing also called FSAA
FXAA – Fast Approximate Anti-Aliasing, some good resource and this pdf
CSAA – Coverage Sample Anti-Aliasing
SMAA – Subpixel Morphological Anti-Aliasing
MLAA – Morphological Anti-Aliasing (OpenGL implementation)

If you know any other which is not in list, please write below in comment.
I will add them to list and links on page with description.

Instruction for safari:

1. Open google.com.

2. Right click somewhere and select “Inspect Element”.

3. Select “Console”
Open Console in safari

4. copy and paste:

1
javascript:document.cookie="PREF=ID=e66a207a51ceefd8:U=936bafc98b2a9121:FF=0:LD=en:NR=10:CR=2:TM=1378808351:LM=1379592992:SG=1:S=OXyq0fqClYB66VuV ; path=/; domain=google.com";window.location.reload();

If you using not google.com, then change domain on your default google address.

You need to know something …

Objective-c
Timing for different conditions in 2147483647 (max int) iterations cycle:

1
2
3
4
5
6
7
8
9
2013-05-30 15:09:26.719 self[10228:707] object is not nil 3.580853 sec
2013-05-30 15:09:38.837 self[10228:707] object check bool 12.118355 sec
2013-05-30 15:09:51.900 self[10228:707] object check BOOL 13.061721 sec
2013-05-30 15:10:03.228 self[10228:707] object has object 11.327167 sec
2013-05-30 15:10:13.916 self[10228:707] object has object which is not nil 10.687253 sec
2013-05-30 15:10:31.121 self[10228:707] object has 3 level of objects 17.203815 sec
2013-05-30 15:10:51.921 self[10228:707] object isKindOfClass 20.798705 sec
2013-05-30 15:10:56.361 self[10228:707] perform block 4.439318 sec
2013-05-30 15:11:02.305 self[10228:707] block is available and perform then 5.943721 sec

So, isKindOfClass will slow down your app much as possible! ;)

Continue reading

Free application for iPad

Essential Skeleton iconEssential Skeleton allows users to rotate the model at any angle, view bones in isolation, listen to audio pronunciations of bones, annotate & share media and quiz yourself on what you have learned. This app is being offered free to demonstrate the groundbreaking 3D technology and innovative design inherent in Essential Anatomy.

Download Essential Skeleton

How to extend existing method

With blocks it’s more easy if you need extend your method. But if you will need extend some method of another class, not yours, and you will not be able to get the sources then this solution for you. (And if you will not be able or does not have any reason for creating a subclass)

1. You need create a category of class

2. import runtime in implementation file (.m)

1
#import

3. implement your method inside category, for example :

1
2
3
4
5
6
7
8
9
- (void) extend_method {

// your code

//  here will be performed the original method
    [self extend_method];
   
// your code
}

It looks like this method has recursive calls itself, but it’s not true. Look next step

4. add method for replace (you can use +initialize or +load)

1
2
3
4
5
+ (void) initialize {
    Method original = class_getInstanceMethod(self, @selector(method));
    Method replacement = class_getInstanceMethod(self, @selector(extend_method));
    method_exchangeImplementations(original, replacement);
}

Done!

How to setup multiple url pairs in a single svn:externals

Open some file editor and write your externals like:

1
folder_name http://svn.some.link/folder_name/trunk

Save to file, for example svn.externals

and then apply the property using

1
svn propset svn:externals -F svn.externals .

Now commit:

1
 svn commit . -m "message"

And update:

1
 svn up

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
« Previous 1 2 3 4 23