11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Clang 4.0

Last updated at Posted at 2012-11-26

Clang 4.0以降から変態的文法が増えてる気配なのでメモ

全ては追い切れないので、象徴的なものだけ抜粋

Literal

NSString以外にもリテラルが使えるようになる

NSNumber

NSNumber *number;
number = [NSNumber numberWithChar:'X'];
number = [NSNumber numberWithInt:12345];
number = [NSNumber numberWithUnsignedLong:12345ul];
number = [NSNumber numberWithLongLong:12345ll];
number = [NSNumber numberWithFloat:123.45f];
number = [NSNumber numberWithDouble:123.45];
number = [NSNumber numberWithBool:YES];
NSNumber *number;
number = @'X';
number = @12345;
number = @12345ul;
number = @12345ll;
number = @123.45f;
number = @123.45;
number = @YES;

NSArray

array = [NSArray arrayWithObjects:a, b, c, nil];
array = @[ a, b, c ];

NSDictionary

dict = [NSDictionary dictionaryWithObjects:@[o1, o2, o3]
                                   forKeys:@[k1, k2, k3]];
dict = @{ k1 : o1, k2 : o2, k3 : o3 };

取得側も変更有り

arr[@1]      === [arr objectAtIndex:1]
dict[@1]     === [dict objectAtIndex:1]
dict[@"key"] === [dict objectForKey:@"key"]

lambda

C++11 から Block のような文法をサポート

  NSArray *array = @[
	@"string 1", @"string 21", @"string 12", @"String 11",
	@"String 02"]; //"

  const NSStringCompareOptions comparisonOptions =
		NSCaseInsensitiveSearch | NSNumericSearch |
		NSWidthInsensitiveSearch | NSForcedOrderingSearch;
  NSLocale *currentLocale = [NSLocale currentLocale];
  NSArray *sorted =
	[array sortedArrayUsingComparator:[=](id s1, id s2) ->
		NSComparisonResult {
               NSRange string1Range = NSMakeRange(0, [s1 length]);
               return [s1 compare:s2 options:comparisonOptions 
                          range:string1Range locale:currentLocale];
       }];
  NSLog(@"sorted: %@", sorted);

参考

11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?