Difference between revisions of "Swift"

From Lost In Wonderlands
Jump to: navigation, search
(U)
(P)
 
(22 intermediate revisions by the same user not shown)
Line 173: Line 173:
 
== B ==
 
== B ==
 
== C ==
 
== C ==
 +
 +
=== Compiler Directives ===
 +
* constants for Apple Platforms OS
 +
  iOS , tvOS, macOS, watchOS, iPadOS (should be this for iPad)
 +
 +
* directive model
 +
  #if os(iOS) || os(tvOS)
 +
      ...
 +
  #elseif (os(macOS)
 +
    ...
 +
  #endif
 +
 +
* In #if compiler directive in Swift, you need to enclosed '''valid statements'''.
 +
 +
 +
 +
You may need to write something like this:
 +
 +
  #if os(iOS)
 +
      var body: some View {
 +
          NavigationView{
 +
              ...
 +
          }
 +
          .navigationViewStyle(StackNavigationViewStyle())
 +
      }
 +
  #else
 +
      var body: some View {
 +
          NavigationView{
 +
                ...
 +
          }
 +
        .navigationViewStyle(DoubleColumnNavigationViewStyle())
 +
      }
 +
  #endif
 +
 +
Or this:
 +
  var body: some View {
 +
      let navView = NavigationView{
 +
      ...
 +
  }
 +
  #if os(iOS)
 +
      return navView
 +
      .navigationViewStyle(StackNavigationViewStyle())
 +
  #else
 +
      return navView
 +
      .navigationViewStyle(DoubleColumnNavigationViewStyle())
 +
  #endif
 +
  }
 +
 +
but not  this:  As you can see, ''.navigationViewStyle(StackNavigationViewStyle())'' is not a '''valid statement'''.
 +
      NavigationView {
 +
          ...
 +
      }
 +
  #if os(iOS)
 +
      .navigationViewStyle(StackNavigationViewStyle())
 +
  #endif
 +
 
== D ==
 
== D ==
 +
 +
=== Do, Try /Catch ===
 +
* https://stackoverflow.com/questions/30720497/swift-do-try-catch-syntax
 +
 
== E ==
 
== E ==
 
== F ==
 
== F ==
 
== G ==
 
== G ==
 
== H ==
 
== H ==
 +
 +
=== HTTPCookieStorage ===
 +
* https://developer.apple.com/documentation/foundation/httpcookiestorage
  
 
== I ==
 
== I ==
Line 189: Line 252:
  
 
== J ==
 
== J ==
 +
 +
=== JSONDecoder ===
 +
* https://developer.apple.com/documentation/foundation/jsondecoder
 +
 +
=== JSONEncoder ===
 +
* https://developer.apple.com/documentation/foundation/jsonencoder
 +
 +
=== JSONSerialisation ===
 +
* https://developer.apple.com/documentation/foundation/jsonserialization
 +
 
== K ==
 
== K ==
 
== L ==
 
== L ==
Line 214: Line 287:
 
* https://www.browserstack.com/question/663
 
* https://www.browserstack.com/question/663
 
* https://learnappmaking.com/urlsession-swift-networking-how-to/
 
* https://learnappmaking.com/urlsession-swift-networking-how-to/
* https://www.appsdeveloperblog.com/http-get-request-example-in-swift/  
+
* https://www.appsdeveloperblog.com/http-get-request-example-in-swift/
 +
 
 +
 
 +
=== NSURLConnection ===
 +
* https://developer.apple.com/documentation/foundation/nsurlconnection
 +
 
 
== O ==
 
== O ==
 
== P ==
 
== P ==
 +
 +
* print
 +
* debugPrint
 +
 +
special print keywords
 +
 +
* https://docs.swift.org/swift-book/ReferenceManual/Expressions.html#ID390
 +
 +
Literal        Type    Value
 +
{| class="wikitable" border="1"
 +
|-
 +
! Tag
 +
! Type
 +
! Description
 +
|-
 +
| #file
 +
| String
 +
| The name of the file in which it appears.
 +
|-
 +
| #fileID
 +
| String
 +
| The name of the file and module in which it appears.
 +
|-
 +
| #filePath
 +
| String
 +
| The path to the file in which it appears.
 +
|-
 +
| #line
 +
| int
 +
| The line number on which it appears.
 +
|-
 +
| #column
 +
| Int
 +
| The column number in which it begins.
 +
|-
 +
| #function
 +
| String
 +
| The name of the declaration in which it appears.
 +
|-
 +
| #dsohandle
 +
| UnsafeMutablePointer
 +
| The dso handle.
 +
|}
 +
 
