Skip to content
This repository was archived by the owner on Apr 16, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Pod/Classes/ExportConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ internal extension ExportConfiguration {
case .ALL:
return predicateNoCorreltion
case .ADDED_BY_THIS_APP:
return NSCompoundPredicate(andPredicateWithSubpredicates: [predicateNoCorreltion, HKQuery.predicateForObjectsFromSource(HKSource.defaultSource())])
return NSCompoundPredicate(andPredicateWithSubpredicates: [predicateNoCorreltion, HKQuery.predicateForObjects(from: HKSource.default())])
case .GENERATED_BY_THIS_APP:
return NSCompoundPredicate(andPredicateWithSubpredicates: [predicateNoCorreltion, HKQuery.predicateForObjectsWithMetadataKey("GeneratorSource", allowedValues: ["HSG"])])
return NSCompoundPredicate(andPredicateWithSubpredicates: [predicateNoCorreltion, HKQuery.predicateForObjects(withMetadataKey: "GeneratorSource", allowedValues: ["HSG"])])
}

}
Expand Down
48 changes: 24 additions & 24 deletions Pod/Classes/ExportTargets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,77 +19,77 @@ public protocol ExportTarget {
func endExport() throws -> Void

/// output the metadata of the profile
func writeMetaData(creationDate creationDate: NSDate, profileName: String, version: String) throws -> Void
func writeMetaData(creationDate: Date, profileName: String, version: String) throws -> Void
/// output the user data from healthkit
func writeUserData(userData: Dictionary <String, AnyObject>) throws -> Void
func writeUserData(_ userData: Dictionary <String, AnyObject>) throws -> Void
/// start writing a type
func startWriteType(type:HKSampleType) throws -> Void
func startWriteType(_ type:HKSampleType) throws -> Void
/// end writing a type
func endWriteType() throws -> Void
/// write a dictionary to the output - e.g. a dict of the sample data
func writeDictionary(entry:Dictionary <String, AnyObject>) throws -> Void
func writeDictionary(_ entry:Dictionary <String, AnyObject>) throws -> Void
}

/// An export target that generetes a single json doc for the whole data.
public class JsonSingleDocExportTarget {
open class JsonSingleDocExportTarget {

private(set) var jsonWriter: JsonWriter
fileprivate(set) var jsonWriter: JsonWriter

init(outputStream: OutputStream){
self.jsonWriter = JsonWriter(outputStream: outputStream)
}

/// see ExportTarget Protocol
public func startExport() -> Void {
open func startExport() -> Void {
jsonWriter.writeStartObject()
}

/// see ExportTarget Protocol
public func endExport() {
open func endExport() {
jsonWriter.writeEndObject()
jsonWriter.close()
}

/// see ExportTarget Protocol
public func writeMetaData(creationDate creationDate: NSDate, profileName: String, version: String) {
open func writeMetaData(creationDate: Date, profileName: String, version: String) {

jsonWriter.writeObjectFieldStart(HealthKitConstants.META_DATA)

jsonWriter.writeField(HealthKitConstants.CREATION_DATE, value: creationDate)
jsonWriter.writeField(HealthKitConstants.PROFILE_NAME, value: profileName)
jsonWriter.writeField(HealthKitConstants.VERSION, value: version)
jsonWriter.writeField(HealthKitConstants.TYPE, value: String(JsonSingleDocExportTarget))
jsonWriter.writeField(HealthKitConstants.TYPE, value: String(describing: JsonSingleDocExportTarget.self))

jsonWriter.writeEndObject()
}

/// see ExportTarget Protocol
public func writeUserData(userData: Dictionary <String, AnyObject>) throws {
open func writeUserData(_ userData: Dictionary <String, AnyObject>) throws {
try jsonWriter.writeFieldWithObject(HealthKitConstants.USER_DATA, value: userData)
}

/// see ExportTarget Protocol
public func startWriteType(type:HKSampleType) -> Void {
jsonWriter.writeArrayFieldStart(String(type))
open func startWriteType(_ type:HKSampleType) -> Void {
jsonWriter.writeArrayFieldStart(type.identifier)
}

/// see ExportTarget Protocol
public func endWriteType() -> Void {
open func endWriteType() -> Void {
jsonWriter.writeEndArray()
}

/// see ExportTarget Protocol
public func writeDictionary(entry:Dictionary <String, AnyObject>) throws -> Void {
open func writeDictionary(_ entry:Dictionary <String, AnyObject>) throws -> Void {
try jsonWriter.writeObject(entry)
}
}

/// an export target that creates a single json doc within a file
public class JsonSingleDocAsFileExportTarget : JsonSingleDocExportTarget, ExportTarget {
open class JsonSingleDocAsFileExportTarget : JsonSingleDocExportTarget, ExportTarget {

/// the full path of the ouput file
private(set) public var outputFileName: String
private(set) var overwriteIfExist = false
fileprivate(set) open var outputFileName: String
fileprivate(set) var overwriteIfExist = false

/**
Instantiate a JsonSingleDocAsFileExportTarget.
Expand All @@ -107,11 +107,11 @@ public class JsonSingleDocAsFileExportTarget : JsonSingleDocExportTarget, Export
Check the validity of the ExportTarget.
- Returns: true if the file does not already exist or overwrite is allowed.
*/
public func isValid() -> Bool {
open func isValid() -> Bool {
var valid = true

// if the outputFileName already exists, the state is only valid, if overwrite is allowed
if NSFileManager.defaultManager().fileExistsAtPath(outputFileName) {
if FileManager.default.fileExists(atPath: outputFileName) {
valid = valid && overwriteIfExist
}

Expand All @@ -120,20 +120,20 @@ public class JsonSingleDocAsFileExportTarget : JsonSingleDocExportTarget, Export
}

/// an export target that creates a single json doc in memory
public class JsonSingleDocInMemExportTarget: JsonSingleDocExportTarget, ExportTarget {
open class JsonSingleDocInMemExportTarget: JsonSingleDocExportTarget, ExportTarget {

/// create a JsonSingleDocExportTarget in Mem
public init(){
super.init(outputStream: MemOutputStream())
}

/// is always valid
public func isValid() -> Bool {
open func isValid() -> Bool {
return true
}

/// see ExportTarget Protocol
public func getJsonString() -> String {
open func getJsonString() -> String {
return jsonWriter.getJsonString()
}
}
}
Loading