Skip to content

Instantly share code, notes, and snippets.

@kiok46
Last active June 29, 2016 13:30
Show Gist options
  • Save kiok46/53efe5d0a317f76531ebc3709c028790 to your computer and use it in GitHub Desktop.
Save kiok46/53efe5d0a317f76531ebc3709c028790 to your computer and use it in GitHub Desktop.
## Objective-C implementation
- (void)updateScanTab
{
NSError *err = nil;
NSDictionary *params = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:([mergeScanResultsCheckbox state] == NSOnState)] forKey:kCWScanKeyMerge];
self.scanResults = [NSMutableArray arrayWithArray:[self.currentInterface scanForNetworksWithParameters:params error:&err]];
if( err )
[[NSAlert alertWithError:err] runModal];
else
[self.scanResults sortUsingDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"ssid" ascending:YES selector:@selector (caseInsensitiveCompare:)] autorelease]]];
[scanResultsTable reloadData];
}
## Python Implementation
from pyobjus import autoclass
CWInterface = autoclass('CWInterface')
CWConfiguration = autoclass('CWConfiguration')
CWNetwork = autoclass('CWNetwork')
NSMutableArray = autoclass('NSMutableArray')
CWChannel = autoclass('CWChannel')
CWWiFiClient = autoclass('CWWiFiClient')
NSSortDescriptor = autoclass('NSSortDescriptor')
NSArray = autoclass('NSArray')
NSDictionary = autoclass('NSDictionary')
NSNumber = autoclass('NSNumber')
def test():
c = CWInterface.interface()
#NSSortDescriptor.alloc().init("ssid")
param = NSDictionary.dictionaryWithObject_forKey_(NSNumber.numberWithBool_(), "kCWScanKeyMerge")
foo(NSNumber, "")
scan = c.scanForNetworksWithParameters_error_(param, None)
scan_result = NSMutableArray.arrayWithArray_(scan)
#ns = NSMutableArray.arrayWithArray_(scan)
#print ns
print scan_result.sortedArrayUsingDescriptors_(NSArray.arrayWithObject_(NSSortDescriptor.alloc().init("ssid"))).autorelease
def foo(name, string):
matching = []
matching = [s for s in dir(name) if "{}".format(string) in s]
for m in matching:
print m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment