swift2

Using inout keyword: is the parameter passed-by-reference or by copy-in copy-out (/call by value result)

﹥>﹥吖頭↗ 提交于 2019-12-20 01:04:30
问题 Question: Based on the information and discussion below: Are inout parameters passed-by-reference or by copy-in copy-out ? Based on the following SO threads, function parameters marked by the inout keyword is passed by reference : Does inout/var parameter make any difference with reference type? Is Swift Pass By Value or Pass By Reference Why doesn't inout pass by reference? We note that the two top-most threads are pre-Swift 2.0; I haven't been able to find any newer discussion on the

How to live check a NSTextField - Swift OS X

梦想的初衷 提交于 2019-12-19 21:19:03
问题 I am currently making an OS X application written in Swift. What I want to do is when the user enters text in a NSTextField , I want to run a function that checks the value and adds it to a Label. How would I do this in swift? 回答1: Conforms ViewController to protocol NSTextDelegate . Assign ViewController as Delegate for TextField . Implement controlTextDidChange method. import Cocoa @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate { @IBOutlet weak

How do I add a left bar button without overriding the natural back button?

◇◆丶佛笑我妖孽 提交于 2019-12-19 19:45:45
问题 I have a project that uses UIViewControllers embedded in navigation view controllers, so the back button is automatically set up for me whenever I segue into any detail of my tableviews. Now I want to add an Edit button beside the back button. I've already put an Unassign button on the right side, and since the word "Unassign" is quite long, I'd rather fit the Edit button beside the back button on the left side. I know I can programmatically add bar buttons with navigationItem

Difference between sort and sortInPlace in swift 2?

寵の児 提交于 2019-12-19 18:54:51
问题 I have been trying to use the sortInPlace function in swift but it is not working. When I use the sort function instead of sortinplace it works. Please explain the difference between these 2 function. It would be very helpful if you can provide small code sample demonstrating the use of both functions. 回答1: var mutableArray = [19, 7, 8, 45, 34] // function sort sorts the array but does not change it. Also it has return mutableArray.sort() mutableArray // prints 19, 7, 8, 45, 34 // function

Apply a number to each letter in text swift2

心已入冬 提交于 2019-12-19 12:47:19
问题 I want to compare two entries in a UITextField giving a number to each letter and then compare the results of the addition of the letters from both fields. Example: a=1 b=2 c=3 d=4 e=5 f=6 textfield1= cae textfield2= fca Result is: textfield1=9 and textfield2=10 回答1: You could use the unicode scalar representation of each character (look up ASCII tables) and sum these shifted by -96 (such that a -> 1 , b -> 2 and so on). In the following, upper case letters will generate the same number value

How can i create a user with info about Display Name, username & Profile pic?

扶醉桌前 提交于 2019-12-19 12:00:11
问题 How can i create a user with info about Display Name, username & Profile pic? Can I use this code? if let user = FIRAuth.auth()?.currentUser let name = user.displayName let email = user.email let photoUrl = user.photoURL let uid = user.uid; // The user's ID, unique to the Firebase project. // Do NOT use this value to authenticate with // your backend server, if you have one. Use // getTokenWithCompletion:completion: instead. } else { // No user is signed in. } If not, for what purpose this

Swift, for some UIViews to their overall controller when clicked

谁说胖子不能爱 提交于 2019-12-19 11:32:30
问题 I have a DotBoss:UIViewController There are a dozen UIView in the scene, Dot:UIView (Some are direct subviews, some are further down.) There are even container views in the chain between the highest controller and the Dot items. The dozen Dot items know if they are tapped... class Dot:UIView { private var tap:UITapGestureRecognizer? = nil override func awakeFromNib() { tap = UITapGestureRecognizer(target:self, action: #selector(SnapDot.handleTap(_:))) self.addGestureRecognizer(tap!) } func

Swift, for some UIViews to their overall controller when clicked

此生再无相见时 提交于 2019-12-19 11:30:32
问题 I have a DotBoss:UIViewController There are a dozen UIView in the scene, Dot:UIView (Some are direct subviews, some are further down.) There are even container views in the chain between the highest controller and the Dot items. The dozen Dot items know if they are tapped... class Dot:UIView { private var tap:UITapGestureRecognizer? = nil override func awakeFromNib() { tap = UITapGestureRecognizer(target:self, action: #selector(SnapDot.handleTap(_:))) self.addGestureRecognizer(tap!) } func

context?.save(nil) coming up with error

旧巷老猫 提交于 2019-12-19 10:34:14
问题 Using Xcode 7 and swift 2.0 if get the following error on the context?.save(nil). Any help is appreciated "cannot use optional chaining on non-optional value of type 'NSManagedObjectContext' func newItem() { let context = self.context let ent = NSEntityDescription.entityForName("CallList", inManagedObjectContext: context) let nItem = CallList(entity: ent!, insertIntoManagedObjectContext: context) nItem.firstname = firstName.text nItem.lastname = lastName.text nItem.phonenumber = phoneNumber

.sort not working in Swift 2.0

亡梦爱人 提交于 2019-12-19 10:31:47
问题 I'm trying to sort my arrays of combinations i currently have. It is multidimensional array, but I only need to sort out the array that's inside for now. for combination in myCombinations { combination.sort({$0 < $1}) print("\(combination)") } Here's my code to sort out the array and here's my result. ["lys", "dyt", "lrt"] ["lys", "dyt", "gbc"] ["lys", "dyt", "lbc"] I also got a warning that says "Result of call to 'sort' is unused" Could anyone help me out with this? Thanks. 回答1: In Swift 2,