Posts

ios - Using a Swift String with NSData without NSString -

is possible init swift string (not nsstring ) contents of nsdata object without creating nsstring first? i know can use nsstring: var datastring = nsstring(data data: nsdata!, encoding encoding: uint) but how can use basic swift string type? thought swift strings , nsstrings interchangeable, have data out of nsdata using nsstring , assign value swift string? as of swift 1.2 aren't quite interchangeable, convertible, there's no reason not use nsstring , constructors when need to. work fine: var datastring = nsstring(data:data, encoding:nsutf8stringencoding) as! string the as! needed because nsstring(...) can return nil invalid input - if aren't sure data represents valid utf8 string, may wish use following instead return string? (aka optional<string> ). var datastring = nsstring(data:data, encoding:nsutf8stringencoding) string? once constructed, can use datastring other swift string, e.g. var foo = datastring + "some other string...

php - Need to explode and string and make it as key value pairs -

i have data [0] => 1#*#1-1 my requirement explode #*# , have make generated array elements key value pairs example $data = explode("#*#",'1#*#1-1'); $data[0] =1; $data[1] = 1-1; requirement make dynamic associative array array($data[1] => $data[0]) <? $str = '1#*#1-1 3#*#1-2 5#*#1-3 7#*#1-4 9#*#1-5 11#*#1-6 13#*#1-7 15#*#1-8 17#*#1-9 19#*#1-10 2#*#2-1 4#*#2-2 6#*#2-3 8#*#2-4 10#*#2-5 12#*#2-6 14#*#2-7 16#*#2-8 18#*#2-9'; $ex = array_map('trim',explode("\n",$str)); $out = array(); foreach($ex $e){ $ex2 = explode('#*#',$e); $out[$ex2[1]] = $ex2[0]; } print_r($out); array ( [1-1] => 1 [1-2] => 3 [1-3] => 5 [1-4] => 7 [1-5] => 9 [1-6] => 11 [1-7] => 13 [1-8] => 15 [1-9] => 17 [1-10] => 19 [2-1] => 2 [2-2] => 4 [2-3] =...

Array as a dictionary value in swift language -

i have following swift dictionary var list = [ 2543 : [ "book", "pen" ], 2876 : [ "school", "house"] ] how can access array values ? println(list[2543][0]) the above code gives error "could not find member subscript" and should print "book" note subscript returns optional. have force unwrapping: println(list[2543]![0]) or use optional chaining println(list[2543]?[0])

c++ - How to get all ones or all zeros from boolean result? -

i (stupidly) thought if took boolean result of true, cast int , left-shifted end lsb repeated @ every bit, not! if had boolean result , wanted convert ones true , zeros false, cheapest way (computationally) this? bool result = x == y; unsigned int x = 0; //x becomes ones when result true //x becomes zeros when result false like this, perhaps: bool result = x == y; unsigned int z = -result;

bash - shell script pattern matching -

need on shell script. i have following result in file name-label ( rw) : host1 networks (mro): 1/ip: 192.168.1.2; 0/ip: 192.168.1.10 name-label ( rw) : host2 networks (mro): 1/ip: 192.168.1.15; 1/ipv6/0: fe80::9060:b6ff:fec1:7bbb; 0/ip: 192.168.1.20; 0/ipv6/0: fe80::286d:7cff:fefe:3ed7 i want hostname , corresponding 0/ip value file. final output be host1 192.168.1.10 host2 192.168.1.20 perl solution: perl -ne '/^name-label .*: (.+)/ , $name = $1; m(0/ip: ([0-9.]+)) , print "$name $1\n"' name-label stored in variable, it's printed ip when processing next line.

Flash Error #1009: Cannot access a property or method of a null object referencee -

my flash professional cc showing error simple alert code. have tried solve reading discussed on website unable solve it. error : typeerror: error #1009: cannot access property or method of null object reference. @ mx.controls::alert$/show()[/users/aharui/flex-sdk-4.12.1/frameworks/projects/mx/src/mx/controls/alert.as:574] @ alerttest()[d:\summer project\practice\alerttest.as:7] can suggest reason, here code!! package { import flash.display.sprite; import mx.controls.alert; public class alerttest extends sprite { public function alerttest() { alert.show("would exit application?", "confirm", alert.yes | alert.no | alert.cancel); trace("hey"); } } } before getting error 1046 : type not found or compile time constant.. so installed flex skd 4.12.1 in folder , included library path in action settings fla file. after doing landed getting error. kindly suggest. the mx alert class flex framework , can't...

Android Camera unlock mediarecorder -

i want write app records video through smartphone camera. found website : http://developer.android.com/guide/topics/media/camera.html#custom-camera im using source code started. my main activity : public class mainactivity extends activity { protected static final string tag = null; private camera mcamera; private camerapreview mpreview; private mediarecorder mmediarecorder=null; public static final int media_type_image = 1; public static final int media_type_video = 2; private boolean isrecording = false; /** safe way instance of camera object. */ public static camera getcamerainstance(){ camera c = null; try { c = camera.open(); // attempt camera instance } catch (exception e){ // camera not available (in use or not exist) } return c; // returns null if camera unavailable } @overr...