obj-c 부분 대상 빠른 값 부여 및 값 가져오기
6465 단어 대상
NSNumber *number = @1234;
기존 방식:
NSArray *physicsValues = [NSArrayarrayWithObjects:
[NSNumbernumberWithDouble:6.02214129e23],
[NSNumbernumberWithDouble:1.3806503e-23],
[NSNumbernumberWithDouble:6.626068e-34],
[NSNumbernumberWithDouble:1.097373e-7],
nil];
우리는 다음과 같은 방법으로 대체할 수 있다.
NSArray *numberArray = [NSArray arrayWithObjects:
@6.02129e23
@1.380,
@6.62,
@1.097373e-7,
nil];
하지만 위의 코드는 더욱 간단할 수 있다.
1 NSArray *numberArray = @[@6.02129e23,
2 @1.380,
3 @6.62,
4 @1.097373e-7];
5
6
7 NSArray *stringArray = @[ @"good",
8 @"see"
9 @"xCode",
10 @"what"];
물론 사전에도 유사한 방법이 있습니다. 수조는 @[]이고 사전은 @{}입니다
오래된 방법을 살펴보자.
1 nameDict = [NSDictionary dictionaryWithObjectsAndKeys:
2
3 physic, @"Physic",
4
5 newStrings, @"string",
6
7 number, @"Numbers",
8 nil];
새로운 방법:
1 nameDict = @{
2 @"Physic" : physic,
3
4 @"string" : newStrings,
5
6 @"Numbers" : number
7
8 };
배열에 대해 우리는 값을 찾으려고 하는데 일반적으로 [array objectAtindex:0]를 사용한다.
하지만 이제 더 편리하고 빠른 방법이 생겼다. 바로 아래 표지의 array[0]를 직접 사용하는 것이다. 효과는 앞의 문장과 같다.
데이터를 바꾸는 것과 같이 아래로 표시할 수 있습니다
1 // :
2
3 [valuesArray replaceObjectAtIndex:controller.indexInSection withObject:controller.value];
4
5 [valuesDictionary setObject:valuesArray forKey:controller.sectionName];
6
7 // :
8
9 valuesArray[controller.indexInSection] = controller.value;
10
11 valuesDictionary[controller.sectionName] = valuesArray;
상기 특성을 사용하면 우리는 OS 버전에 관심을 가질 필요가 없다. 이것은 컴파일러의 일이기 때문에 우리는 얼마든지 안심하고 할 수 있다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
List 컬렉션 객체에서 서로 다른 속성 크기로 정렬된 인스턴스인스턴스는 다음과 같습니다. 테스트: 출력 결과는 다음과 같습니다. 두 번째 방법은 컬렉션에 따라.sort 재부팅 방법(예: 마스터 클래스에서 이렇게 작성하면 됩니다. 출력 결과는 다음과 같습니다. 전자의 코드 구조...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.