Advertisement
--DSR--

ULTIMATE GUIDE TO #SWIFT BY DSR

Apr 15th, 2017
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.62 KB | None | 0 0
  1. #THIS IS THE GUIDE TO SWIFT
  2. # You can always ask for support in the channel #swift
  3. # this is an part of #opspeakcode runned by V1 and dsr(#swift)
  4. #this tutorial has been written by dsr also operator in all the #opspeakcode sub channels
  5. # our channels are part of #opspeakcode
  6. #java
  7. #python
  8. #swift
  9. #ruby
  10. #optraining also for pentesting and other hacks related
  11. #perl
  12. #javascript
  13.  
  14. I recommend you add those channels to auto-join we have always some operators that run support per channel
  15. V1 is the owner of all the #opspeakcode chans and DSR is the writer of this Guide and also founder of #swift and operator in all the channels ...
  16.  
  17.  
  18. from here on have a good study
  19.  
  20. ************************************************************************************************************************GUIDE STARTS HERE
  21. ----INTRO ----
  22.  
  23.  
  24. swift combines C and objective-C
  25. So this is a great way to make IOS apps.
  26.  
  27. !! 1 Text printing !!
  28.  
  29. text printing is like python and is done by :
  30.  
  31.  
  32.  
  33. print("hello world")
  34.  
  35. OUTPUT = hello world
  36.  
  37.  
  38. You can also print a value of a variable:
  39.  
  40. print("the value is \(myvariable)")
  41.  
  42. If you want nothing else then the value you can type:
  43.  
  44.  
  45. print(myvariable)
  46.  
  47.  
  48. In python # is our comment
  49. In swift that will be //
  50. multi-line is with /*....*/
  51. example :
  52.  
  53. //this is a comment
  54.  
  55. /* This is a
  56. MULTI-LINE comment */
  57.  
  58. To build apps swift needs xcode downloaded here = ...
  59. without this IOS will NOT run your program
  60.  
  61. ----end intro ----
  62. ----start section 1 :swift variables----
  63.  
  64. We can have variables storing data lets take a look here shall we ?
  65.  
  66. a= 42
  67. | L 42 is the value
  68. L a is the var
  69.  
  70. keyword "var" declares a variable
  71.  
  72. I swift you can re-assign the value of a var:
  73.  
  74. a = 38
  75.  
  76. Now even if we say a = 42 its not because we've changed it now , Thats called re-assignment
  77.  
  78. conclusion : The variable is ALWAYS re-assignable
  79.  
  80. -------start section 2 :swift constants ------
  81. You can declare a constant using the keyword "let"
  82. usage
  83.  
  84. let one = 1
  85.  
  86. let = constant
  87. one = name
  88. 1 = value
  89.  
  90. So "let" puts a block on changing the variable.
  91.  
  92. you can declare multiple constants on one line
  93. example
  94.  
  95. let x=0.0 , y=0.0 , z=0.0
  96.  
  97. so the conclusion is
  98.  
  99. Constants are NEVER re-assignable so thats what "let" does.
  100. If you try it will result an error..
  101.  
  102. note : constants and variables can contain
  103. almost ANY character including Unicode chars
  104.  
  105. ------section 3 = TYPE ANNOTATIONS -------
  106. In swift we have the following types
  107. -Int : integers
  108. -double and float : floating-points values
  109. -bool : boolean
  110. -string : textual data
  111.  
  112. you can use those by using " : "
  113.  
  114. example
  115.  
  116. var welcome text : string
  117. welcometext = "hello"
  118. print(welcometext)
  119.  
  120.  
  121. OUTPUT = <value welcometext>
  122.  
  123. I assume you already know what the effect of
  124. these types are , If you don't ask in our channel #swift / #opspeakcode
  125. and i will explain , but 80 % knows this so i only spend time for if anyone doesn't know this...
  126.  
  127. ------start basic operations part 1 ------
  128.  
  129. So we start with 3 operators
  130. 1.unary
  131. 2.binary
  132. 3.ternary
  133.  
  134. 1. unary has 1 target (-a)
  135. 2.binary has 2 targets(4+5)
  136. 3.ternary has 3 targets( a?b:c )
  137. YOU WILL UNDERSTAND THESE LATER
  138.  
  139.  
  140. section--assignment operator
  141.  
  142. The assignment operator (a=b)
  143. initializes or updates the value of a with b
  144.  
  145. example
  146.  
  147. let b = 7
  148. var a = 42
  149. a=b
  150. print(/a)
  151.  
  152. OUTPUT = 7
  153.  
  154. note: b has the constant so this is not an error because
  155. var is all alone in our code
  156.  
  157. --section arithmetic operators--
  158.  
  159. ADDITION 1+2 // equals to 3
  160. SUBTRACTION 6-2 // equals to 4
  161. MULTIPLICATION 4*3 // equals to 12
  162. DIVISION 10.0 / 2.5 // equals to 4.0
  163.  
  164. The addition operator is also supported for string concatenation
  165. "hello," +"world" // outputs hello,world
  166.  
  167. --- section remainder operator----
  168.  
  169. 9 % 4
  170.  
  171. /* outputs 1
  172. When you do 2*4 its 8
  173. when 9-8 the remainder is one . */
  174.  
  175. var a = 10
  176. var b = 3
  177. var c = a % (a-b)
  178.  
  179. what will c be ?
  180.  
  181. Validate your answer on the irc in channel #swift to DSR and gain VOP status...
  182. Watch out its just 1 shot that you will have... also no cheating by asking araund on IRC we are in all chans
  183. we will notice for sure
  184.  
  185. -----Increment and decrement ----
  186.  
  187. var i = 0 i has been assigned to 1 now
  188. ++i This also works with --i
  189.  
  190.  
  191.  
  192. var a = 1 now its been assigned to 3
  193. a += 2
  194.  
  195.  
  196. /////////// END OF PART 1 BASIC OPERATORS /////////////
  197.  
  198. //////////////////////START BASIC OPERATORS PART 2 ///////////////////////////////////////////////////////////////////
  199.  
  200. Boolean
  201. // No comments you just have to learn this
  202.  
  203. 1==1 // equal to
  204. 2!=1 // not equal to
  205. 2>1 // greater then
  206. 1<2 // smaller then
  207. 1>=1 // greater then or equal to
  208. 2<=1 // smaller then or equal to
  209.  
  210. All of those output 'True'
  211. Try to understand the concept
  212.  
  213. -----------------------Ternary conditional operators---------------------------------------
  214.  
  215. Ternary conditional operators
  216.  
  217. //This is a special oper with 3 parts taking form
  218.  
  219. question? answer1:answer2
  220.  
  221. exemple--
  222.  
  223. gender==0?print("male"):print("female")
  224.  
  225.  
  226. // The above , will evaluate the expression gender==0 if its true it prints 'male'
  227. otherwise it prints 'female'
  228.  
  229. --------------------------------- END OF : Ternary conditional operators -------------------------------
  230. ---------------------------START OF: Range operators ------------------------------------------------------
  231.  
  232. METHOD 1:
  233.  
  234. 1...3
  235.  
  236. outputs 1,2,3
  237.  
  238. --------------
  239. METHOD 2 :
  240.  
  241. 1..<3
  242.  
  243. outputs 1,2
  244.  
  245. // notice <3 is a hart too , so love swift ;)
  246.  
  247. ----------------End range ops-----------------------------------------
  248.  
  249. Back on BOOLEAN
  250.  
  251. //also here i wont say too much its all just practice
  252.  
  253. NOT : if "true " its printed "false"
  254. AND : The 2 conditions have to be "true"
  255. OR : One of the 2 have to be "true"
  256.  
  257. // The usage of this , opens a SQLi vulnerability , its an important function but
  258. Absolutely dont use this on login forms , search an alternative...
  259. You can use it on php so its reducing its vulns but still its a fact that any login form can be manipulated
  260.  
  261.  
  262. ------------Optionals
  263.  
  264. //Used in situations in which a value may be ABSENT
  265.  
  266. /* it tells
  267.  
  268. --theres a value and its equal to x
  269. OR
  270. -- There isnt a value
  271.  
  272. */
  273.  
  274. --exemple--
  275. var mycode : int?=404
  276.  
  277. ------- 2
  278.  
  279. var mycode : int?=404
  280. mycode = nil
  281.  
  282. //mycode now contains NO VALUE
  283.  
  284. var somemsg : string ?
  285.  
  286. //contains automaticly no value or nil
  287.  
  288. ////////////////////////////////////////////////////////////END BASICS PART 2 //////////////////////////////
  289. --add link to xcode
  290. //request in channel please
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement