Questions tagged [swift3]

Use this tag only for questions directly related to changes in version 3 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 3 is the version of Apple's programming language Swift. It was released on September 13, 2016. The language is open source and available on Github (see ).

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

For more information, please visit Swift's Getting Started page.

18453 questions
88
votes
7 answers

Convert NSDate to String in iOS Swift

I am trying to convert a NSDate to a String and then Change Format. But when I pass NSDate to String it is producing whitespace. let formatter = DateFormatter() let myString = (String(describing: date)) formatter.dateFormat = "yyyy-MM-dd…
Inder_iOS
  • 1,636
  • 1
  • 12
  • 20
87
votes
9 answers

didReceiveRemoteNotification not called, iOS 10

In iOS 9.3, the didReceiveRemoteNotification method gets called on both of the following occasions. 1) When the push notification is received 2) When the user launches the app by tapping on the notification. But on iOS 10, I notice that the…
smartsanja
  • 4,413
  • 9
  • 58
  • 106
84
votes
20 answers

add Shadow on UIView using swift 3

prior swift 3 i was adding shadow in my UIView like this : //toolbar is an UIToolbar (UIView) toolbar.layer.masksToBounds = false toolbar.layer.shadowOffset = CGSize(width: -1, height: 1) toolbar.layer.shadowRadius = 1 toolbar.layer.shadowOpacity =…
remy boys
  • 2,928
  • 5
  • 36
  • 65
83
votes
5 answers

Closure cannot implicitly capture a mutating self parameter

I am using Firebase to observe event and then setting an image inside completion handler FirebaseRef.observeSingleEvent(of: .value, with: { (snapshot) in if let _ = snapshot.value as? NSNull { self.img =…
coding_999
  • 833
  • 1
  • 6
  • 4
82
votes
10 answers

JSONSerialization Invalid type in JSON write (_SwiftValue)

Why does the following code give me the error: Invalid type in JSON write (_SwiftValue). The error is thrown on this line: urlRequest.httpBody = try JSONSerialization.data(withJSONObject: parameters) Full code: let parameters:Parameters =…
jimijon
  • 2,046
  • 1
  • 20
  • 39
80
votes
6 answers

Detect if the application in background or foreground in swift

is there any way to know the state of my application if it is in background mode or in foreground . Thanks
Mohammed Aboelwafa
  • 1,035
  • 1
  • 9
  • 13
76
votes
5 answers

Remove Last Two Characters in a String

Is there a quick way to remove the last two characters in a String in Swift? I see there is a simple way to remove the last character as clearly noted here. Do you know how to remove the last two characters? Thanks!
Ben
  • 3,346
  • 6
  • 32
  • 51
75
votes
22 answers

Failed to load Info.plist from bundle

Cannot run app. Failed to load Info.plist from bundle error occurs. When I CMD+K clean the project, it runs fine. But I have to clean the project every time I make changes and run the app. Following is the screenshot of my podfile:
Chanchal Raj
  • 4,176
  • 4
  • 39
  • 46
75
votes
2 answers

Updating closures to Swift 3 - @escaping

I've updated my code to Xcode 8.0 beta 6 but I got stuck with what seems to be about the new non escaping closure default. In the following code Xcode suggests to add @escaping in front of completion: in the first line of the below code, but that…
nontomatic
  • 2,003
  • 2
  • 24
  • 38
75
votes
6 answers

Accessing code in Swift 3 Error

New in Xcode 8 beta 4, NSError is bridged to the Swift Error protocol type. This affects StoreKit when dealing with failed SKPaymentTransactions. You ought to check to be sure the error didn't occur because the transaction was cancelled to know…
Jordan H
  • 52,571
  • 37
  • 201
  • 351
73
votes
1 answer

Swift 3 incorrect string interpolation with implicitly unwrapped Optionals

Why are implicitly unwrapped optionals not unwrapped when using string interpolation in Swift 3? Example: Running the following code in the playground var str: String! str = "Hello" print("The following should not be printed as an optional:…
Keiwan
  • 8,031
  • 5
  • 36
  • 49
72
votes
13 answers

Swift 3: Array to Dictionary?

I have a large array and need to access it by a key (a lookup) so I need to create Dictionary. Is there a built in function in Swift 3.0 to do so, or do I need to write it myself? First I will need it for a class with key "String" and later on…
Peter71
  • 2,180
  • 4
  • 20
  • 33
72
votes
2 answers

Class PLBuildVersion is implemented in both/Applications

Why am I getting this? objc[3993]: Class PLBuildVersion is implemented in both …
Cristian Siles
  • 783
  • 1
  • 7
  • 13
65
votes
4 answers

Generics in Swift - "Generic parameter 'T' could not be inferred

I'd like to return a UIViewController conforming to MyProtocol from a method, so I'm using the method signature: func myMethod() -> T { First thing I don't understand: if myMethod returns e.g. a…
swalkner
  • 16,679
  • 31
  • 123
  • 210
64
votes
1 answer

Could not load IOSurface for time string. Rendering locally instead swift 4

Could you help me with this problem when I running my project : Could not load IOSurface for time string. Rendering locally instead I don't know what is going on with my codding ..... pleas help .
Mr Ice
  • 690
  • 1
  • 6
  • 9