Post

Replies

Boosts

Views

Activity

Reply to Unable to extract substring from larger mutli-line string
@OOper not sure if you have some experience with ARKit, but now I am trying to take the rating and display it on the user's camera. I know how to display simple text on the user's screen, but for some reason I'm getting an error when running this code: override func viewDidLoad() { 				super.viewDidLoad() 				// Set the view's delegate 				sceneView.delegate = self 				configure() 				configureOCR() 				let text = SCNText(string: ocrTextView, extrusionDepth: 2) 				let material = SCNMaterial() 				material.diffuse.contents = UIColor.magenta 				text.materials = [material] 				let node = SCNNode() 				node.position = SCNVector3(x:0, y:0.02, z:-0.1) 				node.scale = SCNVector3(x:0.01, y:0.01, z:0.01) 				node.geometry = text 				sceneView.scene.rootNode.addChildNode(node) 				sceneView.autoenablesDefaultLighting = true 		} When I run it, it crashes and gives an exception: Thread 1: Exception: "-[UITextInputTraits length]: unrecognized selector sent to instance 0x1035332b0"
Jul ’20
Reply to Unable to extract substring from larger mutli-line string
@OOPer I got a part solution here: URLSession.shared.dataTask(with: url) { data, response, error in 										guard let data = data else { 												print(error ?? "") 												return 										} 										html = String(data: data, encoding: .utf8)! 										let pattern = #"(\d.\d) out of 5 stars"										if let range = html.range(of: pattern, options: .regularExpression) { 												let rating = html[range].prefix(3) 												ocrText = ocrText + rating 												print("testing", ocrText) //prints with rating 										} 										 								}.resume() 								 								print("LATER:", ocrText) //doesn't print with rating 								 								 								 								 								 								DispatchQueue.main.async { 										self.ocrTextView.text = ocrText 										self.scanButton.isEnabled = true 								} It is correctly getting the number of stars, but the problem is that I have a text view (as you can see in the above code) which I set equal to the string ocrText. However, I put two print statements: one inside the URLSession method and one outside the URLSessionMethod. I am trying to get the rating into the string ocrText, which works in the print statement in the URLSession method but not outside this method. How can I fix this? BTW all the above code is in a seprate function and then I call this function in the viewDidLoad method. edit: do you want the full code in the viewcontroller.swift ? its pretty long and i think there's a character limit for a post
Jul ’20
Reply to Unable to extract substring from larger mutli-line string
@OOper As you would probably expect, the HTML is really long so I'll just include a snippet of the HTML which contains the rating: </h2> <div class="a-row a-size-small a-color-secondary"><span class="a-size-small" dir="auto">by </span><span class="a-size-small" dir="auto">John Bolton</span></div> 										</div> 										 												<div class="a-section a-spacing-none a-spacing-top-mini"> 														<div class="a-row a-size-small"> <span aria-label="3.1 out of 5 stars"> 		 <i class="a-icon a-icon-star-small a-star-small-3 aok-align-bottom"><span class="a-icon-alt">3.1 out of 5 stars</span></i> </span> Also html is a string. @Claude I am searching for "stars"
Jun ’20