Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MVC-N Discussion
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Marcus S. Zarra
March 10, 2016
Technology
8
47k
MVC-N Discussion
A discussion about proper networking in your iOS based application
Marcus S. Zarra
March 10, 2016
Tweet
Share
Other Decks in Technology
See All in Technology
Snowflake Night #2 LT
taromatsui_cccmkhd
0
270
AI Agentにおける評価指標とAgent GPA
tsho
1
240
Master Dataグループ紹介資料
sansan33
PRO
1
4.4k
論文検索を日本語でできるアプリを作ってみた
sailen2
0
140
Claude Cowork Plugins を読む - Skills駆動型業務エージェント設計の実像と構造
knishioka
0
190
20260222ねこIoTLT ねこIoTLTをふりかえる
poropinai1966
0
310
Serverless Agent Architecture on Azure / serverless-agent-on-azure
miyake
1
110
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
6
71k
社内でAWS BuilderCards体験会を立ち上げ、得られた気づき / 20260225 Masaki Okuda
shift_evolve
PRO
1
150
AI Coding Agentの地殻変動 ~ ai-coding.info の定点観測 ~
kotauchisunsun
1
490
dbt meetup #19 『dbtを『なんとなく動かす』を卒業します』
tiltmax3
0
130
LINEヤフーにおけるAI駆動開発組織のプロデュース施策
lycorptech_jp
PRO
0
190
Featured
See All Featured
Between Models and Reality
mayunak
1
210
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
190
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
70
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
GitHub's CSS Performance
jonrohan
1032
470k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
660
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
140
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
240
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.3k
Transcript
Marcus S. Zarra MVC-N
MyUIViewController Network Request Network Request OtherUIViewController Network Request Network Request
ThirdUIViewController Network Request Network Request Controller Layer FourthUIViewController Network Request Network Request Core Data Anti-Pattern
MVCN Network Controller
MVCN MyUIViewController OtherUIViewController ThirdUIViewController FourthUIViewController NetworkController NR NR NR NR
NR NR Core Data The Net
NetworkController NR NR NR NR NR NR Network Controller Dependency
Injection Singleton AppDelegate property class NetworkController: NSObject { } let queue = NSOperationQueue() var mainContext: NSManagedObjectContext? func requestMyData() func requestMyData() -> NSFetchedResultsController func requestMyData(completion: (Void) -> Bool)
NetworkController NR NR NR NR NR NR Network Controller class
MyNetworkRequest: NSOperation { var context: NSManagedObjectContext? init(myParam1: String, myParam2: String) }
class MyNetworkRequest: NSOperation { var context: NSManagedObjectContext? private var innerContext:
NSManagedObjectContext? private var task: NSURLSessionTask? private let incomingData = NSMutableData() init(myParam1: String, myParam2: String) { super.init() //set some parameters here } var internalFinished: Bool = false override var finished: Bool { get { return internalFinished } set (newAnswer) { willChangeValueForKey("isFinished") internalFinished = newAnswer didChangeValueForKey("isFinished") } } }
func URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveResponse response: NSURLResponse, completionHandler: (NSURLSessionResponseDisposition)
-> Void) { if cancelled { finished = true sessionTask?.cancel() return } //Check the response code and react appropriately completionHandler(.Allow) } func URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveData data: NSData) { if cancelled { finished = true sessionTask?.cancel() return } incomingData.appendData(data) }
func URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError error: NSError?) { if
cancelled { finished = true sessionTask?.cancel() return } if error != nil { self.error = error log("Failed to receive response: \(error)") finished = true return } //PROCESS DATA INTO CORE DATA finished = true }
Unit Testing
Network Conditions • Operations can report speeds • Control Performance
via the Queue • Network Controller can react to conditions • Central location for canceling of actions • Single decision point for background processing
Wrap up • Own your network code • Don’t put
network code in view controllers • Keep all network code together • All UI should feed from Core Data • Disconnect data collection and data display
Marcus S. Zarra
[email protected]
http://www.cimgf.com Thank You