swift3

After Swift 3 conversion, I can't get rid of error: “Ambiguous use of 'indexOfObject(passingTest:)'”

别来无恙 提交于 2019-12-12 10:48:11
问题 I'm using NSArray 's indexesOfObjects(passingTest:), but after I converted my code to Swift 3 I get the error: "Ambiguous use of 'indexOfObject(passingTest:)'". My code below worked fine with Swift 2.3. let indexesOfBubbleConstraints = bubbleConstraints.indexesOfObjects(passingTest: { (constraint, idx, stop) in if let view = constraint.firstItem as? UIView{ return view.tag == usernameTag } else{ return false } }) For Swift 3, I also had to cast constraint to AnyObject , but that doesn't fix

Change orientation programmatically with button - iOS

流过昼夜 提交于 2019-12-12 10:42:49
问题 I have a view controller and I would like to have the following experience. Inside the view controller i got a button which force rotate the orientation to landscape right. In Deployment Info - Device Orientation i have enabled "Landscape Right" and "Portrait". I want to mention that in my device i have enabled the "Portrait Orientation Lock" that's why i want a button to rotate the orientation programmatically with the following code. let rotateButton: UIButton = { let btn = UIButton(type:

Cache that can purge unused objects by demand

陌路散爱 提交于 2019-12-12 10:15:25
问题 I need to create a cache, that could save some objects, but then, at some point when I have memory warning or simply user wants it, I would like to purge all instances that are used only in the cache at the moment. In other words: I need to deinit objects with ARC count == 1. The problem is that based on my googling of this project, it is not possible in pure Swift to get the retain count of an object. From my experience I see that it is not possible by default in Swift. In objective-c I was

UNUserNotificationCenter Swift - Local Notification Not Firing in specific cases

假如想象 提交于 2019-12-12 10:02:52
问题 I'm facing issue while using Local Notifications in application. I'm scheduling local notification with custom content & custom action category. It's scheduling & firing in iOS 11, but not in iOS 10. As per documentation, it should be worked in iOS 10 as well. Please review my code, and let me why it's not working in such specific cases. Code is below. AppDelegate.swift func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey:

Text padding on UILabel

拥有回忆 提交于 2019-12-12 10:00:20
问题 Here, I am trying to have a label with some padding (left, right, top and bottom) around the text. This issue has related post on SOF and after reading a few of them, I tried using a solution proposed here: This is the code for my subclassing UILabel: import UIKit class LuxLabel: UILabel { //let padding: UIEdgeInsets var padding: UIEdgeInsets = UIEdgeInsets.zero { didSet { self.invalidateIntrinsicContentSize() } } // Create a new PaddingLabel instance programamtically with the desired insets

How initialize a Timer inside a custom class in Swift? [duplicate]

无人久伴 提交于 2019-12-12 10:00:18
问题 This question already has answers here : Swift wants argument of #selector to be exposed to Objective-C (3 answers) Closed 3 years ago . I make a simple cronometer app, but, now I want make it better, and I would like to write a class for the cronometer control: class Cronometer{ private var counter:Int = 0 private var timer:Timer = Timer() private var state:Bool = true func initCronometer(){ if self.state{ self.timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: Selector(

How to move an object towards a direction without stopping

徘徊边缘 提交于 2019-12-12 09:53:45
问题 I'm developing a small game in Swift 3 with SpriteKit and I want to move the enemies to the direction of the character, but at all times the enemies stop when they arrive at the character's initial position. I'm doing this: enemigo.name = "enemigo" enemigo.position = CGPoint(x: 280, y: 100) enemigo.xScale = 1/1 enemigo.yScale = 1/15 addChild(enemigo) let movement1 = CGVector( dx: (enemigo.position.x - personaje.position.x)*10, dy: (enemigo.position.y - personaje.position.y)*10 ) let

Swift 3 select multiple photos using UIImagePickerController

青春壹個敷衍的年華 提交于 2019-12-12 09:42:30
问题 I have a UIImagePickerController which with it I select a photo from Library, or take a photo with Camera and then show the selected photo in a UIImageView . I want to upload this photo later to an API (which still don't know how to upload photos, have never done it). So what I want is a feature like WhatsApp selecting photos feature which you can select let's say 20 photos and then you can see them. (I mean for my case I only have one UIImageView and can only show one photo. What is the

How to extract street, city, etc. from GMSPlace Address Components

亡梦爱人 提交于 2019-12-12 09:37:57
问题 I'm using Google Places API for iOS and can successfully retrieve nearby places and present the address as a string. What I'm trying to do is extract address components such as city to store in a database. The documentation indicates a GMSPlace has an addressComponents property (an array), but I can't seem to figure how to use this property. The code below provides sets the entire address to the text of a label, but I can't get beyond that: Edit ---- added code that shows how I'm trying to

Where is CGRectGetMidX/Y in Swift 3

 ̄綄美尐妖づ 提交于 2019-12-12 09:29:50
问题 IN Siwft 3, I could not find CGRectGetMidX and Y which I used to calclate position of nodes. Also I could not find CGPointMake. IN this case, how am I able to set nodes in the center of SKScene? Thanks! Update: I created a node and specified the position of it, by writing this way; let node = SKSpriteNode() node.position = CGPoint(x:self.frame.size.width/2, y:self.frame.size.height/2) node.size = CGSize(width: 100, height: 100) node.color = SKColor.red self.addChild(node) Why is it somewhere