[Solved] How to convert Objective-C to Swift [closed]

This is more correct than iPrabu’s answer, which is incomplete. let deviceTokenString = deviceToken.debugDescription.stringByReplacingOccurrencesOfString(“>”, withString: “”).stringByReplacingOccurrencesOfString(“<“, withString: “”).stringByReplacingOccurrencesOfString(” “, withString: “”) let link = “http://emlscer.no-ip.info:8080/sample/iAppList.php?add=\(deviceTokenString)” if let escapedString = link.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding), url = NSURL(string: escapedString) { var request = NSMutableURLRequest(URL: url) request.HTTPMethod = “GET” do { try NSURLConnection.sendSynchronousRequest(request, returningResponse: nil) } catch { // Handle your … Read more

[Solved] Checking if TableView row was selected for the first time

You can maintain a set like this. var selectedOnce = Set<Int>() Add the selected index to this set whenever it is selected first time. selectedOnce.insert(index) Check next time, whether it was already selected like if selectedOnce.contains(indexToCheck) { } If something is required for one time per app. I mean, it should not happen for next … Read more

[Solved] How can I substring this string?

Swift’s substring is complicated: let str = “12:345” if let range = str.range(of: “:”) { let startIndex = str.index(range.lowerBound, offsetBy: 1) let endIndex = str.index(startIndex, offsetBy: 2) print(str[startIndex..<endIndex]) } 2 solved How can I substring this string?

[Solved] Singleton class with instance variable and methods in Swift (iOS)

i got the solution, when i tried this, worked fine! class ABC_Util { var doesValueExists:Bool = false var arrValues:NSMutableArray? = nil class var sharedInstance: ABC_Util { struct ABC_UtilSingleton { static let instance = ABC_Util() } return ABC_UtilSingleton.instance } init() { self.doesValueExists = self.checkValueExists() self.arrValues = self.getArrayOfValues() } //method internal func checkValueExists()-> Bool { //return true/false … Read more

[Solved] Hide status bar only on iPhone 5, 5s, SE

iPhone 5, 5S and SE have a screen width of 320. In your AppDelegate you could do the following: func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { if UIScreen.main.bounds.width == 320 { application.isStatusBarHidden = true } return true } And go to your info.plist and add a new value: View controller-based status … Read more

[Solved] Retrieve numbers before/after sign change in [Double]

([60, 21, -18, -57, -95, -67, -29, 8, 45, 82] as [Double]) .consecutivePairs .filter { $0.sign != $1.sign } public extension Sequence { /// Each element of the sequence, paired with the element after. var consecutivePairs: Zip2Sequence<Self, DropFirstSequence<Self>> { zip(self, dropFirst()) } } solved Retrieve numbers before/after sign change in [Double]

[Solved] Reduce UserDefaults Integer Value – Swift

First, obtain the old value of the high score. Then, do the arithmetic before finally saving the new value: let oldValue = UserDefaults.standard.integer(forKey: “HIGHSCORE”) let newValue = oldValue – 20 UserDefaults.standard.set(newValue, forKey: “HIGHSCORE”) solved Reduce UserDefaults Integer Value – Swift

[Solved] How to make an array using dummy values from Struct Modal class in Swift iOS

You need to actually initialize syncModelRecord. Try this: let syncModelRecord = SyncModelRecord(date: String(Int64(syncTimestamp!)), shakeState: 0) dummySyncModelRecordArray.append(syncModelRecord!) Another tip maybe worth exploring, you can directly decode a date and specify the decoder’s strategy for it (in your case secondsSince1970) solved How to make an array using dummy values from Struct Modal class in Swift iOS

[Solved] Logout button in every viewcontroller in swift 5

I’ve created an UILibraryFunction.swift file. class UILibraryFunction: UIViewController { var navBar:UINavigationBar = UINavigationBar() var navItem = UINavigationItem(title: “SomeTitle”) var screenWidth:CGFloat = 0 var screenHeight:CGFloat = 0 var NameHeight:CGFloat = 0 var NameWidth:CGFloat = 0 override func viewDidLoad() { super.viewDidLoad() let screenSize: CGRect = UIScreen.main.bounds screenWidth = screenSize.width screenHeight = screenSize.height NameHeight = screenHeight * 0.09 … Read more