Objective-c Array Detailed __oc

Source: Internet
Author: User

(1) Create an array and output it. To create an array directly using Nsarray, [arr count] calls the method to compute the length of the array. [Arr objectatindex:i] is an object that invokes a method to get a index position.

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main (int argc, char * argv[]) {
  
  Nsarray *arr = @[@ " Hello ", @" World "];
  
  for (int i = 0; i < [arr count]; i++) {
    
    NSLog (@ "%@", [arr objectatindex:i]);
  }
  
  

(2) The invocation of the computed length at this time uses the array's property value count, so the Arr.count call is used directly. When accessing data, it is also the most common use of subscript direct access in other languages.

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main (int argc, char * argv[]) {
  
  Nsarray *arr = @[@ " Hello ", @" World "];
  
  for (int i = 0; i < Arr.count i++) {
    
    NSLog (@ "%@", Arr[i]);
  }
  
  

(3) Declaring a string using the factory method:

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main (int argc, char * argv[]) {
  
  Nsarray *arr = [NSA Rray arraywithobjects:@ "Hello", @ "World", nil];
  
  for (int i = 0; i < Arr.count i++) {
    
    NSLog (@ "%@", Arr[i]);
  }
  
  

(4) Read the plist file and create a new data.plist. as follows:


The code is as follows:

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main (int argc, char * argv[]) {
  
  Nsarray *arr = [NSA Rray arraywithcontentsoffile:[[nsbundle Mainbundle] pathforresource:@ "Data" oftype:@ "plist"]];
  
  for (int i = 0; i < Arr.count i++) {
    
    NSLog (@ "%@", Arr[i]);
  }
  
  



GitHub home: https://github.com/chenyufeng1991. You are welcome to visit.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: