IOS
527. (ios/swift5) [유틸 파일] getAssetLoadHtmlUrl : 프로젝트 내에 저장된 html 파일 로드 수행
투케이2K
2024. 5. 1. 11:23
728x90
[개발 환경 설정]
개발 툴 : XCODE
개발 언어 : SWIFT5

[소스 코드]
// -----------------------------------------------------------------------------------------
// MARK: - [프로젝트 내에 저장된 html 파일 로드 수행]
// -----------------------------------------------------------------------------------------
func getAssetLoadHtmlUrl(filePath: String) -> URLRequest? {
/*
// -----------------------------------------
[getAssetLoadHtmlUrl 메소드 설명]
// -----------------------------------------
1. 프로젝트 내에 저장된 html 파일 로드 수행
// -----------------------------------------
2. 호출 방법 :
C_App().getAssetLoadHtmlUrl(filePath: "functionTest")
// -----------------------------------------
3. 리턴 예시 :
file:///private/var/containers/Bundle/Application/59377464-9069-4A49-B89F-BBBB194A4FE4/swiftProject.app/functionTest.html
// -----------------------------------------
*/
// [변수 선언]
var returnData: URLRequest? = nil
var M_LOG = ""
// [로직 처리 수행]
if C_Util().stringNotNull(str: filePath) == true {
guard let localFilePath = Bundle.main.path(forResource: filePath, ofType: "html")
else {
M_LOG = "[Error] :: file type error"
S_Log._D_(description: "프로젝트 내에 저장된 html 파일 로드 에러", data: [
"M_LOG :: \(String(describing: M_LOG))"
])
return nil
}
let urlFile = URL(fileURLWithPath: localFilePath)
var request = URLRequest(url: urlFile)
// [리턴 변수 삽입]
returnData = request
M_LOG = "[Success] :: getAssetLoadHtmlUrl"
}
else {
M_LOG = "[Error] :: Input Data Is Null"
}
// [로그 출력 실시]
S_Log._D_(description: "프로젝트 내에 저장된 html 파일 로드 수행", data: [
"INPUT :: \(String(describing: filePath))",
"M_LOG :: \(String(describing: M_LOG))",
"RETURN :: \(String(describing: returnData))"
])
// [리턴 변수 선언]
return returnData
}
[결과 출력]

728x90
반응형