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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Marcus S. Zarra
March 10, 2016
Technology
47k
8
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
MVC-N Discussion
A discussion about proper networking in your iOS based application
Marcus S. Zarra
March 10, 2016
Other Decks in Technology
See All in Technology
金融の未来を考える / Thinking About the Future of Finance
ks91
PRO
0
110
Text-to-SQLをAgentCoreで実現し、生成されるSQLの精度を定量的に評価する
yakumo
2
390
AWS Summit Japan 2026の振り返りと2027へ向けて / AWS Summit Japan 2026 Recap and Prospects for 2027
kaminashi
1
170
4人目のSREはAgent
tanimuyk
0
360
ゼロをイチにする仕事が終わったあと
smasato
0
190
作る力から、見極める力へ — AI時代に広がるエンジニアの価値と役割
rince
0
390
From Prompt Engineering to Loop Engineering
shibuiwilliam
1
320
從觀望到全公司落地:AI Agentic Coding 導入實戰 — 流程整合與安全治理
appleboy
1
510
攻撃者がいなくてもAIエージェントはインシデントを起こす
nomizone
0
180
GitHub Copilot運用のリアル ~AI Credit時代にどう向き合うか~
takafumisu2uk1
0
600
感情と身体を置き去りにしない、エンジニアの生きのこり方 ──いまから、ここから「自分の状態」を扱うという選択
saorimurooka
1
450
FinOps X 2026 Recap from Engineer Side #JapanFinOps
chacco38
0
240
Featured
See All Featured
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.1k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
67
56k
A designer walks into a library…
pauljervisheath
211
24k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Six Lessons from altMBA
skipperchong
29
4.3k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
350
Mobile First: as difficult as doing things right
swwweet
225
10k
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