== Q ==
 
== Q ==
 
== R ==
 
== R ==
Line 233: Line 355:
 
== S ==
 
== S ==
 
== T ==
 
== T ==
 +
 +
=== try /catch ===
 +
* https://www.hackingwithswift.com/example-code/language/how-to-use-try-catch-in-swift-to-handle-exceptions
 +
 
== U ==
 
== U ==
 +
 +
=== URl Cache ===
 +
* https://developer.apple.com/documentation/foundation/urlcache
 +
 +
=== URLSessionConfiguration ===
 +
* https://developer.apple.com/documentation/foundation/urlsessionconfiguration/
 +
* https://useyourloaf.com/blog/urlsessionconfiguration-quick-guide/
 +
* https://stackoverflow.com/questions/45785458/swift-urlsessionconfiguration
 +
 
=== URLComponents, how to build a safe escaped url /uri ===
 
=== URLComponents, how to build a safe escaped url /uri ===
 
* https://www.swiftbysundell.com/articles/constructing-urls-in-swift/
 
* https://www.swiftbysundell.com/articles/constructing-urls-in-swift/
Line 243: Line 378:
 
* https://www.raywenderlich.com/7565482-visually-rich-links-tutorial-for-ios-image-thumbnails
 
* https://www.raywenderlich.com/7565482-visually-rich-links-tutorial-for-ios-image-thumbnails
 
* https://developer.apple.com/forums/thread/666662
 
* https://developer.apple.com/forums/thread/666662
 
  
 
==== sample code ====
 
==== sample code ====
 
* https://github.com/PerfectExamples/Perfect-URL-Shortener
 
* https://github.com/PerfectExamples/Perfect-URL-Shortener
 
* https://github.com/swisspol/GCDWebServer
 
* https://github.com/swisspol/GCDWebServer
 +
 +
=== URLCredentielStorage ===
 +
* https://developer.apple.com/documentation/foundation/urlcredentialstorage
  
 
=== URLRequest ===
 
=== URLRequest ===
Line 253: Line 390:
 
* https://cocoacasts.com/networking-fundamentals-how-to-make-an-http-request-in-swift
 
* https://cocoacasts.com/networking-fundamentals-how-to-make-an-http-request-in-swift
 
* https://stackoverflow.com/questions/24016142/how-do-i-make-an-http-request-in-swift
 
* https://stackoverflow.com/questions/24016142/how-do-i-make-an-http-request-in-swift
 
=== URLConfiguration ===
 
* https://developer.apple.com/documentation/foundation/urlsessionconfiguration/
 
 
  
 
=== URLSession ===
 
=== URLSession ===
 
* https://developer.apple.com/documentation/foundation/urlsession
 
* https://developer.apple.com/documentation/foundation/urlsession
 +
* https://developer.apple.com/documentation/foundation/urlsession/1409000-shared
 
* https://www.raywenderlich.com/3244963-urlsession-tutorial-getting-started
 
* https://www.raywenderlich.com/3244963-urlsession-tutorial-getting-started
 
* https://learnappmaking.com/urlsession-swift-networking-how-to/
 
* https://learnappmaking.com/urlsession-swift-networking-how-to/
Line 265: Line 399:
 
* hhttps://cocoacasts.com/networking-in-swift-meet-the-urlsession-family
 
* hhttps://cocoacasts.com/networking-in-swift-meet-the-urlsession-family
 
* https://stackoverflow.com/questions/41600446/urlsession-best-practice-multiple-requests
 
* https://stackoverflow.com/questions/41600446/urlsession-best-practice-multiple-requests
 +
* https://www.appsdeveloperblog.com/http-get-request-example-in-swift/
 +
 +
=== Using JSON with custom Type ===
 +
* https://developer.apple.com/documentation/foundation/archives_and_serialization/using_json_with_custom_types
  
 
== V ==
 
== V ==
Line 298: Line 436:
 
* https://github.com/depoon/SwiftLocalhost
 
* https://github.com/depoon/SwiftLocalhost
 
