Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

NSMutableArray+QueueAdditions.m 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. #import "NSMutableArray+QueueAdditions.h"
  18. @implementation NSMutableArray (QueueAdditions)
  19. - (id)cdv_queueHead
  20. {
  21. if ([self count] == 0) {
  22. return nil;
  23. }
  24. return [self objectAtIndex:0];
  25. }
  26. - (__autoreleasing id)cdv_dequeue
  27. {
  28. if ([self count] == 0) {
  29. return nil;
  30. }
  31. id head = [self objectAtIndex:0];
  32. if (head != nil) {
  33. // [[head retain] autorelease]; ARC - the __autoreleasing on the return value should so the same thing
  34. [self removeObjectAtIndex:0];
  35. }
  36. return head;
  37. }
  38. - (id)cdv_pop
  39. {
  40. return [self cdv_dequeue];
  41. }
  42. - (void)cdv_enqueue:(id)object
  43. {
  44. [self addObject:object];
  45. }
  46. @end