Xcode에서 메소드를 폐기하는 방법
고객에게 제공하는 라이브러리가 있고 일부 메소드를 변경 표시 때문에 "사용되지 않음"으로 표시하고 싶습니다 (예 : Apple이 iPhone SDK에서 수행함).
나는 본 적이 __OSX_AVAILABLE_BUT_DEPRECATED
에 매핑되는 전 처리기 매크로 __AVAILABILITY_INTERNAL
에 매핑, __attribute__((deprecated))
...
글쎄, 나는이 물건과 혼란스러워!
아무도 어디에 있습니까?
__attribute__((deprecated))
는 IS GCC 방법 (도 연타에서 지원 하지 않는 등의 기능 / 방법은 마킹)입니다. 하나가 "사용되지 않음"으로 표시되면 누군가 호출 할 때마다 경고가 생성됩니다.
일반 함수의 구문은 다음과 가변적입니다.
__attribute__((deprecated))
void f(...) {
...
}
// gcc 4.5+ / clang
__attribute__((deprecated("g has been deprecated please use g2 instead")))
void g(...) {
...
}
Objective-C 방법의 경우
@interface MyClass : NSObject { ... }
-(void)f:(id)x __attribute__((deprecated));
...
@end
다음을 사용하여 전체 클래스를 더 이상 사용하지 않음으로 표시 할 수도 있습니다.
__attribute__((deprecated))
@interface DeprecatedClass : NSObject { ... }
...
@end
Apple은 또한 <AvailabilityMacros.h>
위의 속성으로 확장되는 DEPRECATED_ATTRIBUTE 및 DEPRECATED_MSG_ATTRIBUTE (msg) 매크로를 제공하는 헤더를 제공하거나 컴파일러가 속성을 지원하지 않는 경우 아무 것도 제공하지 않습니다. 이 헤더는 OS X / iOS 외부에 존재하지 않습니다.
참고로 Swift를 사용하는 경우 @available
속성 을 사용하여 항목을 비추천합니다.
@available(*, deprecated=2.0, message="no longer needed")
func f() {
...
}
더 읽기 쉬운 정의를 사용할 수도 있습니다.
DEPRECATED_ATTRIBUTE
정의 usr/include/AvailabilityMacros.h
:
#define DEPRECATED_ATTRIBUTE __attribute__((deprecated))
#define DEPRECATED_MSG_ATTRIBUTE(msg) __attribute((deprecated((msg))))
Objective-C 방법 예 :
@interface MyClass : NSObject { ... }
-(void)foo:(id)x DEPRECATED_ATTRIBUTE;
// If you want to specify deprecated message:
-(void)bar:(id)x DEPRECATED_MSG_ATTRIBUTE("Use baz: method instead.");
...
@end
전체 클래스를 더 이상 사용하지 않습니다.
DEPRECATED_ATTRIBUTE
@interface DeprecatedClass : NSObject { ... }
...
@end
엑스 코드 프로젝트에서 C ++ 14 사용하는를 [[deprecated]]
경우 [[deprecated("reason")]]
이제 언어의 일부인 또는 속성을 사용할 수도 있습니다.
문서 참조 : http://en.cppreference.com/w/cpp/language/attributes
-SWIFT 코드 :
방법 바로 위에 이것을 넣으십시오. @available(*, deprecated: <#Version#>, message: <#Message#>)
예:
@available(*, deprecated: 11, message: "Use color assets instead")
public struct ColorPaletteItemResource: ColorPaletteItemResourceType {
...
}
스위프트 5.0
다음을 사용하여 모든 메소드 / 클래스 / 구조체 / 프로토콜을 폐기하십시오. @available
@available(*, deprecated, message: "Parse your data by hand instead")
func parseData() { }
@available(*, deprecated, renamed: "loadData")
func fetchData() { }
@available(swift, obsoleted: 4.1, renamed: "attemptConnection")
func testConnection() { }
@available(swift, deprecated: 4.0, obsoleted: 5.0, message: "This will be removed in v5.0; please migrate to a different API.")
가능한 매개 변수 :
- 도입
- 비추천
- 구식
- 메시지
- 이름이 변경됨
자세한 내용은 apple doc : 속성을 참조하십시오.
참고 URL : https://stackoverflow.com/questions/4924285/how-to-deprecate-a-method-in-xcode
'ProgramingTip' 카테고리의 다른 글
jQuery 또는 순수 JS를 사용하여 무엇입니까? (0) | 2020.10.13 |
---|---|
MySQL은 가장 최근 행에만 가입 하시겠습니까? (0) | 2020.10.13 |
SQL Server의 이스케이프 문자 (0) | 2020.10.13 |
C # String.IsNullOrEmpty Javascript (0) | 2020.10.13 |
AsyncTask에서 발생하는 가져 오기 (0) | 2020.10.13 |