swift2

How to access the Terminal's $PATH variable from within my mac app, it seems to uses a different $PATH

微笑、不失礼 提交于 2021-02-17 20:47:20
问题 I'm trying to make a mac app where the user can type in commands just like they would in the mac terminal, I got most of it working however I found out that the $PATH variable of apps run from the finder or xcode is different than the $PATH variable the Terminal uses. I can run commands and also found a way to add a predefined path to the application's $PATH variable but I need a way to automatically read the Terminal's $PATH variable and copy it to the Application's $PATH variable. This

Swift extension for selected class instance

自作多情 提交于 2021-02-16 06:24:23
问题 In Objective-C category, you can bring in the extended capability introduced by the category methods by including the header of the category in your class. It seems like all Swift extensions are automatically introduced without import. How do you achieve the same thing in Swift? For example: extension UIView { // only want certain UIView to have this, not all // similar to Objective-C, where imported category header // will grant the capability to the class func extraCapability() { } } 回答1:

How do I specify class name as variable in Swift?

◇◆丶佛笑我妖孽 提交于 2021-02-11 12:09:18
问题 I want to do something like this: class Dog: Object { dynamic var name = "" dynamic var age = 0 } let results = realm.objects(Dog) ...but specify the object name as a variable. This doesn't work: let objectName = "Dog" let results = realm.objects(objectName) Neither does this: let object = Dog let results = realm.objects(object) ...or this: let object = Dog() let results = realm.objects(object) ...or this: let object: Dog let results = realm.objects(object) Any ideas? 回答1: You can reference

Are inout variables of protocol type prohibited?

给你一囗甜甜゛ 提交于 2021-02-07 22:12:09
问题 The following code: protocol SomeProtocol {} class SomeClass: SomeProtocol {} private func doSomethingWith(inout someVar: SomeProtocol) {} private var someGlobalVar = SomeClass() // inferring SomeClass's type doSomethingWith(&someGlobalVar) produces the following error: Cannot invoke 'doSomethingWith' with an argument list of type '(inout SomeClass)' Changing the penultimate line to private var someGlobalVar: SomeProtocol = SomeClass() resolves the error. Subj. 回答1: When you assign a

Cannot convert value of type 'String.Type' to expected argument type 'String!'

怎甘沉沦 提交于 2021-02-07 07:23:15
问题 I am using a library MDWamp written in objective C and it has a property of the following type @property (nonatomic, strong) void (^deferredWampCRASigningBlock)( NSString *challange, void(^finishBLock)(NSString *signature) ); This is the signature in swift public var deferredWampCRASigningBlock: ((String!, ((String!) -> Void)!) -> Void)! and when I try to instantiate it in swift in the following manner self.wamp?.config.deferredWampCRASigningBlock?(str : String , { (str2 : String) -> Void in

Adding GIF Background to viewController with Swift

守給你的承諾、 提交于 2021-02-07 04:36:17
问题 I wanted to add GIF Background to my landing screen with swift, so I found this code online but when I try to use it on XCODE 7 with Swift 2.0 import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() var filePath = NSBundle.mainBundle().pathForResource("videoName", ofType: "gif") var gif = NSData(contentsOfFile: filePath!) var webViewBG = UIWebView(frame: self.view.frame) webViewBG.loadData(gif, MIMEType: "image/gif", textEncodingName: nil,

Loading local css & js files into WKWebView

点点圈 提交于 2021-02-06 11:01:03
问题 in Swift 2.1.1 & Xcode 7.1 My code uses WKWebView and loads index.html form a local file but fails to load index.css and other javascript files as shown in the head tag. My best guess is that the baseURL is not correct, if so, How can I set the baseURL correctly? Thanks import UIKit import WebKit class ViewController: UIViewController { @IBOutlet var containerView: UIView! = nil //allows the class to refrence WKWebView var webView: WKWebView? override func loadView() { super.loadView() self

Loading local css & js files into WKWebView

笑着哭i 提交于 2021-02-06 10:57:18
问题 in Swift 2.1.1 & Xcode 7.1 My code uses WKWebView and loads index.html form a local file but fails to load index.css and other javascript files as shown in the head tag. My best guess is that the baseURL is not correct, if so, How can I set the baseURL correctly? Thanks import UIKit import WebKit class ViewController: UIViewController { @IBOutlet var containerView: UIView! = nil //allows the class to refrence WKWebView var webView: WKWebView? override func loadView() { super.loadView() self

How can identify strong reference cycles in Swift?

匆匆过客 提交于 2021-02-05 12:48:10
问题 Is there a tool or method to locate strong references cycles in my SWIFT code? A strong reference cycle is when two instances of classes reference each other without the proper safeties ( weak / unowned ) hence preventing the garbage collector from disposing of them once all the variables I created stopped referencing those objects. 回答1: The method for finding strong reference cycles is the same in Swift as it is in Objective-C. You'd run the app from Xcode, exercise the app sufficiently to

Instance member cannot be use on type

帅比萌擦擦* 提交于 2021-01-29 04:03:59
问题 @IBAction func saveDetails(sender: AnyObject) { Person.firstName = firstNameTF.text Person.lastName = lastNameTF.text } Above is the function I am trying to implement and below is the class I am trying to create an instance of and store the data from my text fields in... I am getting the error "Instance member "firstName" cannot be used on type Person". I was almost positive that my class was setup and initialised properly so I can't see what the problem could be? class Person { var firstName