4 ms·
shuffled() can accept randomness generator, this form just uses the default. Also .shuffled() returns a new array. For in-place shuffling there is .shuffle().
by rimliu 8y ago
shuffled() can accept randomness generator, this form just uses the default.
Also .shuffled() returns a new array. For in-place shuffling there is .shuffle(). This pattern is consistent: verb() is for in-place actions, verbed() if for actions returning a new collection e.g. sort()/sorted().
Btw, there is also .first(where:) which accepts a predicate.
- jonhohle 8y agoContrast that to Objective C < 2, Ruby, or Smalltalk where everything is a message sent to the object and there are no exposed, public fields.
- wool_gather 8y agoYou're misremembering. Prior to ObjC 2, classes indeed exposed fields. Convention was that you should not touch them and use accessors instead, but they were most definitely there, declared in the `@interface`. @interface Foo : NSObject { NSString * name; NSInteger count; } - (NSString)name; - (void)setName:(NSString *)newName; - (NSInteger)count; @end (This is still legal, of course, but bad practice now that there's `@property` synthesis as well as ivars being declarable in either an extension or the `@implementation` block.)