I need a component like comboBox when it dropes down and allow user to select value. PickerView looks terrible and one I found nice looking was DownPicker
I followed instructions, installed it and tried to use but I did not see the data I pass to this component in it.
let data = NSMutableArray()
data.addObject("1")
data.addObject("2")
data.addObject("3")
let a = DownPicker(textField: group!, withData: data)
Also nothing happens when I tap down arrow icon
Just advice me another components like this one which will work correctly with xcode 7 beta 6 or help me to fix problems with current try. Thanks)
Update:
I've just tried this one. Nothing good from it too :\
DownPicker is working fine with Swift. I just tried it and use it in my project. The problem I see is that you init DownPicker to local variable. There are two ways how you can use DownPicker in your project and it looks you choose Control Wrapper. So you should have in your controller these controls:
#IBOutlet weak var personTextField: UITextField!
var personDownPicker: DownPicker!
The first one is outlet connected to UITextField added in storyboard. DownPicker I Initialized in viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
let persons: NSMutableArray = ["Architect", "Designer"]
self.personDownPicker = DownPicker(textField: self.personTextField, withData:persons)
}
Related
I'm brand new to Swift programming and my background has always been procedural languages so am coming to terms with both the language and some OO concepts.
I'm building an OSX application that has 1 GUI window, with 2 input fields and a button - when the button is clicked, the program takes image files from the folder entered in 1 of the text boxes and copies them to the folder entered in the second text box. On this main window us a NSTextView that acts as an output log so the user knows the progress of the copies.
ViewController.swift
utilities.swift
ImageCopy.swift
The 3 controls are defined in my ViewController
#IBOutlet var logView: NSTextView!
#IBOutlet weak var sourceFolder: NSTextField!
#IBOutlet weak var targetFolder: NSTextField!
The button code is:
#IBAction func ExecuteButtonPressed(_ sender: NSButtonCell){
utilities.writeToLog(lineOfText: "Copy process starting\n")
processImages(inputFolder, outputFolder) // <-- This can take some time
utilities.writeToLog(lineOfText: "Copy process ended\n")
}
in utilities.swift the writeToLog function is defined as:
class utilities{
static func writeToLog(lineOfText: String){
// Get current viewcontroller where the logview textview is
let vc = (NSApplication.shared.keyWindow?.contentViewController as! ViewController)
let calendar = Calendar.current
let time=calendar.dateComponents([.hour,.minute,.second], from: Date())
let outputLineOfText = "\(time.hour!):\(time.minute!):\(time.second!) - " + lineOfText
vc.logView.textStorage?.append(NSAttributedString(string: outputLineOfText))
vc.logView.scrollToEndOfDocument(self)
}
All the copy functionality is in the ImageCopy.swift file and utilises the writeToLog() function to attempt to write to the GUI control as it progresses.
The application is all working with one exception - as the ProcessImages() function can take so long, and from what I can understand is running on the main thread, it blocks the GUI updates so once the ProcessImages() function returns the logView NSTextView updates all at once.
I think I need to run the ProcessImages() function on a thread, however when I did that it still didn't update the logView.
Any help would be much appreciated.
************************************** UPDATE
I think I'm on the right path now. I'm investigating delegates and Notifications to communicate between the background thread and the UI View.
************************************** UPDATE
I think I'm on the right path now. I'm investigating delegates and Notifications to communicate between the background thread and the UI View.
I've already searched a lot but any answer fixed the problem.
I've created an app group, selected it on both app and today extension, they're linked to the same group now. I'm trying to load data from the app and display it on a table view on the today extension, the thing is that I'm getting a crash saying that my array is nil, and it cannot be nil. I don't know why tho, cause I'm putting the data into the array. Here is my code:
func handleData() {
let defaults = NSUserDefaults(suiteName: "MY APP GROUP HERE")
if let descriptionsArr = defaults?.valueForKey("descriptions") as? [String] {
descriptions = descriptionsArr
}
defaults?.synchronize()
}
So, I'm pretty sure the app group is spelled right, and the value key. What could it be that is making my array nil? Really need help!
Thanks.
I have a NSDocument-based app, and I'd like my window positions to be saved and restored when re-opening documents. Apple's documentation on this is pretty sparse, but what I've been able to piece together is that at some point, something in the app needs to call NSWindow.setFrameUsingName() and NSWindow.setFrameAutosaveName().
What I haven't quite figured out is what point this needs to happen at, and what things need to do this. For example, this doesn't work at all:
// In my NSDocument class
override func windowControllerDidLoadNib(aController: NSWindowController) {
super.windowControllerDidLoadNib(aController)
// Add any code here that needs to be executed once the windowController has loaded the document's window.
aController.window?.setFrameUsingName("MainWindow")
aController.window?.setFrameAutosaveName("MainWindow")
}
I've read various different pieces of documentation or forum answers that point to awakeFromNib() to be another area to do this, but I can't get that to work either.
I'm also confused / worried that this is somehow being affected by Auto Layout or something I've done wrong in Interface Builder - for example, this is how my window is set up in IB:
I don't particularly want my window centered, but the other options seem to lock it in place in fixed horizontal or fixed vertical positions, which I also don't really want. A side effect of having my window be centered is that my document windows no longer cascade, which I neither want nor can seem to stop from happening (note that windowController.shouldCascadeWindows = true isn't helping either).
So - what's going on here? I'm finding knowledge on this topic to be particularly unclear or misleading, and likely out of date for Cocoa development 2015, so a modern refresher on this would be great.
Step 1: In IB, give the window an autosave name.
Step 2: There is no step 2.
The easiest place to set the name of the autosave name for the window frame is probably in your implementation of NSDocument.
If you override makeWindowControllers() as part of the implementation, you are creating the window controller(s) manually, and thus can set the name there:
override func makeWindowControllers() {
let storyboard = NSStoryboard(name: NSStoryboard.Name("MyDocumentStoryboard"), bundle: nil)
let windowController = storyboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("MyDocument Window Controller")) as! MyDocumentWindowController
// this assumes you have a stored property or a computed property `someUniqueIdentifier` that is as unique as possible for your document
// and that you store on disk together with the rest of the document properties
windowController.windowFrameAutosaveName = NSWindow.FrameAutosaveName(rawValue: someUniqueIdentifier)
self.addWindowController(windowController)
}
If you instantiate your document window by overriding windowNibName, you should instead override the method windowControllerDidLoadNib(_:), to set the autosave name on the window. I have not tested this code, but I assume it will work:
func windowControllerDidLoadNib(_ windowController: NSWindowController) {
// this assumes you have a stored property or a computed property `someUniqueIdentifier` that is as unique as possible for your document
// and that you store on disk together with the rest of the document properties
windowController.windowFrameAutosaveName = NSWindow.FrameAutosaveName(rawValue: someUniqueIdentifier)
}
I have a WKInterfacePicker in my Watch's Interface and want to add items to it. Here is my code I currently have:
let item1:WKPickerItem = WKPickerItem()
item1.title = "1"
let item2:WKPickerItem = WKPickerItem()
item2.title = "2"
timePicker.setItems([item1, item2])
When I run the app it crashes and tells me there is a nil last line:
fatal error: unexpectedly found nil while unwrapping an optional value
I had a look at Apple's docs for the WKInterfacePicker and WKPickerItem but that did not help me either. Is it possible that I have to set the content of the items somehow else? I thought the title is the content already and I couldn't find any other method for setting content.
It's likely that timePicker is nil. Did you remember to hook it up to the outlet?
#IBOutlet var timePicker: WKInterfacePicker!
Since it's declared with !, this is the only place you could be force unwrapping nil.
If you're still having problems, there's a full guide on WKInterfacePicker you can try here: http://www.sneakycrab.com/blog/2015/6/12/wkinterfacepicker-in-watchkit-20-using-the-digital-crown
I'm new to the coding industry and am seriously struggling with Swift. I have a situation where I want to go from one page to another, but I keep getting an error of "use of undeclared type AVCamViewController. This is my code:
#IBAction func goToApp(sender : AnyObject) {
let AVCam = self.storyboard.instantiateViewControllerWithIdentifier("AVCam") as? AVCamViewController.h
self.navigationController.pushViewController(AVCam, animated: true)
}
And if I try to import the AVCamViewController or AVCamViewController.h or AVCamViewController.m, I get an error of 'no such module'.
I have have all the files of the AVCam application in my app so I am not sure what to do. Any advice please?
You need to remove .h from line when you instantiate vc:
let AVCam = self.storyboard.instantiateViewControllerWithIdentifier("AVCam") as? AVCamViewController
AVCamViewController.h is file name but you need class name which is AVCamViewController
Do you have a bridging header set up? If AVCamViewController is a system class, you have to #import the right framework, i.e. #import AVFoundation. Otherwise, you have to create a header specifically for use as a bridge from Objective C to Swift. In said header, you include your own headers that you want Swift to see. You will have to set the build settings to point to the new header. If you added a new Swift class/file, Xcode should have asked if it could create one automatically. If you do have one, you can put your header imports/includes into that file.