3 ms·
Collections subscripting operator [] and boxed C strings are life-savers. Instantiating obj-c object is always a pain cause the syntax is very verbose, expecial
by program 14y ago
Collections subscripting operator [] and boxed C strings are life-savers. Instantiating obj-c object is always a pain cause the syntax is very verbose, expecially for NSString:
NSString *s = [NSString stringWithCString:"hello" encoding:NSUTF8StringEncoding];
NSString *s = @("hello");
it's 11 characters vs 67. Now what I really, really miss is the implementation of the NSString concatenation operator. stringWithFormat isn't always the answer nor appendString. Please forgive me if you find that my idea is silly:
// String concatenation
NSString *s = @+(@"hello ", @"world");
Or maybe some concise dictionary operators.
NSDictionary *d1 = @{ @"first":@"Hello", @("second"):@"World" };
NSDictionary *d2 = @{ @"third":@"Greetings" };
NSDictionary *cd = @|(d1, d2); // Dictionary merge
NSDictionary *id = @&(d1, d2); // Dictionary intersect
NSDictionary *dd = @^(d1, d2); // Dictionary difference
- Someone 14y agoI think that would be inconsistent. All existing @<whatever> fragments are evaluated at compile-time. Your @+, @|, @&, @^ feel more appropriate as proper functions (the compiler could still know of them, so it could optimize calls away) Also: dictionary merge/intersect/difference aren't easily defined. For example, what should @&( @{ @"a":@"aye", @"b":@"bee" }, @{ @"a":@"ai ai", @"Bee":@"bee" }) return?
- sjwright 14y agoI don't like it, mainly because it spreads the at-sign too far, and the result is a cornucopia of dense, unreadable at-signs. When you want to do thinks like dictionary operations, I'd prefer to have the intent clearly spelled out in the code.