Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #THIS IS THE GUIDE TO SWIFT
- # You can always ask for support in the channel #swift
- # this is an part of #opspeakcode runned by V1 and dsr(#swift)
- #this tutorial has been written by dsr also operator in all the #opspeakcode sub channels
- # our channels are part of #opspeakcode
- #java
- #python
- #swift
- #ruby
- #optraining also for pentesting and other hacks related
- #perl
- #javascript
- I recommend you add those channels to auto-join we have always some operators that run support per channel
- 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 ...
- from here on have a good study
- ************************************************************************************************************************GUIDE STARTS HERE
- ----INTRO ----
- swift combines C and objective-C
- So this is a great way to make IOS apps.
- !! 1 Text printing !!
- text printing is like python and is done by :
- print("hello world")
- OUTPUT = hello world
- You can also print a value of a variable:
- print("the value is \(myvariable)")
- If you want nothing else then the value you can type:
- print(myvariable)
- In python # is our comment
- In swift that will be //
- multi-line is with /*....*/
- example :
- //this is a comment
- /* This is a
- MULTI-LINE comment */
- To build apps swift needs xcode downloaded here = ...
- without this IOS will NOT run your program
- ----end intro ----
- ----start section 1 :swift variables----
- We can have variables storing data lets take a look here shall we ?
- a= 42
- | L 42 is the value
- L a is the var
- keyword "var" declares a variable
- I swift you can re-assign the value of a var:
- a = 38
- Now even if we say a = 42 its not because we've changed it now , Thats called re-assignment
- conclusion : The variable is ALWAYS re-assignable
- -------start section 2 :swift constants ------
- You can declare a constant using the keyword "let"
- usage
- let one = 1
- let = constant
- one = name
- 1 = value
- So "let" puts a block on changing the variable.
- you can declare multiple constants on one line
- example
- let x=0.0 , y=0.0 , z=0.0
- so the conclusion is
- Constants are NEVER re-assignable so thats what "let" does.
- If you try it will result an error..
- note : constants and variables can contain
- almost ANY character including Unicode chars
- ------section 3 = TYPE ANNOTATIONS -------
- In swift we have the following types
- -Int : integers
- -double and float : floating-points values
- -bool : boolean
- -string : textual data
- you can use those by using " : "
- example
- var welcome text : string
- welcometext = "hello"
- print(welcometext)
- OUTPUT = <value welcometext>
- I assume you already know what the effect of
- these types are , If you don't ask in our channel #swift / #opspeakcode
- and i will explain , but 80 % knows this so i only spend time for if anyone doesn't know this...
- ------start basic operations part 1 ------
- So we start with 3 operators
- 1.unary
- 2.binary
- 3.ternary
- 1. unary has 1 target (-a)
- 2.binary has 2 targets(4+5)
- 3.ternary has 3 targets( a?b:c )
- YOU WILL UNDERSTAND THESE LATER
- section--assignment operator
- The assignment operator (a=b)
- initializes or updates the value of a with b
- example
- let b = 7
- var a = 42
- a=b
- print(/a)
- OUTPUT = 7
- note: b has the constant so this is not an error because
- var is all alone in our code
- --section arithmetic operators--
- ADDITION 1+2 // equals to 3
- SUBTRACTION 6-2 // equals to 4
- MULTIPLICATION 4*3 // equals to 12
- DIVISION 10.0 / 2.5 // equals to 4.0
- The addition operator is also supported for string concatenation
- "hello," +"world" // outputs hello,world
- --- section remainder operator----
- 9 % 4
- /* outputs 1
- When you do 2*4 its 8
- when 9-8 the remainder is one . */
- var a = 10
- var b = 3
- var c = a % (a-b)
- what will c be ?
- Validate your answer on the irc in channel #swift to DSR and gain VOP status...
- Watch out its just 1 shot that you will have... also no cheating by asking araund on IRC we are in all chans
- we will notice for sure
- -----Increment and decrement ----
- var i = 0 i has been assigned to 1 now
- ++i This also works with --i
- var a = 1 now its been assigned to 3
- a += 2
- /////////// END OF PART 1 BASIC OPERATORS /////////////
- //////////////////////START BASIC OPERATORS PART 2 ///////////////////////////////////////////////////////////////////
- Boolean
- // No comments you just have to learn this
- 1==1 // equal to
- 2!=1 // not equal to
- 2>1 // greater then
- 1<2 // smaller then
- 1>=1 // greater then or equal to
- 2<=1 // smaller then or equal to
- All of those output 'True'
- Try to understand the concept
- -----------------------Ternary conditional operators---------------------------------------
- Ternary conditional operators
- //This is a special oper with 3 parts taking form
- question? answer1:answer2
- exemple--
- gender==0?print("male"):print("female")
- // The above , will evaluate the expression gender==0 if its true it prints 'male'
- otherwise it prints 'female'
- --------------------------------- END OF : Ternary conditional operators -------------------------------
- ---------------------------START OF: Range operators ------------------------------------------------------
- METHOD 1:
- 1...3
- outputs 1,2,3
- --------------
- METHOD 2 :
- 1..<3
- outputs 1,2
- // notice <3 is a hart too , so love swift ;)
- ----------------End range ops-----------------------------------------
- Back on BOOLEAN
- //also here i wont say too much its all just practice
- NOT : if "true " its printed "false"
- AND : The 2 conditions have to be "true"
- OR : One of the 2 have to be "true"
- // The usage of this , opens a SQLi vulnerability , its an important function but
- Absolutely dont use this on login forms , search an alternative...
- You can use it on php so its reducing its vulns but still its a fact that any login form can be manipulated
- ------------Optionals
- //Used in situations in which a value may be ABSENT
- /* it tells
- --theres a value and its equal to x
- OR
- -- There isnt a value
- */
- --exemple--
- var mycode : int?=404
- ------- 2
- var mycode : int?=404
- mycode = nil
- //mycode now contains NO VALUE
- var somemsg : string ?
- //contains automaticly no value or nil
- ////////////////////////////////////////////////////////////END BASICS PART 2 //////////////////////////////
- --add link to xcode
- //request in channel please
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement