(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.