01
feb

Suppose that we have a ViewController.h and .m like this:

1
2
3
4
5
// ViewController.h
#import UIKit/UIKit.h

@interface ViewController : UIViewController
@end
1
2
3
4
5
6
7
8
9
10
11
12
// ViewController.m
#import "ViewController.h"
#import "SetValue.h"

@implementation ViewController
- (void)viewDidLoad
{
  [super viewDidLoad];

  [SetValue SetTheValue:@"a string"];
}
@end

And a class called SetValue, with two methods.

1
2
3
4
5
6
7
8
9
// SetValue.h
#import Foundation/Foundation.h

@interface SetValue : NSObject { }

+ (void) SetTheValue:(id)Obj;
- (void) MySelector:(id)Obj;

@end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// SetValue.m
#import "SetValue.h"

@implementation SetValue

+ (void) SetTheValue:(id)Obj
{
  [self performSelectorOnMainThread:@selector(MySelector:)
                withObject:Obj
                waitUntilDone:NO];
}

- (void) MySelector:(id)Obj
{
  NSLog(@"Data: %@", [Obj description]);
}

@end

What is the value printed by the NSLog?

enjoy.

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

01
feb

NSString and retainCount memo:

1
2
3
4
5
6
7
8
    NSString *A = [[NSString alloc] init];
    NSLog(@"_A_RC: %i", [A retainCount]);

    NSString *B = [[NSString alloc] initWithFormat:@"AAA"];
    NSLog(@"_B_RC: %i", [B retainCount]);

    NSString *C = [[NSString alloc] initWithString:@"AAA"];
    NSLog(@"_C_RC: %i", [C retainCount]);
1
2
3
...Test[3530:15203] _A_RC: -1  (ios < 5 = 2147483647)
...Test[3530:15203] _B_RC: 1
...Test[3530:15203] _C_RC: -1  (ios < 5 = 2147483647)

Because your string is not in the heap, but is a constant. A NSString made from a constant NSString is identical to the original NSString.

UINT_MAX (2147483647) -> http://it.wikipedia.org/wiki/2147483647

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , ,

21
dic

Mobile Marketing

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

21
dic

codesnippet.biz

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

21
dic

Reading Info.plist:

1
2
  NSBundle*  mainBundle = [NSBundle mainBundle];
  NSLog(@"%@", [mainBundle objectForInfoDictionaryKey:@"UIBackgroundModes"]);

Writing Info.plist

You can’t.
App bundles are read-only because they are signed, changing their content would break the signing and the app would be considered to be tampered with and not run.

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

16
dic

Here a unix command line script to count code lines for your project (or something else!).

In this example it counts lines in an Objective-C iOS Application (.h or .m files).

1
2
3
4
$
$find . \( -name '*.h' -o -name '*.m' \) -print -exec cat {} \; | wc -l
  25812
$


Explanation:

find . \( -name ‘*.h’ -o -name ‘*.m’ \) -print

- list all files endings with .H or .M recursively from current folder (.).

-exec cat {} \;

- while it finds files, exec a cat on current file

wc -l

- count lines of current file and sum it to total.

25812 lines of code! Sounds good!

enjoy!

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , , , , ,

16
dic

Great idea!
Follow this link: http://appsumo.com/~_z6T and you can win a paid account for Github!
You need only respond to a simple question! :)

Do you know GitHub.com?

git·hub /’ɡɪtˌhʌb/
GitHub is the best way to collaborate with others. Fork, send pull requests and manage all your public and private git repositories.


Github Free Account

Click here http://appsumo.com/~_z6T and Win!

Enjoy!

FacebookTwitterDeliciousLinkedInGoogle BookmarksNetlogGoogle GmailMySpaceGoogle ReaderShare

, , , , ,

Switch to our mobile site