Calling fcntl() and friends from Swift?

2014-10-18 Thread Rick Mann
So far, my foray into Swift is going decently well. But I'm trying to re-write some code that uses IOKit and , and while the IOKit calls are fine, it doesn't like me trying to call fcntl(). It says, "Use of unresolved identifier 'fcntl'". I've tried including in my bridging header, I tried a f

Re: Table of TextViews

2014-10-18 Thread Ken Thomases
On Oct 15, 2014, at 6:40 AM, Charles Jenkins wrote: > Thanks for looking it over. :-) I guess I misunderstood the documentation. I > thought if you dragged out a table view from the palette into a NIB, you got > a full hierarchy of objects (including the extra scroll view I specifically > don’

Re: Calling fcntl() and friends from Swift?

2014-10-18 Thread Roland King
> On 18 Oct 2014, at 5:25 pm, Rick Mann wrote: > > So far, my foray into Swift is going decently well. But I'm trying to > re-write some code that uses IOKit and , and while the IOKit > calls are fine, it doesn't like me trying to call fcntl(). It says, "Use of > unresolved identifier 'fcntl'

DOMDocument in 10.10

2014-10-18 Thread Gerriet M. Denkmann
WebFrame *mainFrame = [ webView mainFrame ]; DOMDocument *domDoc = [ mainFrame DOMDocument ]; When I print domDoc, I get with 10.9 something like: with 1 children with 3 children [ 0] with 15 children [ 0] DOMText = "** white **"

Document style programming

2014-10-18 Thread Luther Baker
Hi, I am creating a Desktop issue tracking app using core data and the NSDocument framework - so yes, the Xcode wizard extended NSPersistentDocument which provides me with an NSManagedObjectContext. My question is - if I start working in the app, creating issues for instance ... when I go to actu

Re: Document style programming

2014-10-18 Thread Mike Abdullah
When using NSPersistentDocument it takes over responsibility for saving the context. You should not save the context yourself. > On 18 Oct 2014, at 17:00, Luther Baker wrote: > > Hi, > > I am creating a Desktop issue tracking app using core data and the > NSDocument framework - so yes, the Xco

Saving a Document style app

2014-10-18 Thread Luther Baker
I'd like to save my Document based app in the bundle style format. IE: I'd like to save things in a directory - like apps like OmniOutliner do. Out of the box, I get the option to save as sqlite, binary or XML. What I'd like is to save a 'bundle' with my own extension and nest things like the the

Re: Document style programming

2014-10-18 Thread Luther Baker
Thanks Mike. Let me ask another question ... what if I need to create a temporary, thread specific NSManagedObjectContext? Let's say I'm interacting with a RESTful API ala AFNetworking and I need to parse and save data on a background response thread. How do I tie my thread specific context into

Re: Saving a Document style app

2014-10-18 Thread Mike Abdullah
> On 18 Oct 2014, at 17:06, Luther Baker wrote: > > I'd like to save my Document based app in the bundle style format. IE: I'd > like to save things in a directory - like apps like OmniOutliner do. > > Out of the box, I get the option to save as sqlite, binary or XML. What I'd > like is to save

Re: Document style programming

2014-10-18 Thread Mike Abdullah
> On 18 Oct 2014, at 17:09, Luther Baker wrote: > > Thanks Mike. > > Let me ask another question ... what if I need to create a temporary, thread > specific NSManagedObjectContext? Let's say I'm interacting with a RESTful API > ala AFNetworking and I need to parse and save data on a backgroun

One more Document app style question

2014-10-18 Thread Luther Baker
Coming from an iOS background, I'm used to seeing (and encapsulating) the creation of key Core Data components (persistent store, location, contexts). Everything is pretty explicit and consequently easy to follow. When I use Xcode to generate a desktop Document based app for me, that functionality

Re: Saving a Document style app

2014-10-18 Thread Luther Baker
Awesome! Thanks Mike. By the way, I'm a happy Hit List user! -Luther On Sat, Oct 18, 2014 at 11:10 AM, Mike Abdullah wrote: > > > On 18 Oct 2014, at 17:06, Luther Baker wrote: > > > > I'd like to save my Document based app in the bundle style format. IE: > I'd > > like to save things in

Re: Document style programming

2014-10-18 Thread Luther Baker
As an aside, I'm sure it is well-known, there is some funny caching going on. If I open the app the first time (and pre-populate the context with data) - I cannot actually "SAVE". If I formally shut the app down by quitting the app and choosing "Don't Save", then subsequent restarts exhibit the s

Re: Passing a swift function to objective-c

2014-10-18 Thread Kevin Meaney
Hi Roland, Thanks for the followup. I've created a proper git rep on github rather than just a gist. Most of my github reps seem to be this kind of mini demonstration project and I was trying to avoid yet another one. https://github.com/SheffieldKevin/swift-objectivec > What version of Xcode a

Re: Document style programming

2014-10-18 Thread Mike Abdullah
> On 18 Oct 2014, at 17:33, Luther Baker wrote: > > As an aside, I'm sure it is well-known, there is some funny caching going on. > > If I open the app the first time (and pre-populate the context with data) - I > cannot actually "SAVE". > > If I formally shut the app down by quitting the app

Re: Passing a swift function to objective-c

2014-10-18 Thread Kevin Meaney
I've now found an acceptable solution. Rather than a property I've added an optional method to the protocol which then in its implementation assigns using the property, pretty much to make sure that the function/block is copied. I declared the method like so: -(void)applyMyCreateImageFunction:(

Re: DOMDocument in 10.10

2014-10-18 Thread Jens Alfke
> On Oct 18, 2014, at 5:33 AM, Gerriet M. Denkmann wrote: > > Note: the head has only 12 children (the first 10 are identical to 10.9), and > there is no body at all. Weird! Are you sure that the page has finished loading by the time you made the call? Maybe your code is running at a point wh

How does the Swift Darwin module work?

2014-10-18 Thread Rick Mann
I need access to fcntl, so I thought I'd do what Apple does with Darwin. But I don't actually see how to do that. They create Darwin.stdio.fopen(), for example. But then how do they call the underlying C fopen()? For that matter, Swift can call C functions directly in some cases, and not at all

Set UICollectionView UIScrollViewDelegate delegate

2014-10-18 Thread Mazzaroth M.
Hi, I have a parent view controller that has two UICollectionViewController subclasses as children in its view controller hierarchy. I'd like to set the parentViewController as the Subclass1CollectionViewController and Subclass2CollectionViewControllers' .colllectionView UIScrollView delegate. Howe

Re: How does the Swift Darwin module work?

2014-10-18 Thread Jean-Daniel Dupas
AFAIK, variadic C functions are not (yet) callable from swift code. > Le 18 oct. 2014 à 20:37, Rick Mann a écrit : > > I need access to fcntl, so I thought I'd do what Apple does with Darwin. But > I don't actually see how to do that. They create Darwin.stdio.fopen(), for > example. But then

Re: Set UICollectionView UIScrollViewDelegate delegate

2014-10-18 Thread Kyle Sluder
On Oct 18, 2014, at 2:22 PM, Mazzaroth M. wrote: > > Hi, I have a parent view controller that has two UICollectionViewController > subclasses as children in its view controller hierarchy. I'd like to set > the parentViewController as the Subclass1CollectionViewController and > Subclass2Collection

Clear NSSearchField

2014-10-18 Thread Randy Widell
It looks like a couple of people have asked about this in the past, but none of the answers are working for me. I am trying to clear the contents of a NSSearchField and have it go back to its empty state. I don’t have a pre-Yosemite Mac handy to check if this is a bug / new behavior in Yosemit

Re: Clear NSSearchField

2014-10-18 Thread Randy Widell
Yeah, I tried that initially. An invalid parameter exception comes flying out of NSCell’s setStringValue. > On Oct 18, 2014, at 14:59, Gerd Knops wrote: > > Did you try to set it ti nil instead of an empty string? > > Gerd > >> On Oct 18, 2014, at 4:51 PM, Randy Widell wrote: >> >> It loo

Toolbar icons, yosemite

2014-10-18 Thread Alex Kac
I’m learning about toolbar buttons/icons on Yosemite (probably not much different than before, but…I’m an iOS guy so its new for me). I have a few basic, 101-style questions that I hope somebody can point me to the right place for: 1. How do you do a popup menu button like the sidebar icon with

Re: Clear NSSearchField

2014-10-18 Thread Kyle Sluder
On Sat, Oct 18, 2014, at 04:51 PM, Randy Widell wrote: > That works somewhat, but not really. Half the time the search field > remains the first responder as if the call to set the outline view as the > first responder never happened. Have you tried forcing the text field to give up first respond

Re: How does the Swift Darwin module work?

2014-10-18 Thread Roland King
> On 19 Oct 2014, at 5:23 am, Jean-Daniel Dupas wrote: > > AFAIK, variadic C functions are not (yet) callable from swift code. > > They aren’t - I didn’t remember fnctl() was varidadic. I shall quote an Apple engineer then .. "This is not possible in Swift. C variadics are inherently unsafe

Re: Clear NSSearchField

2014-10-18 Thread Randy Widell
Yeah, that doesn’t work either. I’m clearing the search field in response to a change in selection in an outline view. Which means the search field is already not the first responder. So, setting the first responder to nil just makes the outline view give up first responder without affecting

Re: Toolbar icons, yosemite

2014-10-18 Thread Randy Widell
1) This is pretty easy. Just create a Pop Up Button, then switch its style to “Pull Down”. This will give you a push button with the single down arrow on the right. Then just edit the Pop Up Button’s menu. You can give it an icon, and then size it down horizontally so that only the icon is v

Re: Toolbar icons, yosemite

2014-10-18 Thread SevenBits
On Oct 18, 2014, at 8:31 PM, Randy Widell wrote: > 1) This is pretty easy. Just create a Pop Up Button, then switch its style > to “Pull Down”. This will give you a push button with the single down arrow > on the right. Then just edit the Pop Up Button’s menu. You can give it an > icon, and

