Tag: swift2

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?

Workaround to submit app to app store with Xcode 7

When trying to submit an app compiled with Xcode 7 to iTunes Connect for review, I get an error message Apps and app updates submitted to the App Store must be built with Xcode 5.1.1 or later, and iOS 7 SDK. Is there any workaround to this? I’ve already updated all of my code to […]

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]) { PFPush.handlePush(userInfo) if application.applicationState == UIApplicationState.Inactive { PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)} Here is the JSON i received from parse website : [aps: { alert = “test adirax”; sound = default; }] It works well […]