Tag: swift

View Position Resets with bringSubviewToFront

Using Autolayout, everytime I call bringSubviewToFront, the UIView resets. I tried setting an original position with txtViewPosition: txtViewPosition = CGRect(x: txtView.frame.origin.x, y: txtView.frame.origin.y, width: txtView.frame.size.width, height: txtView.frame.size.height) containerView.bringSubviewToFront(txtView) txtView.frame = txtViewPosition! It looks like the view is the correct position, but it is still showing up in its original spot (set in AutoLayout). Update (UIView […]

Compile errors with C++ static library include in Swift project

I created a static library that includes the follow C++ files: //TestClass.h File: #ifndef TESTCLASS_H_ #define TESTCLASS_H_ using namespace std; #include <string> class TestClass { public: TestClass(); virtual ~TestClass(); int sum(int x, int y) const; string chain(const string& x, const string& y) const; }; #endif /* TESTCLASS_H_ */ //TestClass.cpp File: #include<iostream> #include “TestClass.h” TestClass::TestClass() { […]

Problems with some for loops – – “Cannot subscript a value of type 'Double' with an index of type 'int'” errors

I’m getting a lot of “Cannot subscript a value of type ‘Double’ with an index of type ‘int’” errors in places with the indexes? arrays? like this This code is taken from Obj-C and translated as best as I could to Swift but I’m unfamiliar with some syntax. I cleaned up the for loops but […]

CryptoSwift, converting objective-c code to swift

I really need some help to convert the objective-c code to swift using CryptoSwift. I’m not sure how to use functions like: bzero, getCString, malloc in Swift. +(NSData*)encryptData:(NSData*)data { static NSString *key = @”BitCave012345678″; char keyPtr[kCCKeySizeAES128+1]; bzero(keyPtr, sizeof(keyPtr)); [key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding]; NSUInteger dataLength = [data length]; size_t bufferSize = dataLength + kCCBlockSizeAES128; void *buffer […]

UIView class for drop down list with UIButtons – delegate/protocol issue?

I am trying to create a custom drop down list in a ViewController. There are going to be 5 drop down lists and each list will have 4 options. Because of the number of lists, I decided to make a UIView that has the four choices in the form of UIButtons for each of the […]

How to get CFBundleURLSchemes of an app in iOS Swift

I have made a demo project App1 in which I added a button which will redirect me to the installed app suppose App2(“fitbit“) I have gone through many tutorials and basically got the idea how to do this through the 2nd answer "This app is not allowed to query for scheme cydia" IOS9 error .but […]

Swift classes not found in Objective-C project

I am working on an iOS project developed using Objective-C. I need to integrate some Swift files in it. So, did following: Added a new Swift file named “temp”, so that MyProject-Bridging-Header.h is added by my Xcode IDE (Version 9.1). Added the Swift files, which I want to use, to the project. Changed target setting […]

Why UICollectionView offset changes when keyboard appears

I’m developing an iPad app, that has a horizontal UICollectionView. Each of the cells has a UITextField. When the UITextField becomes first responder, the keyboard automatically comes up, and surprisingly all the cells move upwards. I haven’t implemented any logic for the cells to move upwards. Do you know why? I haven’t found any documentation […]

How do I unfocus UITextFields when user presses other controls/blank space?

I have a UITextField. It works normally, meaning that when pressed, it fires EditingDidBegin method etc. The problem is that I cannot deselect it, meaning that the keyboard will be always visible, covering important controls. I thought that default behavior would be deselecting/hiding keyboard when user clicks somewhere different from the UITextField, for example on […]

Swift error: “Cannot find interface declaration for 'SKScene', superclass of”

Disclaimer: I read through similar questions on SO, couldn’t find a solution to my problem. I want to add an subclass of SKScene to a project that did not previously use SpriteKit. The project is a mixture of ObjC and Swift. The subclass is written in Swift. What I did: Added SpriteKit.Framework by going to […]