CoreOffice / XMLCoder

Easy XML parsing using Codable protocols in Swift
https://coreoffice.github.io/XMLCoder/
MIT License
800 stars 112 forks source link

Example Error (swift package manager) #172

Closed xiote closed 4 years ago

xiote commented 4 years ago
warning: dependency 'XMLCoder' is not used by any target
/Users/xiote/github.com/xiote/swift-XMLCoder-Example/Sources/XMLCoderExample/XMLCoderExample.swift:19:1: error: statements are not allowed at the top level
guard let data = xmlStr.data(using: .utf8) else { return }
^
/Users/xiote/github.com/xiote/swift-XMLCoder-Example/.build/x86_64-apple-macosx/debug/XMLCoder.build/module.modulemap:2:12: error: header '/Users/xiote/github.com/xiote/swift-XMLCoder-Example/.build/x86_64-apple-macosx/debug/XMLCoder.build/XMLCoder-Swift.h' not found
    header "/Users/xiote/github.com/xiote/swift-XMLCoder-Example/.build/x86_64-apple-macosx/debug/XMLCoder.build/XMLCoder-Swift.h"
           ^
/Users/xiote/github.com/xiote/swift-XMLCoder-Example/Sources/XMLCoderExample/XMLCoderExample.swift:1:8: error: could not build Objective-C module 'XMLCoder'
import XMLCoder
➜  swift-XMLCoder-Example swift --version
Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
Target: x86_64-apple-darwin19.4.0
➜  swift-XMLCoder-Example swift package --version
Swift Package Manager - Swift 5.2.0

import PackageDescription

let package = Package( name: "XMLCoderExample", products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( name: "XMLCoderExample", targets: ["XMLCoderExample"] ), ], dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: / package url /, from: "1.0.0"), .package(url: "https://github.com/MaxDesiatov/XMLCoder.git", from: "0.10.0"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "XMLCoderExample", dependencies: [] ), .testTarget( name: "XMLCoderExampleTests", dependencies: ["XMLCoderExample"] ), ] )


* Sources/XMLCoderExample/XMLCoderExmaple.swift
```swift
import XMLCoder

let xmlStr = """
<note>
    <to>Bob</to>
    <from>Jane</from>
    <heading>Reminder</heading>
    <body>Don't forget to use XMLCoder!</body>
</note>
"""

struct Note: Codable {
    let to: String
    let from: String
    let heading: String
    let body: String
}

guard let data = xmlStr.data(using: .utf8) else { return }

let note = try? XMLDecoder().decode(Note.self, from: data)

let returnData = try? XMLEncoder().encode(note, withRootKey: "note")

struct XMLCoderExample {
    var text = "Hello, World!"
}
xiote commented 4 years ago

import XMLCoder issue

build/x86_64-apple-macosx/debug/XMLCoder.build/module.modulemap:2:12: error: header '.build/x86_64-apple-macosx/debug/XMLCoder.build/XMLCoder-Swift.h' not found
    header ".build/x86_64-apple-macosx/debug/XMLCoder.build/XMLCoder-Swift.h"
           ^
main.swift:32:8: error: could not build Objective-C module 'XMLCoder'
import XMLCoder
xiote commented 4 years ago

import PackageDescription

let package = Package( name: "XMLCoderExample", products: [ // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( name: "XMLCoderExample", targets: ["XMLCoderExample"] ), ], dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: / package url /, from: "1.0.0"), .package(url: "https://github.com/MaxDesiatov/XMLCoder.git", from: "0.10.0"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "XMLCoderExample", dependencies: ["XMLCoder"] ), .testTarget( name: "XMLCoderExampleTests", dependencies: ["XMLCoderExample"] ), ] )