resource txt 화일을 드래그 해서 navigator 화면에 드래그해서 아무데나 넣는다. 어디든 프로젝트안이라면 ios가 검색할수 있다.

Bundle.main.path(forResource: “testtext”, ofType: “txt”)를 통해 path string을 얻을수 있다. ref) https://developer.apple.com/documentation/foundation/bundle/1410989-path?changes=_2 

Bundle.main.url(forResource: ofType: )을 통해서는 url obj를 얻을수 있다. ref) https://developer.apple.com/documentation/foundation/bundle/1411540-url?changes=_2

String()을 통해 화일의 txt내용을 읽어 올수 있다. ref) https://developer.apple.com/documentation/swift/string/1414831-init?changes=_2

let file = “csvTest.csv” //this is the file. we will write to and read from it

       if let path = Bundle.main.path(forResource: “testtext”, ofType: “txt”) {

           print(“check point2”)

           //reading

           do {

               print(“check point3”)

               let text2 = try String(contentsOfFile: path)

               print(text2)

           }

           catch {/* error handling here */}

오래전에 만들어진 tutorial이나 블로그 포스트를 보면 요즘(2018 6 10) 과 appdelegate에 있는 코드가 다른것을 알수 있다. 최근의 코드에서는 persistentContainer 를 통해 managedObjectContext, managedObjectModel, persistentStoreCoordinator 에 접근할수 있게 되었다.

최근)

// 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: "test")
        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
    }()

    // MARK: - Core Data Saving support

    func saveContext () {
        let context = persistentContainer.viewContext
        if context.hasChanges {
            do {
                try context.save()
            } catch {
                // 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.
                let nserror = error as NSError
                fatalError("Unresolved error (nserror), (nserror.userInfo)")
            }
        }
        
        
    }



예전)

import CoreData
class CoreDataStack {
    // Applications default directory address
    lazy var applicationDocumentsDirectory: NSURL = {
        let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
        return urls[urls.count-1]
}()
lazy var managedObjectModel: NSManagedObjectModel = {
        // 1
        let modelURL = NSBundle.mainBundle().URLForResource("Supercars", withExtension: "momd")!
        return NSManagedObjectModel(contentsOfURL: modelURL)!
}()
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
        let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
        let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("SuperCars.sqlite")
        do {
            // If your looking for any kind of migration then here is the time to pass it to the options
            try coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil)
        } catch let  error as NSError {
           print("Ops there was an error (error.localizedDescription)")
           abort()
        }
        return coordinator
}()

lazy var managedObjectContext: NSManagedObjectContext = {
// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the
application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to
fail.
        let coordinator = self.persistentStoreCoordinator
        var context = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
        context.persistentStoreCoordinator = coordinator
        return context
}()
// if there is any change in the context save it
func saveContext() {
        if mangagedObjectContext.hasChanges {
            do {
                try managedObjectContext.save()
            } catch let error as NSError {
                print("Ops there was an error (error.localizedDescription)")
                abort() 
      }
     } 
   }
}

samsung smatthings 에서 smart app을 만드는 방법 설명 

samsung smatthings 에서 smart app이란?

각각의 기기별 기본기능에 반응하는 app을 말한다. 예를 들어 LG iot 스위치가 센서도 있도 스위치기능도 있는 경우라고 한다면 smart app에서는 스위치로 구분되어 스위치 기능에대한 general api 에 접근해 작업을 수행할수 있게 된다. 

aws 기본 구성 요소

image

aws iot core ( iot 기기에 대한 기본 작업)

image
image
image

image


aws iot 1 click (원 클릭에 대응하는 기기에 대한 서비스)

image


aws iot device defender (iot 기기에 대한 authorization, authentication 작업 제공)

image

aws green grass

개념이해를 위한 비디오 (local network단위내에서 기기간 서로 상호작용하고 또 이것이 외부 클라우드 서비스와도 상호작용하는 기능을 제공하는 듯)

https://youtu.be/1rLxPOxVJoQ