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
Selecting any option will automatically load the page
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
If I create a playground project that uses a JSONDecoder I get the following error.
The LLDB RPC Server has crashed. The crash log is located at ~/Library/Logs/DiagnosticReports and has a prefix 'lldb-rpc-server'. Please file a bug and attach the most recent crash log.
I have raised feedback for this, FB17702087, but I hope that there may be a workaround.
The code I am using to try and get this to work is from The Apple Developer Documentation - JSON Decoder
var greeting = "JSON Test 3"
struct GroceryProduct: Codable {
var name: String
var points: Int
var description: String?
}
let json = """
{
"name": "Durian",
"points": 600,
"description": "A fruit with a distinctive scent."
}
""".data(using: .utf8)!
let decoder = JSONDecoder()
let product = try decoder.decode(GroceryProduct.self, from: json)
print(product.name) // Prints "Durian"
A screenshot of the playground showing the error
The crash log (the file type has been changed to txt as ips file types cannot be selected for upload.
lldb-rpc-server-2025-05-28-140832.txt
Xcode 16.4, MacOS Sequoia 15.5
If I try to use a logger in an Xcode Playground e.g.
import os
import UIKit
var logger = Logger(subsystem: "Loggertest", category: "")
logger.info("Hello, world!")
I get the following error
error: Couldn't look up symbols: ___dso_handle ___dso_handle Hint: The expression tried to call a function that is not present in the target, perhaps because it was optimized out by the compiler.
Its the logger.info ... that is causing the error.
I have raised FB18214090 but there are no other reports.
I would be grateful if some of you could verify if the Playground runs or errors on your system.
A workaround, still using Logger, would be a great help.
Thanks,
Chris
Topic:
Developer Tools & Services
SubTopic:
Xcode
I have a small playground approx 150 lines no SwiftUI
It also has a 70 line text file
Xcode now thinks I have over 4000 files that have changed and they are Xcode or system files
If I am looking at this list then the Mac Mini will freeze with a frozen mouse, just a stuck mouse pointer.
After a minute or so the Mac will reboot itself.
Any suggestions as to how to fix this would be appreciated.
I have already reinstalled Xcode and the tools and its still the same.
Topic:
Developer Tools & Services
SubTopic:
Xcode
The view in the images snap to position in increasing offsets to the left such by the third view, the left of the view is missing.
I've struggled with my own code and with this example shown here
GoTo https://github.com/sashamyshkina/scroll-swiftui.git
and try ContentView1
Topic:
UI Frameworks
SubTopic:
SwiftUI
When the Table container is scrolled up the data rows just keep moving up and become unreadable with the column headings superimposed over the top.
Prior to scrolling upwards, the display will look like this.
However, if you start to scroll up
This behaviour does not seem to be the expected behaviour without any modifiers etc.
The following is the code I have been using.
import SwiftUI
struct Customer: Identifiable {
let id = UUID()
let name: String
let email: String
let creationDate: Date
}
struct SwiftyPlaceTable: View {
@State var customers = [Customer(name: "John Smith",
email: "john.smith@example.com",
creationDate: Date() + 100),
Customer(name: "Jane Doe",
email: "jane.doe@example.com",
creationDate: Date() - 3000),
Customer(name: "Bob Johnson",
email: "bob.johnson@example.com",
creationDate: Date())]
var body: some View {
Table(customers) {
TableColumn("name", value: \.name)
TableColumn("email", value: \.email)
TableColumn("joined at") { customer in
Text(customer.creationDate, style: .date)
}
}
}
}
#Preview {
SwiftyPlaceTable()
}
Topic:
UI Frameworks
SubTopic:
SwiftUI