2016-10-04 2 views
1

나는 iOS 프로젝트를 보유하고 있습니다. Xcode 8을 사용 중이며 현재 Swift 3을 사용 중입니다. 나는 최근에 Swift 2에서 내 프로젝트 변환을 시작하기 전에, 나는 내 AppDelegate에서 다음을했다 :Swift 3에서 빈 URL을 어떻게 표현합니까?

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool { 

    // Transfer incoming file to global variable to be read 
    if url != "" { 

     // Load from Mail App 

     incomingFileTransfer = url 

     incomingStatus = "Incoming" 

    } else { 

     // Regular Load 

     print("App Delegate: No incoming file") 

     incomingFileTransfer = nil 

    } 

    return true 
} 

훌륭한 근무하고 들어오는 PDF 형식의 파일을 응용 프로그램에 의해 열릴이 있다면 그것은 볼 것입니다. 내 응용 프로그램과 관련된 PDF 파일을 가지고 있으며 내 응용 프로그램 내에서 열 수 있습니다.

코드를 새로운 Swift 3 코드로 변환하는 데 마이그레이션 도구를 사용했습니다.

IT는 AppDelegate에 내 코드를 변환에 변경 : 지금 내가 NSURL이었다 'URL 열기'를 이해

Binary operator '!=' cannot be applied to operands of type 'URL' and 'String'

: 그것은 오류를 제공하지만

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool { 

    // Transfer incoming file to global variable to be read 
    if url != "" { 

     // Load from Mail App 

     incomingFileTransfer = url 

     incomingStatus = "Incoming" 

    } else { 

     // Regular Load 

     print("App Delegate: No incoming file") 

     incomingFileTransfer = nil 

    } 

    return true 
} 

대신 URL을 입력하십시오. Xcode 8과 Swift 3에서 빈 URL을 어떻게 표현합니까? 온라인에서 보았는데 이것에 대해 아무 것도 찾을 수 없습니까?

도움과 조언에 감사드립니다.

답변

2

absoluteString 속성을 사용하려고 시도하면 URL이 비어 있습니다.

if url.absoluteString != "" { 

} 
else { 

} 

참고 : 당신은 그냥 비어를 확인하려면, 다음의 경우에 StringisEmpty 속성을 사용하는 타자if !url.absoluteString.isEmpty {

과 같이됩니다
관련 문제