iOS-App内部跳转到推送开关页面

今天碰到一个需求,是需要使用在app内部点击按钮,直接跳转到推送的开关页面。实际代码如下方所示

Read more   2018/10/9 posted in  iOS

Swift POP 应用 (一) UITableViewCell 的注册与获取

Read more   2018/9/17 posted in  iOS

Swift中的POP——面向协议编程

Don't start with a class. Start with a protocol

Read more   2018/9/14 posted in  iOS

RxCocoa中的 AOP 实现

Read more   2018/9/5 posted in  iOS

KVO代码测试以及探究

之前对于 KVO 的实现,都仅仅限于修改了对应属性的 set 方法的实现,使得在该方法使用前与使用后分别触发不同的方法。现在作者想仔细的看一下具体的细节。

Read more   2018/9/4 posted in  iOS

论 UITableView 的 dequeueReusableCell 方法

由一个项目中的问题想到的。

Read more   2018/8/23 posted in  iOS

重构Massive AppDelegate

本文是翻译自墙外的一片文章。文章通过分析iOS项目中 AppDelegate 中常负担的职能,并将其分为三类,通过引入不同的设计模式将代码进行抽离整合,最终达到单一职能、可重用、易测试的特点。
译者也在文章的影响下,对当前进行的项目进行了相应的兼容和实现,最终效果还是很不错的。

Read more   2018/8/21 posted in  iOS

AutoRelease Pool 总结

Read more   2018/7/26 posted in  iOS

对于首页的优化

当前页面中存在的问题

switch model.style {
case .news: 
    let cell = tableView.dequeue("newsCell") //config
    //...配置
    return cell
case .video:
     let cell = tableView.dequeue("videosCell") //config
    //...配置
    return cell
case .pic:
     let cell = tableView.dequeue("picsCell") //config
    //...配置
    return cell
case .beauty:
     let cell = tableView.dequeue("beautyCell") //config
    //...配置
    return cell
case .bigImage:
     let cell = tableView.dequeue("bigImageCell") //config
    //...配置
    return cell
default: ...
}

实际页面涉及到的cell种类不止这些,并且在未来的开发过程中会随着app特性的增加而增长,因为每次需要维护和更新时对整个大的代码块进行修改就编程一个非常杂乱的过程,稍有不慎还会影响整体的逻辑。那这里我们需要利用协议的特性进行设计。相关参考

实际项目中定义了一个协议,用来表示整个的数据类型

protocol ParseMessageType{
    associatetype: Original
    associatetype: ParseResult
}

Original->ParseResult的转换步骤通过一个 parser来完成, 叫做MessageParser

protocol MessageParser {
 
 associatetype: Message
 associatetype: Target: ParaseMessageType where Message == Target.Original
    func parse(messgae: Message)-> Target.ParsedResult
}

对于Target遵守 ParaseMessageType 的协议, 并且它的 original和message一致, 这就对parse方法的返回值进行了限定,编译过程中进行类型检查时会进行严格的类型匹配。

在具体MessageType实现的过程中

final class ParsedChatMessage: ParsedMessageType {
    let output: NSAttributedString
    let original: ChatMessage
    
    init(message: ChatMessage){
        original = messgae
        let parser = Parser()
        self.output = parser.parse(message: message)
    }
}

struct Parser: MessageParser {
    typealias Target = ParsedChatMessage
    func parse(message: ChatMeaasge)-> NSAttributeString {
     let reuslt = ...
     return .init(attributedString: result...)
    }
}


那么实际中的本地效果呢:

FeedModel IndexProtocol cellViewModel1 cellViewModel2cellViewModel3

在 feedModel,
在feedModel中实现fakeModel
FeedModel-> IndexProtocol
fakeModel-> IndexProtocol
TopicModel -> IndexProtocol

对应的不同的cell,

此外,需要进一步实践的

delegate改进

2018/7/25 posted in  iOS

ObjectMapper学习

ObjectMapper
最近在写Mirror的时候,一直在考虑如何自动实现JSON 与Object之间的解析与赋值问题,而不需要手动进行key值的配置。因此对于当前Swift中常用的几个框架比较好奇。因此我打算解读一下 ObjectMapper是如何实现的。。

Read more   2018/7/21 posted in  iOS