NSCocoaStream

How to retrieve a path to the Downloads folder

2009/06/16 · Leave a Comment

I’ve spent quite amount of time googling a way to retrieve a path to the standard User’s Downloads folder. Surprisingly, a solution has been hard to find (at least for me :). And here is the simplest snippet I’ve come up with:

NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory,
                                                           NSUserDomainMask,
                                                           YES);
NSString *downloadsFolder = [searchPaths lastObject];

Hope it will save somebody their valuable time.

→ Leave a CommentCategories: Cocoa
Tagged: , ,

One of the value transformer implementations

2009/05/29 · Leave a Comment

Some time ago I was playing with value transformers and, finally, I found a kind of my own way to declare and register them. There is nothing special but I’m going to describe it here using some code in test purposes :)

The most important part — value transformer:

//
// PlayPauseLabelTransformer.h
//

@interface PlayPauseLabelTransformer
+ (void)setup;
@end

//
// PlayPauseLabelTransformer.m
//

@implementation PlayPauseLabelTransformer

+ (Class)transformedValueClass {
  return [NSString class];
}

- (id)transformedValue:(id)value {
  BOOL isPlaying = [value boolValue];
  return (isPlaying
          ? NSLocalizedString(@"Pause",
                              @"Label for Pause button")
          : NSLocalizedString(@"Play",
                              @"Label for Play  button"));
}

+ (void)setup {
  [self setValueTransformer:[self new]
                    forName:NSStringFromClass(self)];
}
@end

Registration:

//
// PlaybackViewController.m
//

#import "PlayPauseLabelTransformer.h"

@implementation PlaybackViewController

+ (void)initialize {
  if (self != [PlaybackViewController class]) return;

  [PlayPauseLabelTransformer setup];
}

That’s it. Value transformer is ready to be used in the IB Inspector:

Value transformer in action

→ Leave a CommentCategories: Cocoa
Tagged: , , , , ,

Hello World!

2009/05/29 · 1 Comment

Hi. I’m an UI developer who wants to become a professional mac developer :)

To be honest, I’m not sure if I need this blog. But sometimes I really want to write Something. And I really hope that this place will become my friend for a long time. Let’s go…

→ 1 CommentCategories: Uncategorized
Tagged: ,