* https://github.com/Alamofire/Alamofire
 
* https://github.com/Alamofire/Alamofire
 +
 +
 +
=== samples ===
 +
* https://www.appsdeveloperblog.com/swift-code-examples/
  
 
== Articles==
 
== Articles==
  
 
== Blogs ==
 
== Blogs ==
 +
* https://www.appsdeveloperblog.com/
  
 
== Tools link ==
 
== Tools link ==

Latest revision as of 10:53, 3 May 2022

Contents

Swift

See also

Swift

Swift Topics

Data Flow and Control Flow

Data Modeling

Language Interoperability

Class Bridging
Swift and Objective C and C


Cocoa Design Patterns and Swift

Swift with Style

Swift API design

Swift Standard Library

Swift protocols

protocols conformance

protocols

Swift Generics


Swift Patterns

 https://github.com/ochococo/Design-Patterns-In-Swift


Swift Algorithms

more algorithms

in python

in C++


tutorials

forums

books


Topics

A

Application Transport Security

B

C

Compiler Directives

  • constants for Apple Platforms OS
 iOS , tvOS, macOS, watchOS, iPadOS (should be this for iPad)
  • directive model
 #if os(iOS) || os(tvOS)
     ...
 #elseif (os(macOS)
    ...
 #endif
  • In #if compiler directive in Swift, you need to enclosed valid statements.


You may need to write something like this:

 #if os(iOS)
     var body: some View {
         NavigationView{
              ...
         }
         .navigationViewStyle(StackNavigationViewStyle())
     }
 #else
      var body: some View {
          NavigationView{
                ...
         }
        .navigationViewStyle(DoubleColumnNavigationViewStyle())
      }
 #endif

Or this:

 var body: some View {
      let navView = NavigationView{
      ...
  }
  #if os(iOS)
      return navView
      .navigationViewStyle(StackNavigationViewStyle())
  #else
      return navView
      .navigationViewStyle(DoubleColumnNavigationViewStyle())
  #endif
  }

but not this: As you can see, .navigationViewStyle(StackNavigationViewStyle()) is not a valid statement.

     NavigationView {
         ...
     }
 #if os(iOS)			
     .navigationViewStyle(StackNavigationViewStyle())
 #endif

D

Do, Try /Catch

E

F

G

H

HTTPCookieStorage

I

issues with REST and URLSession

J

JSONDecoder

JSONEncoder

JSONSerialisation

K

L

M

N

NSAppTransportSecurity

https://stackoverflow.com/questions/8023126/how-can-i-test-https-connections-with-django-as-easily-as-i-can-non-https-connec https://gist.github.com/claudiosanches/7012524 https://www.google.com/search?client=safari&rls=en&q=ios++swift+url+maker+and+localhost++plus+port+number&ie=UTF-8&oe=UTF-8 https://github.com/depoon/SwiftLocalhost

  • mostly on a simulator to access a http://localhost:portnum/service hosted on the same host
  • IOS reinforce the access to HTTPS only since ioS 7
  • for sometime it was possible to grant htpp access in the info plist but now we have to grant more things
<key>NSAppTransportSecurity</key>
   <dict>
       <key>NSAllowsArbitraryLoads</key>
       <true/>
   </dict>
  • local host or 127.0.0.1
var rest_url = "http://127.0.0.1:8000/rest/users/"


NSURLConnection

O

P

  • print
  • debugPrint

special print keywords

Literal Type Value

Tag Type Description
#file String The name of the file in which it appears.
#fileID String The name of the file and module in which it appears.
#filePath String The path to the file in which it appears.
#line int The line number on which it appears.
#column Int The column number in which it begins.
#function String The name of the declaration in which it appears.
#dsohandle UnsafeMutablePointer The dso handle.

Q

R

REST API call

testing it using curl

sample code

S

T

try /catch

U

URl Cache

URLSessionConfiguration

URLComponents, how to build a safe escaped url /uri

sample code

URLCredentielStorage

URLRequest

URLSession

Using JSON with custom Type

V

W

X

Y

Z

swift versions

WWDC 2020

WWDC2019

WWDC 2018

WWDC 2017

WWDC 2016

Sample codes

Apple on GitHub for swift

Rest API


samples

Articles

Blogs

Tools link

Books

Trainings