Using Version 14.0 beta (14A5228q) on Monterey 12.4
I am trying to follow the 'Meet Swift regex' presentation dated 7 June but I have stumbled on the most basic of errors that I cannot get around.
At 3:56 in the video, the following line of code is shown
let transaction = "DEBIT 03/05/2022 Doug's Dugout Dogs $33.27"
let fragments = transaction.split(separator: /\s{2,}|\t/)
// ["DEBIT", "03/05/2022", "Doug's Dugout Dogs", "$33.27"]``
The '/' of the separator string generates the error:
error: cannot convert value of type 'Regex' to expected argument type 'String.Element' (aka 'Character')
I am embarrassed but also stuck on the simple issue and I cannot figure out what I am missing.
TIA
Chris
Post
Replies
Boosts
Views
Activity
`import Cocoa
import TabularData
let greeting = "Decimal Type Evaluation"
let JSON = """
[{
"product": "Apple",
"type": "Fruit",
"weight": 7.5,
"unit_price": 0.34
},
{
"product": "Pear",
"type": "Fruit",
"weight": 0.5,
"unit_price": 0.25
}]
"""
struct Product: Decodable {
let product: String
let type: String
let weight: Double
let unit_price: Double
}
let jsonData = JSON.data(using: .utf8)!
let products: [Product] = try! JSONDecoder().decode([Product].self, from: jsonData)
var dataframe = try! DataFrame(jsonData: jsonData)
print (dataframe)`
This results in the output below showing the columns are now ordered alphabetically and not in the order they appear in the array struct definition.
┏━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ ┃ product ┃ type ┃ unit_price ┃ weight ┃
┃ ┃ <String> ┃ <String> ┃ <Double> ┃ <Double> ┃
┡━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ 0 │ Apple │ Fruit │ 0.34 │ 7.5 │
│ 1 │ Pear │ Fruit │ 0.25 │ 0.5 │
└───┴──────────┴──────────┴────────────┴──────────┘
2 rows, 4 columns
In TabularData.DataFrame, using
myDataFrame.jsonRepresentation()
returns an UnsafeRawPointer
Is there a workaround for this please?
I have a playground with multiple sources in a Sources directory in addition to the main Contents.swift. I have been unable to compile & run the playground from the command line.
The compiler is unable to resolve any items located in the separate sources and gives multiple error such as
contents.swift:8:26: error: cannot find 'JSON' in scope
print("JSON rawdata\n\n\(JSON)\n")
^~~~
The playground executes successfully from the IDE so the constants & functions etc are declared correctly as Public
I have tried
swiftc Contents.swift Sources/JSON.swift Sources/Filemanager.swift
etc but with no success
Where am I going wrong?
Failed to launch app"..." in reasonable time.
Creating a new SwiftUI app, trying to show the preview for ContentView.swift before selected another file in the project before selecting ContentView.swift
Finally , trying to show the view preview creates a
'Failed to launch app "..." in reasonable time'
along with the attached error diagnostic.
Also, MobileCal and PowerShell can, after a few minutes, quit unexpectedly. Their diagnostics are also attached.
Can't upload files a the moment