swift3

Dictionary has optional key

那年仲夏 提交于 2019-12-13 07:15:17
问题 I'm having a array of CNContact and I sort them with this function: for contact in self.contacts { var contactName = contact.organizationName let key: String = String(contactName.characters.first).uppercaseString if let arrayForLetter = self.contactDictionary[key] { self.contactDictionary[key]!.append(contact) self.contactDictionary.updateValue(arrayForLetter, forKey: key) } else { self.contactDictionary.updateValue([contact], forKey: key) } } self.keys = self.contactDictionary.keys.sort()

addTarget and addGestureRecognizer not working, no crash/error

余生长醉 提交于 2019-12-13 07:11:13
问题 I a have an overlay with a table in and I'd like to add a Tap gesture recogniser to the background to dismiss the view and also addTarget to a button within the overlay which does the same thing. The overlay displays fine as expected, however whenever I tap the black background or the cancel button, nothing happens. I've searched for an answer here but nothing found has worked. My code is as follows, followed by a screenshot of the overlay: class importedFileView: NSObject { let blackView =

Saving NSDate error in Swift 3 and iOS 10

心不动则不痛 提交于 2019-12-13 07:11:02
问题 I believe this is a bug introduced in the new stack probably Swift 3 / iOS 10. I am running on XCode8 / Swift3 / iPhone 7 (Simulator) / ios 10.0 I have not found any related report of it. set the value let dt : Date? = Date() UserDefaults.standard.set(dt, forKey: "test-date") Get the value let dt = UserDefaults.standard.object(forKey: "test-date") if dt == nil { return false } else { let date = dt! as Date // FAILED } The failed message is: Could not cast value of type '__NSCFData'

Swift 3/XCode 8 NSManagedObjectContext.fetch error

谁都会走 提交于 2019-12-13 07:05:27
问题 I am migrating to Swift 3 and have come across a very strange error message while migrating abstract CoreData query code. entityName is passed to the following method: func objects(entityName name:String)->[NSManagedObject]? { let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName:name) var objects: [NSManagedObject]? do { objects = try managedObjectContext.fetch(fetchRequest) } catch { ... } } This results in the following error: Cannot invoke 'fetch' with an

Swift 3 - Passing Variables and Functions Between View Controllers

风流意气都作罢 提交于 2019-12-13 06:48:24
问题 I am currently making a test app where you can draw and send pictures using multipeer connectivity. There is a connection view controller for the host and a separate one for the other peers. When peers have connected the host will play the game and all the peer's view controllers will go to the drawing VC proving they are connected. However, when I want to send data in the drawing VC, the console says the connected peers the session is 0 even though there are connected peers. I can test that

Swift 3 - Hide Elements

孤者浪人 提交于 2019-12-13 06:10:45
问题 Im trying to hide a element using swift 3. The element won't hide if its in session.dataTask , but if I move it outside session.dataTask the element hides fine. Is it possible to hide a element in session.dataTask ? @IBOutlet weak var login_box: UIStackView! let task = session.dataTask(with: request as URLRequest) { ( data, response, error) in guard let data = data, let _:URLResponse = response, error == nil else { print("error") return } //Following won't hide element self.login_box.isHidden

Accessing MultiLevel Nested Children in Firebase Database Swift 3

北城余情 提交于 2019-12-13 04:34:01
问题 I am using Firebase Realtime Database. I have a customer id which corresponds to customer table. I need to fetch its respective apartment name. Then search the record having same apartment name in apartment table. Once found, I need to get all serviceType values from its respective segments. Also need to fetch its block from apartment table. Table structure is as follows: customer -L1x2AKUL_KNTKXyza apartment_name:"ABC Residency" appartment -L1Ohec4nW-ya_SkiG49 apartment_name:"ABC Residency"

How to show Arabic text in notification? [closed]

若如初见. 提交于 2019-12-13 04:17:20
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I am getting FCM push notification in both languages English/Arabic but I want to show it only in Arabic, How to show this? My Code- @available(iOS 10, *) extension AppDelegate : UNUserNotificationCenterDelegate { // Receive displayed notifications for iOS 10 devices. func userNotificationCenter(_ center:

MapBox turn by turn navigation Custom Marker Issue

旧时模样 提交于 2019-12-13 04:07:56
问题 I am using navigation view for my application, I wan to load n number markers on navigation view with different marker images. When I tried to do this with navigation annotation view only destination image is changed others shown as 1,2,3 etc. I tried to load image using this function func navigationMapView(_ mapView: MGLMapView, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? { let reuseIdentifier = "\(annotation.coordinate)" let annotationView1 = MGLAnnotationView(reuseIdentifier:

Swift 3 UnsafeMutablePointer initialization for C type float**

允我心安 提交于 2019-12-13 04:00:02
问题 Within Swift 3, I need to send data to a C object accepting float ** input. In Swift 2, I used to declare a UnsafeMutablePointer< UnsafeMutablePointer<Float32>> , construct a swift Array (only for init!), and pass this to the pointer, and it worked: var bufferOut: UnsafeMutablePointer< UnsafeMutablePointer<Float32>>? arrayOut = Array(repeating: Array(repeating: 0, count: Int(size1), count: Int(size2)) bufferOut = UnsafeMutablePointer< UnsafeMutablePointer<Float32>>(arrayOut) This is all