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

hide status bar swift 4

I am trying to hide status bar in one of my UIViewControllers (Swift 4). Firstly, I set View controller-based status bar appearance to YES in Info.plist. I overrode the prefersStatusBarHidden property in my controller: override var…
Dragisa Dragisic
  • 731
  • 2
  • 9
  • 19
21
votes
1 answer

#if canImport(module) still does not solve conditional import statement in Swift 4.1?

My App supports from version iOS 9. One of the frameworks that I am adding Icecream framework to sync realm objects needs iOS 10 or greater. How to make the import of the framework conditional? I have tried making the IceCream framework as optional…
Imran
  • 769
  • 1
  • 9
  • 21
21
votes
1 answer

Swift how to check if API is NOT available

I am applying corner radius to only top left and top right of a view. In viewDidLoad() I have: if #available(iOS 11.0, *) { view.layer.cornerRadius = 20.0 view.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] } If iOS 11…
Jack Guo
  • 3,959
  • 8
  • 39
  • 60
21
votes
3 answers

AudioHardware.cpp:1200:AudioObjectRemovePropertyListener: AudioObjectRemovePropertyListener: no object with given ID 0

Working on a project in swift, where I'm trying to initiate the AVPlayer, and for some reason it trows me an exception saying AudioHardware.cpp:1200:AudioObjectRemovePropertyListener: AudioObjectRemovePropertyListener: no object with given ID 0.…
danu
  • 1,079
  • 5
  • 16
  • 48
21
votes
3 answers

Get all key paths from a struct in Swift 4

Let's say I have that struct: struct MyStruct { let x: Bool let y: Bool } In Swift 4 we can now access it's properties with the myStruct[keyPath: \MyStruct.x] interface. What I need is a way to access all it's key paths, something…
Rodrigo Ruiz
  • 4,248
  • 6
  • 43
  • 75
21
votes
3 answers

Cannot convert value of type '[String : AnyObject]?' to expected argument type '[NSAttributedStringKey : Any]?'

How to convert values of type '[String : AnyObject]?'to expected argument type '[NSAttributedStringKey : Any]?'? open class func drawText(context: CGContext, text: String, point: CGPoint, align: NSTextAlignment, attributes: [String :…
Fawwad Ahmed
  • 234
  • 1
  • 4
  • 12
21
votes
2 answers

Swift 4 - How to convert Json to swift Object automatically like Gson in java

I am new in Swift 4 and trying to figure out How to convert Json to swift Object automatically like Gson in java. Is there is any plugin i can use which can convert my json to object and vice versa. I have tried to use SwiftyJson Library but couldnt…
user6457240
20
votes
1 answer

Swift Codable expected to decode Dictionarybut found a string/data instead

I have been working with the Codable protocol Here is my JSON file : { "Adress":[ ], "Object":[ { "next-date":"2017-10-30T11:00:00Z", "text-sample":"Some text", "image-path":[ …
user7219266
20
votes
3 answers

Cocoa App webview not loading request

I have used webview to load url but it is not loaded. i have tried the same with wkwebview but couldn't load url. I have done following import WebKit Info.plist Allow Arbitrary Loads - YES Allow Arbitrary Loads in Web Content - YES LOG:…
Rakshit Korat
  • 1,159
  • 10
  • 23
20
votes
6 answers

How to get substring with specific ranges in Swift 4?

This is using the example code from the official Swift4 doc let greeting = "Hi there! It's nice to meet you! " let endOfSentence = greeting.index(of: "!")! let firstSentence = greeting[...endOfSentence] // firstSentence == "Hi there!" But lets say…
Kent Wong
  • 566
  • 1
  • 6
  • 20
20
votes
0 answers

Losing precision when passing numbers through the JSONDecoder in Swift 4

I'm sending some JSON data to our server and in the process having issues when encoding certain values with the new Swift 4 JSONDecoder. Take this playground example: import Foundation struct QuantyTest: Codable { var name: String var…
David Wood
  • 1,319
  • 2
  • 12
  • 15
20
votes
3 answers

How to fix "'@IBInspectable' attribute is meaningless on a property that cannot be represented in Objective-C" warning

In Xcode 9 and Swift 4 I always get this warning for some IBInspectable properties: @IBDesignable public class CircularIndicator: UIView { // this has a warning @IBInspectable var backgroundIndicatorLineWidth: CGFloat? { // <--…
Adrian
  • 19,440
  • 34
  • 112
  • 219
19
votes
2 answers

What is the most recent correct syntax to initialize the Google Mobile Ads SDK in the App Delegate file?

All of a sudden, I get a warning on the code used to initialize the Google Mobile Ads SDK. (It had been working for weeks before with no warning, but now it seems there's a new way to write the code.) This is the code I…
Derence
  • 408
  • 5
  • 18
19
votes
2 answers

Printing DecodingError details on decode failed in Swift

I'm starting to rewrite an application and I want to use Swift 4 Codable protocol to automatically convert json string to Objects and Structs. Sometimes, specially at the beginning of coding, I encountered decoding problems, so I want to print these…
smukamuka
  • 1,442
  • 1
  • 15
  • 23
19
votes
1 answer

does not conform to protocol Decodable / Codable

I'm using the following struct: struct Item : Codable { var category:String var birthDate:Date var switch:Bool var weightNew: [Weight] var weightOld: Array var createdAt:Date var itemIdentifier:UUID var…
arakweker
  • 1,535
  • 4
  • 18
  • 40