Re: Toolbar icons, yosemite

2014-10-18 Thread Randy Widell
Sorry, forgot that giving the Pop Up Button an icon isn’t exactly straightforward. You want to create an menu item at the top of the menu that has the icon but no text. Then add the rest of your menu items below it. The Pop Up Button will display with the icon, but the first menu item will no

Re: Toolbar icons, yosemite

2014-10-18 Thread Randy Widell
> > I second this site. It’s really useful for finding icons. Just be warned that > some of them don’t look like Apple icons and may feel out of place, even with > the new flat design style. > Agreed. They work well for the application I am working on, but, yeah, that might not be the case f

Re: How does the Swift Darwin module work?

2014-10-18 Thread Rick Mann
> On Oct 18, 2014, at 16:40 , Roland King wrote: > > >> On 19 Oct 2014, at 5:23 am, Jean-Daniel Dupas wrote: >> >> AFAIK, variadic C functions are not (yet) callable from swift code. >> >> > > They aren’t - I didn’t remember fnctl() was varidadic. I shall quote an Apple > engineer then ..

Re: How does the Swift Darwin module work?

2014-10-18 Thread Marco S Hyman
>> So you get to go wrap fcntl() in something else it seems. > > So, how would I do that, exactly? I suppose I have to pass Objective-C > collection types to a method (which could be a straight C function) from a > Swift call? That is, can a Swift variadic call translate into a C function > ca

