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
15
votes
2 answers

Do import statements in Swift have an associated cost?

Reading the String Manifesto, I saw a paragraph about avoiding the Foundation import when not necessary. Why is this a concern to the Swift team? Apart from aesthetics and code tidiness, do imports come with a cost? Could importing unnecessary…
Ferdz
  • 1,182
  • 1
  • 13
  • 31
15
votes
1 answer

KVObserving a protocol in Swift 4

I am struggling to use the new strongly-typed KVO syntax in Swift 4 to observe properties that are only visible through a protocol: import Cocoa @objc protocol Observable: class { var bar: Int { get } } @objc class Foo: NSObject, Observable { …
proxi
  • 1,243
  • 10
  • 18
15
votes
2 answers

Binary operator '+' cannot be applied to operands of type 'DispatchTime' and 'Int32'

I'm trying to set a variable time delay for a timer in Swift4, but when I put in the variable I get the error: Binary operator '+' cannot be applied to operands of type 'DispatchTime' and 'Int32' I used the code: let when = (DispatchTime.now() + (5…
Matthew N
  • 359
  • 4
  • 14
15
votes
1 answer

Swift 4: Cannot convert value of type '(_) -> ()' to expected argument type '() -> ()' or Argument passed to call that takes no arguments

Using XCode 9, Beta 3. Swift 4. statsView.createButton("Button name") { [weak self] Void in //stuff stuff self?.doSomething() } I get hundreds of errors like this, how do I fix them? Errors: Cannot convert value of type '(_) -> ()' to…
Esqarrouth
  • 38,543
  • 21
  • 161
  • 168
15
votes
5 answers

Convert received Int to Bool decoding JSON using Codable

I have structure like this: struct JSONModelSettings { let patientID : String let therapistID : String var isEnabled : Bool enum CodingKeys: String, CodingKey { case settings // The top level "settings" key } // The…
Hondus
  • 292
  • 1
  • 4
  • 16
14
votes
4 answers

Xcode 11 archive gives PhaseScriptExecution failed

After I migrate my project from swift 3.2 to swift 4 in Xcode 10 I try to archive in Xcode 11 and give me this error: PhaseScriptExecution Run\ Script …
Navtti
  • 173
  • 1
  • 7
14
votes
6 answers

'Class' is ambiguous for type lookup in this context

I did a core-data model: class Order: NSManagedObject { ... //code } but when I try to build I get an error: 'Order' is ambiguous for type lookup in this context
Aviram Netanel
  • 12,633
  • 9
  • 45
  • 69
14
votes
3 answers

Binary operator '<' cannot be applied to two 'Int?' operands

Good evening lovely community, this is my first post, please have mercy, if I do something wrong. I know there are some similar questions here, but I doesn't understand it. Maybe I understand, if someone explain it on my code. // these are my two…
MikeJB24
  • 143
  • 1
  • 1
  • 4
14
votes
4 answers

Why does Swift4 cast an array of UIButton! to [UIButton?] type?

I met a strange issue today. Please look at this code: class A { var button1: UIButton! var button2: UIButton! func foo() { let array = [button1, button2] } } Xcode says that array is [UIButton?] type. For some reason…
Kamil Harasimowicz
  • 4,684
  • 5
  • 32
  • 58
14
votes
2 answers

"No targets to convert found" when trying to convert to current Swift syntax

I have searched quite a bit and can't seem to find an answer for this specific problem. I have a project that is a bit older and written in Swift 2. I am trying to convert it to Swift 4, by going to "Edit > Convert > To current Swift Syntax..." It…
vtboyarc
  • 145
  • 2
  • 8
14
votes
2 answers

Accessing fileprivate and private variables in extension and another class using swift 4

I have been going through the recent swift docs and working out on few examples in understanding private and fileprivate keywords in swift4. I am trying to access a fileprivate and private variable in an extension of the same class and another class…
arun_K
  • 313
  • 1
  • 4
  • 12
14
votes
4 answers

Making NSDecimalNumber Codable

Is it possible to extend NSDecimalNumber to conform Encodable & Decodable protocols?
Arda Keskiner
  • 772
  • 7
  • 23
14
votes
1 answer

Compile error in Swift 4 on parameter passing

I used 3rd party library in Xcode 9 Beta 3. And I am getting the following error in the completion call, I am not able to resolve this error: DispatchQueue.main.asyncAfter(deadline: .now() + delay) { self.animationView?.alpha = 0 …
Vidhya Sri
  • 1,773
  • 1
  • 17
  • 46
14
votes
2 answers

Swift 4: How to create a face map with ios11 vision framework from face landmark points

I am using the ios 11 vision framework to yield the face landmark points in real time. I am able to get the face landmark points and overlay the camera layer with the UIBezierPath of the face landmark points. However, I would like to get something…
Ali
  • 1,002
  • 1
  • 11
  • 21
13
votes
5 answers

How to implement Codable while using Realm

Hy I am working on app that uses Realm and Alamofire. I am really happy in using these library in my iOS project. But then I have to post a List of models that contains multiple lists of models. So that is too much deep thing I mean List inside…
A.s.ALI
  • 1,992
  • 3
  • 22
  • 54