iOS sort array 数组排序里面的对象
一:如下代码
//对数据按次数排序
NSArray *sortArrays = [pinCiDataArray sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { NSNumber *num1 = [(ReplayModel *)obj1 useTimes];
NSNumber *num2 = [(ReplayModel *)obj2 useTimes]; return [num2 compare:num1]; }];
数组pinCiDataArray保存的是对象 ReplayModel;
ReplayModel 对象有一个 useTimes的 NsNumber属性;
如上代码对数组按 useTimes的使用次数排序;
[num1 compare :num2] 为结果升序
[num2 compare :num1] 为结果降序
参考:http://stackoverflow.com/questions/805547/how-to-sort-an-nsmutablearray-with-custom-objects-in-it
iOS sort array 数组排序里面的对象的更多相关文章
- LeetCode 905. Sort Array By Parity
905. Sort Array By Parity Given an array A of non-negative integers, return an array consisting of a ...
- 905. Sort Array By Parity - LeetCode
Question 905. Sort Array By Parity Solution 题目大意:数组排序,偶数放前,奇数在后,偶数的数之间不用管顺序,奇数的数之间也不用管顺序 思路:建两个list, ...
- LeetCode 922. Sort Array By Parity II C++ 解题报告
922. Sort Array By Parity II 题目描述 Given an array A of non-negative integers, half of the integers in ...
- Sort Array By Parity II LT922
Given an array A of non-negative integers, half of the integers in A are odd, and half of the intege ...
- js sort方法根据数组中对象的某一个属性值进行排序(实用方法)
js sort方法根据数组中对象的某一个属性值进行排序 sort方法接收一个函数作为参数,这里嵌套一层函数用来接收对象属性名,其他部分代码与正常使用sort方法相同. var arr = [ {nam ...
- [LeetCode] 922. Sort Array By Parity II 按奇偶排序数组之二
Given an array A of non-negative integers, half of the integers in A are odd, and half of the intege ...
- 【LEETCODE】42、922. Sort Array By Parity II
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- 【LEETCODE】41、905. Sort Array By Parity
package y2019.Algorithm.array; /** * @ProjectName: cutter-point * @Package: y2019.Algorithm.array * ...
- Relative Sort Array
Relative Sort Array Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all eleme ...
随机推荐
- textbox获取当前光标位置,在光标后面插入字符串
左侧输入要复制的字符串,点击复制btn,将左侧字符串复制到后侧, 示例: 输入框 复制后 12345 12345 (光标落在3后) aaa 123aaa45(光标落在4后 ...
- 洛谷P1414 又是毕业季 [数论]
题目传送门 又是毕业季 题目背景 “叮铃铃铃”,随着高考最后一科结考铃声的敲响,三年青春时光顿时凝固于此刻.毕业的欣喜怎敌那离别的不舍,憧憬着未来仍毋忘逝去的歌.1000多个日夜的欢笑和泪水,全凝聚在 ...
- Codeforces Round #425 (Div. 2) Misha, Grisha and Underground(LCA)
Misha, Grisha and Underground time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- JZYZOJ1452 NOIP2015_提高组Day2_1_跳石头
http://172.20.6.3/Problem_Show.asp?id=1452很简单的二分,最开始以为是优先队列,想了想发现优先队列是有情况不能达到最优的,所以二分+贪心处理,在贪心check的 ...
- 【状压dp】送餐员
[odevs2800]送餐员 题目描述 Description 有一个送外卖的,他手上有n份订单,他要把n份东西,分别送达n个不同的客户的手上.n个不同的客户分别在1~n个编号的城市中.送外卖的从0号 ...
- [TCO2013]TrickyInequality
$\newcommand{stirf}[2]{{{#1}\brack{#2}}}$$\newcommand{stirs}[2]{{{#1}\brace{#2}}}$题意:$\sum\limits_{i ...
- 【高精度】POJ1001-Exponentiation
整个题库的第二题,原本都没有屑于去做,突发奇想抱着秒杀的心态去写了代码,却硬生生地吃了4个WA.. [思路]先去除掉小数点,进行最基本的高精度乘法运算,再在运算得到的结果中添加小数点输出. [前铺]让 ...
- java之判断输入的数是否为素数
import java.util.Scanner; public class TestIsSushu { public static void main(String[] args) { Scanne ...
- [原创]Java中字符串、数组、集合及JSONArray的长度属性
前言:数组没有length()这个方法,有length的属性.String有有length()这个方法. 1.String字符串 String str = "abcdefg";st ...
- 阿里云ECS使用SSH连接CentOS 6.9经常断线的问题解决:OperationTimedOut
说明:不一定有效,可以试一下. 设置: vi /etc/ssh/sshd_config #添加或修改以下配置 ClientAliveInterval #每隔多少秒给SSH客户端发送一次信号 Clien ...