Re: How does the Swift Darwin module work?

2014-10-18 Thread Roland King
> On 19 Oct 2014, at 9:03 am, Rick Mann wrote: > > >> On Oct 18, 2014, at 16:40 , Roland King wrote: >> >> >>> On 19 Oct 2014, at 5:23 am, Jean-Daniel Dupas wrote: >>> >>> AFAIK, variadic C functions are not (yet) callable from swift code. >>> >>> >> >> They aren’t - I didn’t remember f

Re: How does the Swift Darwin module work?

2014-10-18 Thread Rick Mann
> On Oct 18, 2014, at 18:22 , Roland King wrote: > > Write a simple c wrapper around the thing you’re trying to do and that > bridges across to swift. You could probably try to write something really > generic which wraps fcntl() using an UnsafeMutablePtr as a final > argument and then massag

Re: How does the Swift Darwin module work?

2014-10-18 Thread Rick Mann
Wait, if variadic calls aren't supported, how is it that NSLog() can be called? > On Oct 18, 2014, at 18:22 , Roland King wrote: > > >> On 19 Oct 2014, at 9:03 am, Rick Mann wrote: >> >> >>> On Oct 18, 2014, at 16:40 , Roland King wrote: >>> >>> On 19 Oct 2014, at 5:23 am, Jean-Danie

