RubyCocoa将NSSortDescriptor应用于ruby数组。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RubyCocoa将NSSortDescriptor应用于ruby数组。相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env ruby require 'osx/cocoa' # Build an array of Hashes to sort, could be objects, etc ... data = Array.new data << {:firstname => "Skippy", :lastname => "McFearson", :age => "31"} data << {:firstname => "Ned", :lastname => "Flanders", :age => "75"} data << {:firstname => "Jim", :lastname => "DodSon", :age => "44"} data << {:firstname => "Bob", :lastname => "Austin", :age => "25"} # Apply the Sort Descriptor and sort the array. ageDescriptor = OSX::NSSortDescriptor.alloc.initWithKey_ascending("age", true) sortDescriptors = [ageDescriptor] sortedArray = data.to_ns.sortedArrayUsingDescriptors(sortDescriptors) puts sortedArray.inspect
以上是关于RubyCocoa将NSSortDescriptor应用于ruby数组。的主要内容,如果未能解决你的问题,请参考以下文章