Questions tagged [swift2]

Use this tag only for questions directly related to changes in version 2.x 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 2 is the newest major version of the Swift programming language by Apple.

This version of Swift adds syntax improvements such as the new keywords guard and defer, and also adds error handling with do-catch statements and the try keyword. and Mutability warnings in Swift 2, you'll get warnings in your code whenever you declare variables that never change as constants (using let) rather than variables (using var).

It was made open source on December 3rd of 2015. The source code can be found on github.

Swift was introduced at Apple's 2014 Worldwide Developers Conference (WWDC). It underwent an upgrade to version 1.2 during 2014 and a more major upgrade to Swift 2 at WWDC 2015. Initially a proprietary language, version 2.2 was made open source and made available under the Apache License 2.0 on December 3, 2015, for Apple's platforms and Linux IBM announced its Swift Sandbox website, which allows developers to write Swift code in one pane and display output in another.

The stable Swift version is Swift 2.2.1 which was released on May 3 2016.

As a result of cooperation with Apple, there is an IBM Swift Sandbox for latest Swift syntax.

8879 questions
3
votes
1 answer

Swift Function call list incorrect parameter type

I define the below list swift class, and try to call the sfAuthenticateUser from the viewcontroller. But the Xcode intellisense list the wrong parameter type other than the type i defined. ERROR : Cannot convert value of type 'String' to expected…
Chamath Jeevan
  • 5,072
  • 1
  • 24
  • 27
3
votes
1 answer

Ambiguous use of "init" with optional arguments in Swift 2

I've just updated my code from Swift 1.2 to Swift 2.1. The project was fully-functioning with previous version of Swift, but now I'm seeing "Ambiguous use of 'init'" errors. Each occurrence of this error seems to be caused by the use of optional…
Alexander Tsepkov
  • 3,946
  • 3
  • 35
  • 59
3
votes
1 answer

Swift. Can`t save file to DocumentDirectory. Whats wrong?

Here`s my code: let fileName = "someFileName" func saveDataToFile(urlStr:String){ let url = NSURL(string: urlStr) var data:NSData! let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory,…
Elena
  • 829
  • 8
  • 20
3
votes
1 answer

Kerning on a UIBarButtonItem with Swift

I have a UIBarButtonItem that I would like to the content text Kerned. (I am setting the bar button item the same as the following: Add NSAttributedString to UIBarButtonItem) Using that, in the attributes array, I add NSKernAttributeName but it…
daredevil1234
  • 1,303
  • 1
  • 10
  • 34
3
votes
2 answers

CoreMotion authorization problems

I am currently developing an app that will use a combination of three libraries: CoreLocation, CoreMotion and Healthkit. My issue is that when I initialize CoreLocation and Healthkit, I get the the dialog to allow authorization. However, with…
Villainsoft
  • 137
  • 7
3
votes
3 answers

Generic Parameter 'Key' could not be inferred Swift 2

I am beginner in swift 2 and I not find the problem. the error is in this line: let jsonDictionary try NSJSONSerialization.JSONObjectWithData = (data!, options: NSJSONReadingOptions.MutableContainers) as! Dictionary func searchItunesFor(searchTerm:…
3
votes
3 answers

How to prevent an animation from completing when user leaves and returns to app

I am making an app where I have a button who is moving from one side of the screen to the other. I have created a pause button which pauses the animation once that button is selected. This button and function works fine. I also added a function…
Anton O.
  • 653
  • 7
  • 27
3
votes
2 answers

Swift chained assignment through computed property or subscript: Where is this documented?

I was surprised to find that assigning a member of a value type through either a subscript operation or computed property in Swift worked as one would expect for a reference type: e.g. I really expected myArrayOfValueType[0].someField = value would…
Pat Niemeyer
  • 5,930
  • 1
  • 31
  • 35
3
votes
4 answers

How do i get firstname and givenname from Google Login?

I followed the instructions on https://developers.google.com/identity/sign-in/ios/sdk/ to integrate the google login in my swift project. As you might know the login calls the function below when successful. It gets called but i cannot figure out…
Philip
  • 171
  • 1
  • 3
  • 11
3
votes
2 answers

Protocol conforming

I am experimenting some swift features.( Collection protocols). I would like to implement a structure that implements CollectionType. My code : struct Book { let id : String let name : String init(id: String, name: String) { …
samir
  • 4,501
  • 6
  • 49
  • 76
3
votes
1 answer

Disable cut, copy, paste on UITextField using IBInspectable

Please find the following code which did not work for me. @IBInspectable var pasteOption: Bool = true { didSet { func canPerformAction(action: Selector, withSender sender: AnyObject) -> Bool { if action ==…
Janak Thakkar
  • 414
  • 5
  • 20
3
votes
2 answers

Swift 2, method 'setOn' with Objective-C selector 'setOn:' conflicts with setter for 'on' with the same Objective-C selector

Swift 2, I have a class inherits from objc's UIView and it has 'on' variable, and related methods 'setOn:animated' and 'setOn:' like below: public class AView: UIView { var on: Bool = false public func setOn(on: Bool, animated: Bool) { self.on…
ccoroom
  • 699
  • 9
  • 23
3
votes
2 answers

Swift 2 - Merge two arrays

I am trying to merge two array: array 1 [["aaa","111"],["bbb","222"],["ccc","333"]] array 2 [["ddd","444"],["eee","555"],["fff","666"]] What I want to achieve is to have a single array with the values respecting the array positions such as: merged…
SNos
  • 3,430
  • 5
  • 42
  • 92
3
votes
0 answers

Swift Protocols and Extensions

Attempting do something similar to an abstract class in swift using protocols and extensions to better organize a pluggable class so that it can be swapped out manually if needed, for example a different map api. The issue is once I add the protocol…
kdgwill
  • 2,129
  • 4
  • 29
  • 46
3
votes
1 answer

core data: save different types as the same attribute

I have a core data entity which has an attribute that can represent different types of values (int, double, date, string). Would it lead to problems (e.g. loss of precision) somewhere down to line if I convert all these values to a String and then…
user965972
  • 2,489
  • 2
  • 23
  • 39
1 2 3
99
100