Re: How does the Swift Darwin module work?

2014-10-18 Thread Roland King
> On 19 Oct 2014, at 10:11 am, Rick Mann wrote: > > Wait, if variadic calls aren't supported, how is it that NSLog() can be > called? > Probably has a version which takes a va_list. type import Swift at the top of your swift file then Cmd Click on ‘Swift’ and you’ll find all sorts of i

Re: How does the Swift Darwin module work?

2014-10-18 Thread Rick Mann
> On Oct 18, 2014, at 19:17 , Roland King wrote: > > >> On 19 Oct 2014, at 10:11 am, Rick Mann wrote: >> >> Wait, if variadic calls aren't supported, how is it that NSLog() can be >> called? >> > > Probably has a version which takes a va_list. > > type > > import Swift > > at the top

Re: How does the Swift Darwin module work?

2014-10-18 Thread Roland King
> > That's what I ended up doing (setNonblocking(int inFileDescriptor)), but, I > was asking for the sake of learning the language. It would be nice to have > generic replacements for fcntl() and ioctl(). > The best replacement would be to have a set of functions which took the Swiss Army kni

Re: How does the Swift Darwin module work?

2014-10-18 Thread Rick Mann
I agree, it's just a lot of work for someone (not me; I will only wrap the things I need). > On Oct 18, 2014, at 19:33 , Roland King wrote: > >> >> That's what I ended up doing (setNonblocking(int inFileDescriptor)), but, I >> was asking for the sake of learning the language. It would be nice

Subclassing NSWindowController in Swift

2014-10-18 Thread Rick Mann
In Obj-C, I typically subclass NSWindowController and override -init to call -initWithNibName:. I do this so the caller doesn't have to worry about how to make one of these window controllers: @implementation MyWindowController - (id) init { self = [super initWithWindowNibName: "MyWindow" o

bundleForClass in Swift

2014-10-18 Thread Rick Mann
In an NSWindowController subclass init method, I want to call -loadNibNamed:owner:topLevelObjects, but that requires I have a bundle. I can get the main bundle, but I'd rather get the bundle for this class (makes it useable in unit tests). But, inside an init method, I'm not allowed to referenc

Re: Subclassing NSWindowController in Swift

2014-10-18 Thread Graham Cox
Hi Rick, According to the latest documentation pack that arrived on Thursday, Swift has: convenience init(windowNibName windowNibName: String, owner owner: AnyObject) So just use this. Like C++, Swift has overloaded method names, so 'init' can take various parameter combinations.

Re: bundleForClass in Swift

2014-10-18 Thread Rick Mann
I realize, in this case, I should be loading in loadWindow(), but it still seems problematic. > On Oct 18, 2014, at 20:25 , Rick Mann wrote: > > In an NSWindowController subclass init method, I want to call > -loadNibNamed:owner:topLevelObjects, but that requires I have a bundle. I can > get

Re: bundleForClass in Swift

2014-10-18 Thread Graham Cox
On 19 Oct 2014, at 2:25 pm, Rick Mann wrote: > In an NSWindowController subclass init method, I want to call > -loadNibNamed:owner:topLevelObjects, but that requires I have a bundle. I can > get the main bundle, but I'd rather get the bundle for this class (makes it > useable in unit tests).

Re: Subclassing NSWindowController in Swift

2014-10-18 Thread Rick Mann
> On Oct 18, 2014, at 20:33 , Graham Cox wrote: > > According to the latest documentation pack that arrived on Thursday, Swift > has: > > convenience init(windowNibName windowNibName: String, > owner owner: AnyObject) > > So just use this. Like C++, Swift has overloaded method names

