2017-02-09 11 views
1

그래서 배포 대상을 iOS 9 (실제로는 10.0 이하)로 설정하려고하면 제목에 오류가 표시됩니다.Swift 3 - "NSPersistentContainer는 ios 10 이상에서만 사용 가능합니다"

이 문제는 여기에 존재합니다

// MARK: - Core Data stack 

lazy var persistentContainer: NSPersistentContainer = { 
    /* 
    The persistent container for the application. This implementation 
    creates and returns a container, having loaded the store for the 
    application to it. This property is optional since there are legitimate 
    error conditions that could cause the creation of the store to fail. 
    */ 
    let container = NSPersistentContainer(name: "Keebin_development_1") 
    container.loadPersistentStores(completionHandler: { (storeDescription, error) in 
     if let error = error as NSError? { 
      // Replace this implementation with code to handle the error appropriately. 
      // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 

     /* 
     Typical reasons for an error here include: 
     * The parent directory does not exist, cannot be created, or disallows writing. 
     * The persistent store is not accessible, due to permissions or data protection when the device is locked. 
     * The device is out of space. 
     * The store could not be migrated to the current model version. 
     Check the error message to determine what the actual problem was. 
     */ 
     fatalError("Unresolved error \(error), \(error.userInfo)") 
    } 
}) 
return container 
}() 

내가 아이폰 OS 10을 사용할 수 있는지 여부를 구별하는 몇 가지 코드를 추가 할 필요가 있음이 분명 다른 SO 질문/답변에서 찾고있다. 스위프트 3 자체는 @available(iOS 10.0, *)을 사용하여 제안합니다. 그래도 충분하지 않습니다. 나는 그것이 "쓸모가 없다면 이것을 사용하지 않을 것"이라고 생각하지만, Swift와 iOS 프로그래밍에 익숙하지 않아 무엇을 구체적으로 쓰는지 모르겠습니다. 그리고 나는 무엇을 써야하는지에 대한 정확한 답을주는 대답을 찾을 수없는 것 같습니다. 누군가 도울 수 있습니까?

답변

1

iOS 10과 이전 버전을 구분할 필요가 없습니다. NSPersistentContainer에는 iOS 10이 필요하지만 이전 기술은 여전히 ​​작동하며 계속 지원됩니다. iOS <을 지원해야하는 경우 NSPersistentContainer을 사용하지 마십시오. 관리 객체 모델을로드하고 영구 저장소를 추가하는 것이 더 많은 단계이지만 이렇게하면 모든 버전의 iOS에 대해 단일 코드 경로를 가질 수 있습니다. 당신은 여전히 ​​

다른 솔루션을 사용하는 것이 앱이 여전히 아이폰 OS 10에서 작동되는 기존의 코어 데이터 스택을 사용하여 이전 버전에서 작업해야하는 경우

5

나는 동일한 문제에 직면했으며 아래에 언급 된 방법으로 해결했습니다. 내가 스위프트 3.0

  • 에서 프로젝트를하고 있었다 나는 포드 'INSPersistentContainer'을 사용하고 내 프로젝트에 포드를 설치했습니다.
  • 그런 다음 NSPersistentContainerINSPersistentContainer

를 교체하고 모든 먹으 렴이 행 "import INSPersistentContainer"

  • 에 의해 APpDelegate에서 수입.

    는 지금은

    그것은 당신을 도울 것입니다 희망 아이폰 OS (< 아이폰 OS 10)의 낮은 버전에서 내 응용 프로그램을 실행할 수 있습니다. 해피 코딩 ...

  • +0

    을 지원하기 위해이 응답을 따를 수 있는가? 제 3 자 lib가없는 코드를 통해이를 해결할 수있는 방법이 있기를 희망했습니다. –

    1

    NSPersistentContainer는 아이폰 OS 10

    에서만 사용할 수 있습니다 핵심 데이터 스택 또는 NSPersistentContainer를 실행하기 위해 swift에서 사용할 수있는 속성.

    당신은 https://stackoverflow.com/a/42392120/8023444에게 모두 IOS 9 IOS (10) 제 3 자 라이브러리를 잘하지만입니다