ios - How to talk with main thread swift files to access main thread variables -


i experienced android dev new ios dev using swift. right have setup uiwebview , nsurlprotocol using caninitwithrequest (2 separate swift files). caninitwithrequest method works great need acccess uiwebview object in order call functions on uiwebview object.

for example. if request == google.com uiwebview.something().

in android in order talk main activity thread create interface, implement in main thread , have access on main activity class.

thanks help.

you may looking method -webview(_:shouldstartloadwithrequest:navigationtype:) in uiwebviewdelegate protocol.

by implementing interface, can have different object (e.g. object in "separate swift file") determine whether or not load nsurlrequest , run custom behavior first:

extension myobject: uiwebviewdelegate {     func webview(webview: uiwebview, shouldstartloadwithrequest request: nsurlrequest, navigationtype: uiwebviewnavigationtype) -> bool {         if request.url == nsurl(string: "google.com") {             // custom behavior...             webview.something()         }         // allow webview load request         return true     } } 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -