2015年7月9日 星期四

Xcode的Debug小技巧

加入之後,可以看到解釋清楚的crash原因。

ASTableView的update方式

self._tableView.beginUpdates()
                self._tableView.deleteSections(indexSet, withRowAnimation: UITableViewRowAnimation.Fade)
                self._tableView.reloadSections(indexSet, withRowAnimation: UITableViewRowAnimation.None)
                self._tableView.endUpdates()

a social app needs to have precautions mechanism.

14.3 Details Your app enables the display of user-generated content but does not have the required precautions in place. Next Steps It
July 9, 2015 at 8:43 AM
From Apple
14.3 - Apps that display user generated content must include a method for filtering objectionable material, a mechanism for users to flag offensive content, and the ability to block abusive users from the service
14.3 Details

Your app enables the display of user-generated content but does not have the required precautions in place.

Next Steps

It is necessary that you put all of the following precautions in place:

- Require that users agree to terms (EULA) and these terms must make it clear that there is no tolerance for objectionable content
- Use moderators to flag and remove inappropriate content and offensive users
- Users need a mechanism to flag objectionable content and report users generating this content
- Developer must act on objectionable content reports within 24 hours by removing the content and ejecting the user who provided the offending content
- Developer needs a method for ejecting users who violate the terms of the EULA

Reply Use the field below to ask questions or provide additional information to the App Review team. Learn More Submit an appeal to the App Review Board.This field is required. 4000
Attach File
Send

Therefore, we have three task need to be finished:1. Term agree, 2. block user, 3. report abuse content

2015年7月6日 星期一

在yourUIView.swift中與xib做聯結

required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.view = NSBundle.mainBundle().loadNibNamed("ChatPanelView", owner: self, options: nil)[0] as! UIView
        self.view.frame = CGRectMake(0, 0, DefaultConfig.SCREEN_WIDTH, 87)
        self.addSubview(self.view)
        self.setNeedsUpdateConstraints()
        self.inputTextField.text = Language.get("TYPE_A_MESSAGE", comment: "Type a message")
        self.inputTextField.scrollEnabled = false

    }

2015年6月24日 星期三

更新ASTextNode文字

//重新給文字
self.textNode.attributedString = mutableAttributedString.copy() as! NSAttributedString
//取消上次的計算,然後重算大小
self.textNode.invalidateCalculatedSize()
self.textNode.measure(CGSizeMake(DefaultConfig.SCREEN_WIDTH, CGFloat(FLT_MAX)))

self.textNode.setNeedsLayout()

2015年6月23日 星期二

swift Range <---> objc NSRange 互換

extension String {
    func rangeFromNSRange(nsRange : NSRange) -> Range<String.Index>? {
        if let from = String.Index(self.utf16.startIndex + nsRange.location, within: self),
            let to = String.Index(self.utf16.startIndex + nsRange.location + nsRange.length, within: self) {
                return from ..< to
        }
        return nil
    }

    func NSRangeFromRange(range : Range<String.Index>) -> NSRange {
        let utf16view = self.utf16
        let from = String.UTF16View.Index(range.startIndex, within: utf16view)
        let to = String.UTF16View.Index(range.endIndex, within: utf16view)
        return NSMakeRange(from - utf16view.startIndex, to - from)
    }
}

2015年6月22日 星期一

利用closure的特性來解決callback時間差的問題

如果你要更新你的cell,但你的cell是reuse的,那第一時間用url去抓的image,可能在你滑動的過程中,callback回來時cell已經改放其他的data了。
原本我是想在download image的callback中加入一個key(在下例中是userName)來比對是否跟目前cell的userName相同,但這麼一來,就會破壞了download image API的內聚性。

在swift中比較好的做法是利用closure的特性來解決callback時間差的問題,
closure會把參數copy一份出來,而用self.去接的則是將外部的參數call by reference,
於是我們比較userName == self?.userName 就會等於是比較目前的跟之前的變數差異。
這樣就解決了。

    func setData(displayName: String, userName: String) {
        self.userName = userName
        
        WebImageFetcher.sharedInstance.getImageWithDisplayId(userName, size: ImageSizeEnum.SIZE_96X) {
            [weak self] (data) in
            if let img = data {
                if userName == self?.userName {
                    self?.iconView.image = data
                }
            }
        }
    }