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
6 answers

How to allow only certain set of numbers in a UITextfield in swift 2.0

I am having a UITextField in which i get the month number as input. I am successful in limiting the no of characters to 2 in the UITextField. But i want users to enter only the values from 1 to 12 and none other than that. This has to be done…
Kautham Krishna
  • 967
  • 1
  • 14
  • 33
3
votes
3 answers

Cannot convert value of type() to closure result type NSDictionary in Swift 2

I have to return a value of this function.I am getting error in this line func GetStation(url : String, completionHandler: (stationDictionary: NSDictionary) -> ()) { getResonse(url, completionhandler: { (dict) -> NSDictionary in …
Chaman sharma
  • 41
  • 1
  • 2
  • 8
3
votes
2 answers

Can I trigger a compiler warning when there is an implicitly captured "self" in Swift

If I have some code that takes a closure, and self is implicitly captured, can I make it cause a compiler warning? Is there some flag I can add to the compiler command for this?
user3352495
  • 374
  • 3
  • 11
3
votes
2 answers

Cast Protocol<> Any to String (or others)

I have a class called User() class User { var name: String? var email: String? var id: String? var identification_number: String? var phone_number: NSMutableArray? var user_group: String? var date: NSDate? } I want…
munfai
  • 83
  • 9
3
votes
1 answer

Accessing DOM element in WKwebView

In swift 2.1, Xcode7.1.1 My code loads a local index.html into a WKwebView. How can I have a reference to the textFields so that I can set some of their properties? like myWebViewTextField.userInteractionEnabled = false or myWebViewTextField.enabled…
Fred J.
  • 5,759
  • 10
  • 57
  • 106
3
votes
1 answer

Moving a button in swift using animate with duration with constraints and detecting a touch during it

I want to move a button from point A to point B. Point A: leadingConstraint = 120, topConstraint = 400. Point B: leadingConstraint = 120, topConstraint = 200. For my game purpose, I can't use frames. I also want to be able to detect a touch on it…
Anton O.
  • 653
  • 7
  • 27
3
votes
1 answer

Why don't I get the result of this Metal kernel

I am trying to understand how Metal compute shaders work, so I have wrote this code : class AppDelegate: NSObject, NSApplicationDelegate { var number:Float! var buffer:MTLBuffer! func applicationDidFinishLaunching(aNotification:…
Pop Flamingo
  • 3,023
  • 2
  • 26
  • 64
3
votes
1 answer

Extension doesn't go in derived class in swift

I am implementing a protocol and providing some optional methods in swift but then I am implement these optional methods in derived class. When I call a protocol method it is calling extension method not the derived class method. protocol ProtocolA…
sohail.hussain.dyn
  • 1,411
  • 1
  • 16
  • 26
3
votes
1 answer

Alternative for Multipeer-connectivity tvOS swift

I have been looking around trying to figure out how crossy road developers and beat sports developers have made their remote controller "add-on." First I thought Multipeer-connectivity, but after trying to test it on the Apple TV realized the…
Zander
  • 414
  • 2
  • 16
3
votes
2 answers

Receive Custom Notification iOS swift 2.0

I tried to receive my custom notification from my web through parse website. Code didReceiveRemoteNotification : func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { …
Steven tan
  • 139
  • 1
  • 1
  • 12
3
votes
1 answer

How Can I Pass the Value of A Textfield to a Button Clicked Function in Swift?

I need to preform username and login checks upon pressing the login button. I need to do all of this without storyboards. However, my problem is that when I create a button that connects to a function, the textfields are then out of scope. …
DMop
  • 463
  • 8
  • 23
3
votes
1 answer

Swift 2: How to keep iOS and watchOS2 apps synchronized with WatchConnectivity?

I made a Counting App on iOS and WatchOS, and I want apps to be synchronized. When I count on WatchOS the number on label of iOS have to be same as on WatchOS and when I count on iOS the number on label of WatchOS have to be same as one iOS. One of…
user5537162
3
votes
1 answer

How to create a wave path Swift

I want my node to travel in a sine curve wave, and I tried using that for CGPath. How do I create a CGPath that follows a sine curve? Is there any way other than to manually find the points on the curve, or could I just pass in a sine function? let…
Dieblitzen
  • 544
  • 4
  • 22
3
votes
1 answer

How to convert bytes to NSString after AES CryptoSwift cipher

I am using CryptoSwift to encrypt data I will be passing in a URL. To do this, I need the datatype of the piece of data to be a String to concatenate into the NSURL request. After encrypting the data it is output in bytes. How can I cast the bytes…
iamnickpitoniak
  • 227
  • 1
  • 4
  • 11
3
votes
2 answers

Show Admob Interstitial ads between scenes in Swift SpriteKit

I would like to know how to set up Admob Interstitial ads when I present my GameOverScene. What should I do to show the ads only sometimes when the game gets over? And how do I implement this in Swift? Im referring to this post How to call admob…
Dieblitzen
  • 544
  • 4
  • 22
1 2 3
99
100