技术控

    今日:114| 主题:49431
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] The Realm SDK Enables Clean and Easy Separation of Concerns

[复制链接]
被妳弄來沒了 发表于 2016-11-29 18:04:11
41 0

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

The Realm SDK Enables Clean and Easy Separation of Concerns-1 (highlights,recommend,benefits,offering,database)

   This is the fourth post in a multi-part series on the Realm Mobile Database; it highlights some of the multi-platform aspects of the the database and the high reusability of the code across devices. If you missed the first post on our custom engine , the second post on the benefits of some of the Realm API types , and the third post on sharing code across platforms , we recommend taking few minutes to read through.
  A third-party SDK might empower you or get in your way. For example, a highly functional but monolithic library will allow you to quickly implement some basic app logic, but create more trouble than value down the road.
   The Realm Mobile Database aims to not only allow you to persist your data, but to help you implement good practices. It does that by offering you a flexible SDK in a number of programming languages (Swift, Java, JavaScript, C#, and more) - it allows you to fine-tune your data objects and be in control all the way up to the higher-level APIs like reacting to changes and talking to your server.
  Any SDK, third-party library, or service you’d like to base your own product on should exhibit the same qualities you aim to have in your own product.
  Separation of Concerns

   If you’ve read the previous posts in this series, you remember that we’ve prepared a little companion project to provide examples for the features highlighted in each article. You can always clone (or download) the project from its GitHub repository and peak inside.
  Let’s take a quick look at how the Realm Swift SDK helps separate concerns in the companion project. We didn’t stick to a certain architecture since you might like a different one; this way you can read through the code and apply what you like best in your own project.
  The project consist of a single Xcode workspace, which features one target for each of Apple’s four platforms: iOS, macOS, tvOS, and watchOS:

The Realm SDK Enables Clean and Easy Separation of Concerns-2 (highlights,recommend,benefits,offering,database)

   Since the Realm Swift SDK supports all four platforms, the project shares the data layer code between all of them. In the previous post we had a look at a data entity called Favorite and figured that it only depends on Foundation and RealmSwift frameworks:
  [code]import Foundation
import RealmSwift

class Favorite: Object {
    dynamic var symbol = ":sparkling_heart:"
    var symbolIndex: Int? {
        return Favorite.symbols.index(of: symbol)
    }
    static let symbols = [":sparkling_heart:", ":rocket:", "��"]
    static let noSymbolIndex = -1
}[/code]   The data entity class can be, therefore, re-used as-is between platforms - it only makes use of common Foundation types and Realm itself.
  But let’s move beyond the data entity classes.
  In essence, all of the different apps that the project builds are list-based applications. They might look a bit different across platforms but the basic structure is:
  
       
  • a default screen showing a list of repositories, with the ability to filter them (no filtering in the watch app)   
  • a single repository detail screen, with the ability (where available) to mark the selected repository as favorite  
   The default screen presents a list of items - the iOS project uses a UITableView , the macOS project an NSTableView , tvOS a UICollectionView , etc. Here’s how the storyboard looks for iOS:
12下一页
友荐云推荐




上一篇:Mirai Botnet Knocks Nearly a Million Routers Offline
下一篇:算法专家的匠心之路:用户行为路径分析的产品化实践
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表