iOS 开发实用技术导航
NSHipster 中文版
› http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
› http://www.cocos2d-iphone.org/
CocoaPods
› http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
› http://code.google.com/mobile/analytics/
WWDC
› https://developer.apple.com/wwdc/
Design Guides and Resources
› https://developer.apple.com/design/
Transcripts of WWDC sessions
› http://asciiwwdc.com
Cocoa with Love
› http://cocoawithlove.com/
Cocoa Dev Central
› http://cocoadevcentral.com/
NSHipster
› http://nshipster.com/
Style Guides
› Google Objective-C Style Guide
› NYTimes Objective-C Style Guide
Useful Tools and Services
› Charles Web Debugging Proxy
› Smore
Dystopia
V2EX  ›  iDev

大家都是怎么做「安全锁」的,比如服务器返回 json 每个都要判断是不是为 nil,数据多了好麻烦,有没有更好的办法

  •  
  •   Dystopia · Aug 23, 2016 · 3529 views
    This topic created in 3733 days ago, the information mentioned may be changed or developed.
    如题,大家都是怎么做「安全锁」的,比如服务器返回 json 每个都要判断是不是为 nil ,数据多了好麻烦,有没有更好的办法。

    比如,一个 post 请求返回很多 string 数据,有过有数据为空 可能引起 App 崩溃,但当数据很多的时候 if else 判断真的很麻烦,有没有更有效的方法呢?
    6 replies  •  2016-08-31 14:16:20 +08:00
    guomiaoyou7784
    guomiaoyou7784
    Aug 23, 2016
    1
    可以扩展出 dictionary safe 方法。从 json 取用的时候判断对应类型是否需要提供默认值。数据为空引起 crash 是另一码事,代码不够健壮。
    tinyproxy
    tinyproxy
    Aug 24, 2016 via iPhone
    2
    (°_°)…
    为什么空字符串会导致你的 APP 崩溃。。。
    Rubbly
    Rubbly
    Aug 24, 2016
    3
    一个 post 请求返回很多 string 数据,感觉这个表达就有问题。
    顺吧请利用好 status code ,而且对于 NULL 也有自己的处理逻辑,与崩溃无关。
    hanxiV2EX
    hanxiV2EX
    Aug 24, 2016 via iPhone
    4
    用 JSPNRPC 。从底层过滤掉错误数据。
    04BxPLXu2M6UKH6Z
    04BxPLXu2M6UKH6Z
    Aug 30, 2016 via iPhone
    5
    发消息给 nil 不会 crash 的啊 插入 nil 才会
    ma125125t
    ma125125t
    Aug 31, 2016
    6
    我一般直接判断字符串的 length
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1838 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 15:51 · PVG 23:51 · LAX 07:51 · JFK 10:51
    ♥ Do have faith in what you're doing.