-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Visualize currently running applications by name #9
Conversation
cd7a178
to
7d1bae4
Compare
c0065ba
to
3eb33af
Compare
#import <Cocoa/Cocoa.h> | ||
|
||
@interface ProcessController : NSObject | ||
@property (weak, readonly) NSWorkspace *workspace; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weak:
Keeps a pointer to the object so long as it exists. When it is deallocated, pointer is set to nil automatically.
Readonly
Only generate a getter, no setter. Will warn you if you try to change this property.
NSWorkspace
Can launch apps and handle file services. There is one shared workspace within the entire app.
|
||
@interface ProcessController : NSObject | ||
@property (weak, readonly) NSWorkspace *workspace; | ||
@property(weak, readonly) NSArray *sortDescriptors; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorts an array as part of arrangeObjects
.
|
||
@implementation ProcessController | ||
|
||
- (void)applicationDidBecomeActive:(NSNotification *)notification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tells the delegate that the app has become active.
|
||
- (void)applicationDidBecomeActive:(NSNotification *)notification | ||
{ | ||
[self.arrayOfRunningProcesses rearrangeObjects]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rearrangeObjects
is a method that calls arrangeObjects
which returns an array containing filtered and sorted (sortDescriptors
) objects.
NSLog(@"Array: %@", _arrayOfRunningProcesses); | ||
} | ||
|
||
- (NSWorkspace *)workspace; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Workspaces are used to launch apps and perform file services.
|
||
- (NSWorkspace *)workspace; | ||
{ | ||
return [NSWorkspace sharedWorkspace]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can call sharedWorkspace
from anywhere in the app, so it is needed to bind to the UI.
Part of this issue #5
What does this do?
This displays all of the currently running processes on the computer. This only displays them by name in list form. We can access more data such as PID with
processIdentifier
in a follow up PR.How does it work?
Why do we have to declare class instances in the header?
NSWorkspace is a class that handles apps and file services. runningApplications is an instance property of this class. These cannot be used in the storyboard, so we put them in the header and pass pointers of these instances to the
ProcessController.m
file.Component:
This makes use of the
Table view
component. The process list is generated fromlocalizedName
which returns the name of the application.Attaching the controller to the component:
These are the steps I took to connect the functions in the
ProcessController
to the table component.IMPORTANT NOTES:
Notice how I named the table column
ProcessNamesColumn
. This cannot happen. You must name the columns based on the data they are going to hold. So in our situation, we want to hold the names of the processes. If we look at theNSRunningApplication
, you'll notice that it has alocalizedName
attribute. This returns the localized name of the application.To access the currently running process data, you must use the
NSWorkspace
class. This will give you access torunningApplications
, so you must useworkspace.runningApplications
on the content bindings (screenshots are wrong and should be corrected, this is case sensitive).1. Add the
Table view
component to the scene.The view stack should look as follows:
2. Create an object for the process controller:
3. Create an
array controller
:4. Outlet
arrayOfRunningProcesses
to the newly created array controller5. Bind the value of
arrayOfRunningProcesses
to the table column:This is on the table column:
Note the following referencing binding on the array controller class:
6. Connect the table's delegate to our Process Controller object:
7. Create content array bindings on the Array Of Running Processes class: