반응형
Swift에서 type def를 선언하려면 어떻게 해야 합니까?
스위프트에서 커스텀 타입이 필요하면,typedef
, 어떻게 하죠? (닫힘 구문 유형의 def와 같은 것)
키워드를typealias
대신 사용됩니다.typedef
:
typealias CustomType = String
var customString: CustomType = "Test String"
위의 답변에 추가됨:
"typealias"는 typedef와 유사한 기능을 수행하는 swift로 사용되는 키워드입니다.
/*defines a block that has
no input param and with
void return and the type is given
the name voidInputVoidReturnBlock*/
typealias voidInputVoidReturnBlock = () -> Void
var blockVariable :voidInputVoidReturnBlock = {
println(" this is a block that has no input param and with void return")
}
입력 매개변수를 사용하여 typedef를 만들려면 구문은 다음과 같습니다.
/*defines a block that has
input params NSString, NSError!
and with void return and the type
is given the name completionBlockType*/
typealias completionBlockType = (NSString, NSError!) ->Void
var test:completionBlockType = {(string:NSString, error:NSError!) ->Void in
println("\(string)")
}
test("helloooooooo test",nil);
/*OUTPUTS "helloooooooo test" IN CONSOLE */
언급URL : https://stackoverflow.com/questions/24077428/how-do-i-declare-typedef-in-swift
반응형
'IT' 카테고리의 다른 글
ASP의 다른 페이지로 리디렉션합니다.자바스크립트/jQuery를 이용한 NET MVC (0) | 2023.10.25 |
---|---|
Android: 뷰에 max Height가 없는 이유는 무엇입니까? (0) | 2023.10.25 |
엔티티 프레임워크에서 네임스페이스 변경 (0) | 2023.10.25 |
"SELECT FROM" 쿼리를 Node.js의 Mariadb에 보냅니다. (0) | 2023.10.25 |
골랑 문자열에 있는 문자를 색인하는 방법은? (0) | 2023.10.25 |