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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
もう怖くないバックグラウンド処理 Background Tasks のすべて - Hakodate.swift #1
kantacky
0
230
【Developers Summit 2026】Memory Is All You Need:コンテキストの「最適化」から「継続性」へ ~RAGを進化させるメモリエンジニアリングの最前線~
shisyu_gaku
5
840
Eight Engineering Unit 紹介資料
sansan33
PRO
1
6.8k
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
6
71k
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
15
95k
Snowflakeデータ基盤で挑むAI活用 〜4年間のDataOpsの基礎をもとに〜
kaz3284
1
290
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
43k
研究開発部メンバーの働き⽅ / Sansan R&D Profile
sansan33
PRO
4
22k
Databricksアシスタントが自分で考えて動く時代に! エージェントモード体験もくもく会
taka_aki
0
210
トラブルの大半は「言ってない」x「言ってない」じゃねーか!!
ichimichi
0
210
primeNumber DATA MANAGEMENT CAMP #2:
masatoshi0205
1
640
競争優位を生み出す戦略的内製開発の実践技法
masuda220
PRO
2
500
Featured
See All Featured
Site-Speed That Sticks
csswizardry
13
1.1k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
110
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
360
A designer walks into a library…
pauljervisheath
210
24k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
970
[SF Ruby Conf 2025] Rails X
palkan
2
800
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
What's in a price? How to price your products and services
michaelherold
247
13k
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