Is this a valid thing to do? Or will it cause problems?


#1

Hi guys,

As part of the solution to Annotation Extras, I have this code:

//Create date string
    NSDate *currentDate = [NSDate date];
    NSString *date = [NSDateFormatter localizedStringFromDate: currentDate
                                                    dateStyle:NSDateFormatterShortStyle 
                                                    timeStyle:NSDateFormatterShortStyle];

I was wondering if this is a valid way to write it. (It runs fine, but I don’t know if this is frowned upon)

//Create date string
    NSString *date = [NSDateFormatter localizedStringFromDate: [b][NSDate date][/b]
                                                    dateStyle:NSDateFormatterShortStyle 
                                                    timeStyle:NSDateFormatterShortStyle];

I never see this done which is why I’m thinking its not a good idea to do, can someone please clarify?


#2

This is just fine and in a lot of situations, preferred. However, for clarity in the book, we typically break out messages into single lines if we think it is appropriate. I’d write it the way you write it in my own projects.


#3

Thanks so much for the answer!