Questions tagged [swift4]

Use this tag only for questions directly related to changes in version 4 of Apple's Swift programming language. Use the tag [swift] for more general language questions, or the tags [ios], [cocoa], [apple-watch] etc. for questions about developing on Apple platforms.

Swift 4 is the fourth version of the Swift language developed by Apple that was released in 2017. The language is open source and available on Github (see ).

The development of Swift 4 and its goals can be viewed on the Swift Programming Language Evolution repository on GitHub.

5684 questions
2
votes
1 answer

NSKeyValueObservation not working, Swift 4

How should I properly set up to receive notifications when the variable changes on the shared instance of the singleton? Currently, the block is never fired. class MyViewController: UIViewController { private var observer:…
subjective_c
  • 282
  • 2
  • 10
2
votes
0 answers

How to call "editActionsForRowAt" function programmatically in swift4

There is any way to call editActionsForRowAt programmatically in swift3 func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { } This is for:- when user come on that screen than first row…
Bijender Singh Shekhawat
  • 3,934
  • 2
  • 30
  • 36
2
votes
1 answer

How to add ARKit in single view application

I am Using Xcode 9 Beta and Swift 4. Creating a Single View Application. How can I use argument reality feature in my Single Application View? This is my Code. There is no any error in that. but I can't get any result on my scene. import…
Arjun Yadav
  • 1,369
  • 1
  • 10
  • 23
2
votes
2 answers

Face detection swift vision kit

I am trying Vision kit for iOS 11. I can use Vision and I can find boundbox values face. But I don't know how can I draw a rectangle using this points. I hope so my question is clear.
Mayday
  • 121
  • 1
  • 3
  • 9
2
votes
1 answer

#selector not working in Swift 4?

I'm trying to setup a timer in Xcode 9 using Swift 4 and I have a function called: hello. So in the timer code, I added #selector(hello()) like I would before, but this time it would continue to crash and make me add @objc in front of the hello…
Amit Kalra
  • 4,085
  • 6
  • 28
  • 44
2
votes
2 answers

How to make SCNNode rotate/spin horizontally

I'm trying to make my SCNNode automatically rotate horizontally by itself. This is the code I have so far: box.scale = SCNVector3(x: 0.26, y: 0.26, z: 0.26) box.position = SCNVector3(0.15, 3.85, -3) How do I make this box spin horizontally…
Amit Kalra
  • 4,085
  • 6
  • 28
  • 44
2
votes
1 answer

Swift 4 custom generic struct with optional array behaves strange?

I'm migrating a larger codebase to Swift 4. It includes a custom type that implements a matrix. In Swift 3.1 everything works well and as expected. I was able to reduce the problem to two small code blocks. The first one defines the struct: struct…
Klaas
  • 22,394
  • 11
  • 96
  • 107
2
votes
1 answer

Insert a number into a UiTextView and detect the number

I have a UITextView that contains a lot of text with a number at the end. I am trying to detect the number in the text view but unable to achieve that. I can only find the solution to find the link only. I am using NSAttributedString to display the…
Jivan Bhandari
  • 860
  • 1
  • 10
  • 32
2
votes
2 answers

MKPolyLine Swift 4

I am trying to learn MapKit and add some MKPolyLine as an overlay. Couple of questions: What is the difference between MKPolyLine and MKPolyLineView. Which one should be used when? For the MKPolyLine init method one of the parameter is a generic…
user2511882
  • 9,022
  • 10
  • 51
  • 59
2
votes
1 answer

Swift return associated enum value or nil in one line

Case statements are not always intuitive, especially outside of switch statements. Is it possible to return the associated value of an enum case only if that case matches, otherwise nil, in one line. Here's the code: struct Something { enum…
David James
  • 2,430
  • 1
  • 26
  • 35
2
votes
1 answer

Swift 4 : Cannot call value of non-function type '[Self.Element.Type]' when instantiating associated type array

I was doing some exercises on Xcode 9 beta 2 Swift 4 from this article (https://www.uraimo.com/2016/01/06/10-Swift-One-Liners-To-Impress-Your-Friends/) when I came across an error while doing item no. 6: extension Sequence{ typealias Element =…
mj_jimenez
  • 443
  • 2
  • 5
2
votes
1 answer

UISegmentedControl with multiple strings in each segmented index

I am trying to show 2 strings of text in each segmented index instead of one long text. Currently the view looks like this I want another string below "Repeat task" and "One time task" as marked by the red line in the image. Currently my model is…
Nasim Rony
  • 519
  • 5
  • 22
2
votes
3 answers

How do you get text length in Swift 4?

I am not sure how to update this code: func textWidth(text: String, font: UIFont?) -> CGFloat { let attributes = font?.fontDescriptor.fontAttributes return text.size(withAttributes: attributes).width } Swift 4 complain: Cannot convert…
MarkAurelius
  • 1,203
  • 1
  • 14
  • 27
2
votes
1 answer

Decoding a struct using a key from JSON swift4

Using Swift 4's Encoder & Decoder protocol and JSONDecoder how do I initialize a struct of type Codeable using a key from a given JSON. i.e. Given the JSON below I wish to only use results to initialize Example { "boolean": true, "number": 123, …
kye
  • 2,166
  • 3
  • 27
  • 41
2
votes
1 answer

Binding 2 properties (observe) using keyPath

I am trying to create a routine to simplify binding one property to another, a very common operation. I'm using the block based KVO's in Swift 4 and XCode 9. I want to be able to write the following to bind two variables using their corresponding…
Jim Leask
  • 6,159
  • 5
  • 21
  • 31