Re: bundleForClass in Swift

2014-10-18 Thread Rick Mann
> On Oct 18, 2014, at 20:36 , Graham Cox wrote: > > > On 19 Oct 2014, at 2:25 pm, Rick Mann wrote: > >> In an NSWindowController subclass init method, I want to call >> -loadNibNamed:owner:topLevelObjects, but that requires I have a bundle. I >> can get the main bundle, but I'd rather get t

Re: bundleForClass in Swift

2014-10-18 Thread Graham Cox
On 19 Oct 2014, at 2:43 pm, Rick Mann wrote: > Sorry, I was conflating Obj-C and Swift syntax. I'm trying to do this all in > swift, in which case it's: > > NSBundle(forClass: self.dynamicType) > > But you can't call this in an initializer before calling super init. > Well, I'm not w

Re: bundleForClass in Swift

2014-10-18 Thread Rick Mann
> On Oct 18, 2014, at 20:47 , Graham Cox wrote: > > > On 19 Oct 2014, at 2:43 pm, Rick Mann wrote: > >> Sorry, I was conflating Obj-C and Swift syntax. I'm trying to do this all in >> swift, in which case it's: >> >> NSBundle(forClass: self.dynamicType) >> >> But you can't call this i

NSComboBox in the tab ring

2014-10-18 Thread Luther Baker
Is it possible to keep an NSComboBox in the tabbing ring if I set its "Behavior" to "Selectable". Tabbing reaches the control if the textfield is editable but I don't want to allow the user to type randomly into the text field ... but unfortunately, once I remove its editability, the tabbing cycle

Re: DOMDocument in 10.10

2014-10-18 Thread Gerriet M. Denkmann
> On 19 Oct 2014, at 00:52, Jens Alfke wrote: > > >> On Oct 18, 2014, at 5:33 AM, Gerriet M. Denkmann >> wrote: >> >> Note: the head has only 12 children (the first 10 are identical to 10.9), >> and there is no body at all. > > Weird! Are you sure that the page has finished loading by the

Re: bundleForClass in Swift

2014-10-18 Thread Graham Cox
On 19 Oct 2014, at 2:54 pm, Rick Mann wrote: > You're probably right about that, but in this case, you wouldn't be able to > pass self for owner: True, but since Swift has the other form of init anyway, you don't have to do this yourself... --Graham __

Segue from a toolbar item and prepareForSegue

2014-10-18 Thread Rick Mann
(NB: This is a pure-Swift app, but I don't think that matters here). OS X Storyboard app. I set up a toolbar item with a sheet segue to a view controller. Works fine, but I can't find an appropriate place to put the prepareForSegue() call. The toolbar lives in the window, so I subclassed NSWind

Re: Segue from a toolbar item and prepareForSegue

2014-10-18 Thread Rick Mann
I figured it out. I wasn't able to use "override" when defining my prepareForSegue(), because I renamed the sender: parameter to inSender, not realizing it needed the sender ahead of it. The example code from Apple only had sender: AnyObject?. It was very confusing, because online and in the doc

Re: Subclassing NSWindowController in Swift

2014-10-18 Thread Roland King
> On 19 Oct 2014, at 11:42 am, Rick Mann wrote: > > >> On Oct 18, 2014, at 20:33 , Graham Cox wrote: >> >> According to the latest documentation pack that arrived on Thursday, Swift >> has: >> >> convenience init(windowNibName windowNibName: String, >> owner owner: AnyObject) >> >

Re: Segue from a toolbar item and prepareForSegue

2014-10-18 Thread Roland King
> On 19 Oct 2014, at 2:33 pm, Rick Mann wrote: > > > Also, the background process that handles code completion keeps crashing, so > my code completion was totally borked. Although, the first time it did work, > it put in the override, but failed to put in the named second parameter. > Sourc

Re: Subclassing NSWindowController in Swift

2014-10-18 Thread Rick Mann
> On Oct 18, 2014, at 23:38 , Roland King wrote: > > > The very first of those errors looks like you had the code in the wrong > place, ie not within your class. > > Initialization is one of those Swift things which is uber-safe and thus very > structured and hence in practice annoying. >