Sha*_*hah 2 arrays objective-c nslog nsnumber
我想制作一个演示应用程序,我可以在代码中输入4个数字,然后按1,2,3顺序对其进行排序NSLog.有简单的算法或方法吗?
// Put code in your App's ViewController
@implementation Sorting_NumbersViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// CODE STARTS HERE
// This allocates and initializes the NSMutableArray
NSMutableArray *anArray = [[NSMutableArray alloc] init];
// These are where you enter your numbers
[anArray addObject:@"1"];
[anArray addObject:@"3"];
[anArray addObject:@"2"];
//This looks looks at the objects above and compares them with each-other
NSArray *sorted = [anArray sortedArrayUsingSelector:@selector(compare:)];
//This spits the result out in the console
NSLog(@"Ordered Numbers: %@", sorted);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3576 次 |
| 最近记录: |