반응형
NSInteger를 NSString 데이터 유형으로 어떻게 변환합니까?
어떻게 변환합니까 NSInteger
받는 NSString
데이터 유형을?
나는 달이 다음과 같은 것을 시도했다 NSInteger
:
NSString *inStr = [NSString stringWithFormat:@"%d", [month intValue]];
NSInteger는 객체가 아니며 long
현재 64 비트 아키텍처의 정의와 일치시키기 위해 캐스트합니다 .
NSString *inStr = [NSString stringWithFormat: @"%ld", (long)month];
Obj-C 방법 =) :
NSString *inStr = [@(month) stringValue];
현대 목표 -C
는 NSInteger
방법 갖는 stringValue
리터로에도 사용될 수있다
NSString *integerAsString1 = [@12 stringValue];
NSInteger number = 13;
NSString *integerAsString2 = [@(number) stringValue];
매우 간단합니다. 그렇지 않습니까?
빠른
var integerAsString = String(integer)
%zd
%tu
32 비트 및 64 비트 아키텍처 모두에서 캐스트 및 경고가없는 NSInteger ( NSUInteger의 경우)에서 작동합니다 . 이것이 " 권장 방법 " 이 아닌 이유를 모르겠습니다 .
NSString *string = [NSString stringWithFormat:@"%zd", month];
왜 이것이 효과가 있는지에 관심 이 있다면이 질문을 참조하십시오 .
쉬운 방법 :
NSInteger value = x;
NSString *string = [@(value) stringValue];
여기에서 @(value)
주어진 함수를 필요한 함수를 호출 할 수 NSInteger
있는 NSNumber
객체 로 변환합니다 stringValue
.
에 대한 지원으로 컴파일 할 때 arm64
경고가 생성되지 않습니다.
[NSString stringWithFormat:@"%lu", (unsigned long)myNSUInteger];
시도해 볼 수도 있습니다 :
NSInteger month = 1;
NSString *inStr = [NSString stringWithFormat: @"%ld", month];
답이 주어 지지만 어떤 상황에서는 이것이 NSInteger에서 문자열을 얻는 흥미로운 방법이 될 것이라고 생각합니다.
NSInteger value = 12;
NSString * string = [NSString stringWithFormat:@"%0.0f", (float)value];
이 경우 NSNumber가 적합 할 수 있습니다.
NSString *inStr = [NSString stringWithFormat:@"%d",
[NSNumber numberWithInteger:[month intValue]]];
참고 URL : https://stackoverflow.com/questions/1796390/how-do-i-convert-nsinteger-to-nsstring-datatype
반응형
'programing tip' 카테고리의 다른 글
Android : android.content.res.Resources $ NotFoundException : 문자열 리소스 ID # 0x5 (0) | 2020.06.30 |
---|---|
jQuery를 사용하여 자식 요소를 부모에서 다른 부모 요소로 옮기는 방법 (0) | 2020.06.30 |
'new'를 사용하면 왜 메모리 누수가 발생합니까? (0) | 2020.06.30 |
왜 누군가가 unorder_set 대신 set을 사용합니까? (0) | 2020.06.30 |
ng serve 명령을 실행할 때“포트 4200이 이미 사용 중입니다” (0) | 2020.06.30 |