Hello,
I'm using PaintCode for UIGraphics which exports Swift files with an @objc dynamic public class func nested in a NSObject class. With older versions of Swift, could be implemented with the use of a UIKit view and the storyboard.
How could I do this with SwiftUI?
Thanks in advance.
Post
Replies
Boosts
Views
Activity
Hello,
I'm having issues with Safari's inspect element. Some of the elements on a webpage I'm working on aren't showing up, however they are present under the Sources tab. I'm not sure why that is. Any help would be greatly appreciated.
Thank you
Update: I made a coding error, it had nothing to do with web inspector.
Hello,
I noticed there's a glitch with inspect element. Under elements, when I try to uncheck a style property, the whole element's CSS gets removed, sometime's the whole webpage's. I was wondering if there was anything I could do to fix this issue.
Thanks
Hello,
I'm having trouble previewing a view that has a binding variable. When it's in the below state, I get the error "Edit placeholder in source file":
static var previews: some View {
Navigation(viewState: Binding<String>)
}
}
When I put a string as a placeholder, I get the error: Cannot convert value of type 'String' to expected argument type 'Binding'
static var previews: some View {
Navigation(viewState: "sign-in")
}
}
The code for the supporting view with the binding variable is below:
struct Navigation: View {
@Binding var viewState: String
var body: some View {
ZStack {
HStack {
Spacer()
Button(action: { toggleView(view: "savings")}) {
Text("Savings")
}
Spacer()
Button(action: { toggleView(view: "settings")}) {
Text("Settings")
}
Spacer()
}
}
.position(x: UIScreen.main.bounds.width / 2, y: UIScreen.main.bounds.height / 2)
.frame(width: UIScreen.main.bounds.width, height: 100)
}
func toggleView(view: String) {
viewState = view
}
}
Any help would be greatly appreciated.
Hello,
I'm trying to build a simple button. For some reason, I'm getting the following errors:
Cannot convert value of type '() -> ()' to expected argument type 'String'
Incorrect argument label in call (have 'action:_:', expected 'value:selected:')
Button(action: login) {
ZStack {
RoundedRectangle(cornerRadius: 5)
.fill(Color.black)
.frame(width: UIScreen.main.bounds.width - 50, height: 50)
Text("Sign in")
.foregroundColor(.white)
}
}
All of my buttons in this particular project suddenly have this error. Any help would be greatly appreciated.
Thank you
Hello,
I was following a tutorial on how to use the SwiftUI Canvas and I can't seem to get it to work. Below is the code that I have.
struct Line {
var points: [CGPoint]
var color: Color
}
struct CanvasView: View {
@State var lines: [Line] = []
@State var selectedColor: Color = Color.black
var body: some View {
ScrollView([.horizontal, .vertical]) {
Canvas { ctx, size in
for line in lines {
var path = Path()
path.addLines(line.points)
ctx.stroke(path, with: .color(line.color), style: StrokeStyle(lineWidth: 5, lineCap: .round, lineJoin: .round))
}
}.gesture(DragGesture(minimumDistance: 0, coordinateSpace: .local)
.onChanged({ value in
let position = value.location
if value.translation == .zero {
lines.append(Line(points: [position], color: selectedColor))
} else {
guard let lastIndex = lines.indices.last else {
return
}
lines[lastIndex].points.append(position)
}
})
)
}
}
}
I'm pretty sure I followed the tutorial exactly so I'm not sure why it isn't drawing. Any help would be greatly appreciated. Thank you.
Hello,
I am trying to use the SwiftUI canvas and I'm having a couple of issues. One is that I'd like to be able to fit a canvas view in a ScrollView, but when the canvas is inside a ScrolLView, nothing draws. Additionally, I'm trying to draw lines on the canvas on Appear, but I can't seem to get that to work either. Below is a simplified version of the code I have:
struct Line: Codable, Hashable {
var points: [CGPoint]
var colorName: String?
var rgb: [Double]?
private enum CodingKeys: String, CodingKey {
case points
case colorName
case rgb
}
}
extension CGPoint: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(x)
hasher.combine(y)
}
}
struct CanvasExample: View {
@State var lines: [Line] = []
@State var selectedColor: Color = Color.black
var body: some View {
Canvas { ctx, size in
for line in lines {
var path = Path()
path.addLines(line.points)
ctx.stroke(path, with: .color(line.color), style: StrokeStyle(lineWidth: 5, lineCap: .round, lineJoin: .round))
}
}.gesture(DragGesture(minimumDistance: 0, coordinateSpace: .local)
.onChanged({ value in
let position = value.location
if value.translation == .zero {
lines.append(Line(points: [position], color: selectedColor))
} else {
guard let lastIndex = lines.indices.last else {
return
}
lines[lastIndex].points.append(position)
}
})
)
.onAppear {
lines.append(Line(points: [position], color: .black))
}
}
}
Any help would be greatly appreciated. Thank you.
Hi,
I am inquiring in regard to how to handle data from a bluetooth device. The device would send data in JSON format to a Mac via bluetooth, and I would need to constantly refresh or fetch data from the device in real time.
How would I go about this? Any help would be greatly appreciated.
Thank you.
Hello,
I'm inquiring in regard to information on handling user's subscriptions, specifically if it's possible to cancel a subscription with a line of code. For example:
if condition {
// cancel user's subscription
}
I'm not familiar with the App Store Server API yet, but I glanced at the documentation and I didn't see any information in regard to the question I have. That being said, I'm also wondering where to start with configuring a subscription model for my app.
Any insights would be greatly appreciated. Thank you.
Hi,
I have a view that takes an optional binding boolean variable. I'd like to pass a variable to it from certain views only. The problem I'm having is when I pass a variable, I get the error "Cannot convert value of type 'Binding' to expected argument type 'Binding<Bool?>'", and when I don't, I get the error "Missing argument for parameter 'toggle' in call". Below Is the code I have. Thank you.
Heading(text: "Heading1") // error: Missing argument for parameter 'toggle' in call
Heading(text: "Heading2", toggle: $newEntry) // Cannot convert value of type 'Binding<Bool>' to expected argument type 'Binding<Bool?>'
struct Heading: View {
@State var text: String
@Binding var toggle: Bool?
var body: some View {
VStack {
Spacer()
.frame(height: 25)
HStack {
Text(text)
.font(.system(size: 36))
Spacer()
if text == "str" {
Button(action: { toggle!.toggle() }) {
Image(systemName: "plus")
.foregroundColor(.black)
.font(.system(size: 36))
}
}
}
Spacer()
.frame(height: 25)
}
}
}
Hi,
I'm inquiring in regards to the feasibility or possibility of making a connection from iPhone to another, such that one iPhone uses Apple wallet, and another iPhone would detect for the signal within the app. Please let me know if this is feasible or if any more information would be necessary to assist. If this is possible, what documentation would be relevant?
Thank you.
Hi,
I have a button view that is used in many different ways in an app that I'm working on. One of the ways it is used is in an account creation form. Since the button is in a child view, the action: { } button function isn't available in the view where the input field variables are. I could import the class with the function to the button view but I don't want to pass the input field variables into the button view. I tried binding a boolean variable to the button view and checked for it's state change in the parent view using .onChange(), but the use case for that I found was depreciated and I'm unable to revert the state of the variable in the .onChange function.
To reiterate, in a main view, I need to call a function in a given class and pass variables to it, upon a button being pressed in a child view. Any help would be greatly appreciated.
Hi,
I have a struct that I'd like to encode with JSON and send in the body of an HTTP request:
struct AccountCreationData: Codable, Hashable {
var name: String
var email: String
var phone: String
var password: String
private enum CodingKeys: String, CodingKey {
case name
case email
case phone
case password
}
}
I encode it with this code and set the HTTP request body to the encoded data:
guard let encoded = try? JSONEncoder().encode(account) else {
print("Failed to encode request")
return
}
request.httpBody = encoded
But in my backend, when I receive the data from the HTTP request, the JSON data is formatted as such:
'{"phone":"0000000000",
"password":"password",
"email":"email",",
"name":"name"}': ''}
Instead of:
{
"phone": "0000000000",
"password":"password"
"email":"email"
"name":"name"
}
So the JSON parser in my backend isn't properly parsing the data because of the format that the JSON is in. I was wondering if this is an issue with the way I'm encoding on the front end (Swift) or my backend. I have similar projects using the same code to encode the data so I'm unsure as to what the issue is. Any help would be greatly appreciated. Thank you.
I one project, using .onChange(), I get an error: 'onChange(of:initial:_:)' is only available in iOS 17.0 or newer
The solution provided is to wrap the code in if #available(iOS 17.0, *) { }, but I'm only able to wrap the whole view inside of it, like so:
if #available(iOS 17.0, *) {
VStack () {
// view with .onChange
}
} else {
VStack () {
// view with older solution
}
}
The view is quite lengthy so it would be very redundant to have the same view twice, (the same view for each component of the if/else statement). Is there a way to implement an if statement so that I would only need the code for the view once (something like the code below)?
VStack {
}
if #available(iOS 17.0, *) {
.onChange() {
}
} else {
// older solution
}
Additionally, in a newer project, I don't have to include the if #available(iOS 17.0, *) { }, so I'm guessing the build is made for a newer iOS. If that's the case, would it not be compatible with older iOS versions? Any help would be greatly appreciated.
Hi,
I was searching and replacing code where all of the sudden I got the following errors:
Undefined symbol: AppName.Client.init(id: Swift.Int, name: Swift.String, StructVariable: Swift.Int?, structVariable: [Struct]?) -> AppNameStruct
Linker command failed with exit code 1 (use -v to see invocation)
I replaced the names in the first error message for privacy reasons.
I tried quitting Xcode and restarting my computer but the error persisted. Any help on resolving this would be greatly appreciated.