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
SBJson 4: Don't make me wait!
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Stig Brautaset
March 05, 2014
Programming
420
0
Share
SBJson 4: Don't make me wait!
How SBJson 4 can help you get happy users.
Stig Brautaset
March 05, 2014
More Decks by Stig Brautaset
See All by Stig Brautaset
Delighting your users with SBJson 4
stig
1
1.3k
Other Decks in Programming
See All in Programming
AI駆動開発勉強会 広島支部 第一回勉強会 AI駆動開発概要とワークショップ
hayatoshimiu
0
250
1人1案件のプロダクトエンジニア時代に、"プロセス監督"としてチャレンジしたこと
non0113
0
130
AI時代だからこそ「Bloc」を採用する価値があるのかもしれない
takuroabe
0
200
iOS26時代の新規アプリ開発
yuukiw00w
0
160
関係性から理解する"同一性"の型用語たち
pvcresin
2
250
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
400
空間オーディオの活用
objectiveaudio
0
160
How We Practice Exploratory Testing in Iterative Development( #scrumniigata ) / 反復開発の中で、探索的テストをどう実施しているか
teyamagu
PRO
3
980
GoogleCloudとterraform完全に理解した
terisuke
1
200
Structured Concurrency, Scoped Values and Joiners in the JDK 25 26 27
josepaumard
1
160
Spec-Driven Development with AI Agents (Workshop, May 2026)
antonarhipov
3
400
ふにゃっとしない名前の付け方 〜哲学で茹で上げる、コシのあるソフトウェア設計〜
shimomura
0
120
Featured
See All Featured
Building an army of robots
kneath
306
46k
The Pragmatic Product Professional
lauravandoore
37
7.3k
Into the Great Unknown - MozCon
thekraken
41
2.5k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
140
The Curse of the Amulet
leimatthew05
1
12k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
170
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
140
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
430
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
290
Design in an AI World
tapps
1
210
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
120
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
Transcript
SBJson 4: Don’t make me wait! Stig Brautaset ~ @stigbra
Who am I? Started SBJson in 2007. Compulsively tinkered with
it since.
Fun facts 7 years on • 1012 commits • 4
major releases • 30 contributors • 3247 “stars” • 688 “forks”
–Every non-trivial app, ever. “Download a list of records &
display them to the user.”
What’s more important to your users? • Time until they
see the last record? • Or until they see the first?
The trouble with pagination • Repeated connection overhead • Records
fall in the cracks between pages • Records appear on two consecutive pages
Download-then-parse Time to first record Time to last record
Chunked delivery Time to first record Time to last record
Multi-core chunked delivery Time to first record Time to last
record
Relative time to first record 0 1.25 2.5 3.75 5
1 record 2 records 3 records 4 records 5 records Chunked delivery Traditional
NSJSONSerialisation • Supports NSStream! • But can’t do chunked delivery.
• We can do better!
SBJson 3 • Chunked delivery since June 2011 :-) •
But it was confusing and cumbersome to use… :-/ • …requiring multiple delegates chained together :-(
SBJson 4 • Drops category & OO interfaces • Focus
on chunked delivery • Introduces a block-based interface • Built specifically for two primary use cases
Multi-root JSON [1,2,3] {“foo”:42} [true,false]
Multi-root JSON id parser = [SBJson4Parser multiRootParserWithBlock:block errorHandler:eh];
Multi-root JSON [parser parse:data("[]{")]; // calls block(@[]) [parser parse:data("}[]"]; //
next part of stream // calls block(@{}) // calls block(@[])
Multi-root JSON [parser parse:data("[]{")]; // calls block(@[]) [parser parse:data("}[]"]; //
next part of stream // calls block(@{}) // calls block(@[])
Compromise: “garbage after JSON” []**xx block(@[]) errorHandler(…)
–Johnny Appleseed “What if I am using a 3rd-party API
that just gives me a long list?”
Root array chunks [ [1,2,3], {“foo”:42}, [true,false] ]
Unwrap the root array! id parser = [SBJson4Parser unwrapRootArrayParserWithBlock:block errorHandler:eh];
Unwrap the root array! [parser parse:data("[[],{")]; // calls block(@[]) [parser
parse:data("},true]")]; // calls block(@{}) // calls block(@(YES))
Unwrap the root array! [parser parse:data("[[],{")]; // calls block(@[]) [parser
parse:data("},true]")]; // calls block(@{}) // calls block(@(YES))
Compromise: Corrupted / incomplete JSON [ {}, [], ***###$#”>P block(@{})
block(@[]) errorHandler(…)
Unwrapping is for root-level arrays only!
SBJson’s Blocks SBJson4ValueBlock block = ^(id obj, BOOL *stop) {
if (some_condition) { *stop = YES; } else { // do something with obj } };
SBJson4ParserStatus switch ([parser parse:data]) { case SBJson4ParserStopped: case SBJson4ParserComplete: NSLog(“Done!");
case SBJson4ParserWaitingForData: break; case SBJson4ParserError: NSLog(@"Ouch, I'm hurt!"); break; }
Use with custom NSURLSessionDataDelegate - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dt didReceiveData:(NSData
*)data { switch ([parser parse: data]) { // handle various returns here… } }
Two CocoaPods! To allow both version 3 and 4 in
the same application.
http://www.flickr.com/photos/dullhunk/202872717/