Tag: swift2

How can we use HTTP and HTTPS both ATS (App Transport Security) in One Application?

Apple announced “App Transport Security” for iOS 9 and OSX 10.11 El Capitan. The “What’s New in iOS” guide for iOS 9 explains: App Transport Security (ATS) lets an app add a declaration to its Info.plist file that specifies the domains with which it needs secure communication. ATS prevents accidental disclosure, provides secure default behavior, […]

How to use swift files in objective c

I want to use my Swift files in Objective-C code. I found different link that say how to do it. My project name is: Test-Project. I imported #import “Test-Project-Swift.h” to my .m file to use needed classed in objective c source code. I watched this video and there is no problem, but I have ‘Test-Project-Swift.h’ […]

Selecting the text just updated with replaceRange(range: UITextRange, withText: String)

I’m changing the content of a UITextView with the following code: mainTextField.replaceRange((theRange), withText: newStr) Then I would like to select the new text. I’m trying to use the following code: mainTextField.becomeFirstResponder() let startPosition = mainTextField.positionFromPosition(mainTextField.beginningOfDocument, inDirection: UITextLayoutDirection.Right, offset: startingPoint) let endPosition = mainTextField.positionFromPosition(mainTextField.beginningOfDocument, inDirection: UITextLayoutDirection.Right, offset: endingPoint) if startPosition != nil && endPosition != nil […]

<unknown>:0: error: type 'Key' constrained to non-protocol type 'String'

Migrating to Swift 3 from 2.3 and am running into this issue. The error is traceable to a view controller. I do not see any extensions/protocols which would require a ‘Key’ constrained to ‘String’. I’ve tried to comment out code that might be causing the error, and have had strange results – ie removing an […]

Making table view section expand swift

I am following this tutorial for expanding and collapsing my table view section. As this demo is done in swift 2.2 I have made all the changes according to swift 3.0 . I am stuck at the below function at if condition(currentSectionCells[row][“isVisible”]) which gives me error as “Type ‘NSFastEnumerationIterator.Element’ (aka ‘Any’ has no subscript members)’”. […]

Create UITextField Extension in Swift with custom styling

I have several UITextFields on the view that have to look the same. I figured out that I might create an Extension that will pre-style my text fields (those that I want to have the same style). let passTextField: UITextField = { let tf = UITextField() //tf.backgroundColor = UIColor.blueColor() tf.translatesAutoresizingMaskIntoConstraints = false tf.layer.cornerRadius = 25 […]

Type variable in protocol – Swift 2

So I have a protocol, and in it I want a variable that is a class type. That way I can init that class from the variable. Keep in mind that there will be many different classes. I made a quick example. I get the error “type ‘CashRegister’ does not conform to protocol ‘RegisterProtocol’” This […]

Printing each array item in Xcode Playground?

When looping through an array and printing each item in the Playground, the output is (x times). Where x is the count. Rather than the count, is there a way to make the Playground output each item?

Error when setting up google analytics in swift 2 and xcode 7 beta 4

I set up my xcode project wit cocoapods, added google analytics as pod. Afterwards I imported the GoogleService-info.plist directly below my project file. Bridge header is also created, and code added in the AppdDelegate. During compilation, everything runs fine, but when I start the debugger, I receive those errors: 2015-08-14 16:45:25.866 GetOut[30738:3729265] Client ID must […]

SpriteKit PhysicsBody non-rectangular collision

pipeUp.physicsBody = SKPhysicsBody(rectangleOfSize: pipeUp.size) in this coding I used the rectangleOfSize for collision physics body, but if I want to use by pixel just the shape of the image, what I should use instead of rectangleOfSize?