PTT
Submit
Submit
選擇語言
正體中文
简体中文
PTT
MacDev
[問題] cs193p 程式問題
作者:
angelina877
(牛牛)
2015-11-11 22:12:03
https://www.youtube.com/watch?v=ZqKbN_C4Yvg
課程影片約55分處
#import "TextStatsColorAndOutlineViewContrller.h"
@interface TextStatsColorAndOutlineViewContrller()
@property (weak, nonatomic) IBOutlet UILabel *colorfulCharacterLabel;
@property (weak, nonatomic) IBOutlet UILabel *outlineCharacterLabel;
@end
@implementation TextStatsColorAndOutlineViewContrller
-(void)setTextToAnalyze:(NSAttributedString *)textToAnalyze
{
_textToAnalyze = textToAnalyze;
if (self.view.window) [self updateUi];//如果是nil就不出現在螢幕上
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self updateUi];
}
-(void) updateUi
{
self.colorfulCharacterLabel.text = [[self characterWithAttribute:NSForegroundColorAttributeName] length];
self.outlineCharacterLabel.text = [[self characterWithAttribute:NSForegroundColorAttributeName] length];
}
-(NSAttributedString *)characterWithAttribute:(NSString *)attributeName
{
NSMutableAttributedString *characters = [[NSMutableAttributedString alloc ] init ];
int index = 0;
while (index < [self.textToAnalyze length]) {
NSRange range;
id value = [self.textToAnalyze attribute:attributeName atIndex:index effectiveRange: &range];
if (value) {
[characters appendAttributedString:[self.textToAnalyze attributedSubstringFromRange:range]];
index = range.location + range.length;
}
else{
index++;
}
}
return characters;
}
警告訊息:
在index = range.location + range.length;這一行
implicit conversion loses integer precision 'unsigned long' to 'int'
我的Code都照打
怎麼還是會有warninghttps://www.youtube.com/watch?v=ZqKbN_C4Yvg
課程影片約55分處
#import "TextStatsColorAndOutlineViewContrller.h"
@interface TextStatsColorAndOutlineViewContrller()
@property (weak, nonatomic) IBOutlet UILabel *colorfulCharacterLabel;
@property (weak, nonatomic) IBOutlet UILabel *outlineCharacterLabel;
@end
@implementation TextStatsColorAndOutlineViewContrller
-(void)setTextToAnalyze:(NSAttributedString *)textToAnalyze
{
_textToAnalyze = textToAnalyze;
if (self.view.window) [self updateUi];//如果是nil就不出現在螢幕上
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self updateUi];
}
-(void) updateUi
{
self.colorfulCharacterLabel.text = [[self characterWithAttribute:NSForegroundColorAttributeName] length];
self.outlineCharacterLabel.text = [[self characterWithAttribute:NSForegroundColorAttributeName] length];
}
-(NSAttributedString *)characterWithAttribute:(NSString *)attributeName
{
NSMutableAttributedString *characters = [[NSMutableAttributedString alloc ] init ];
int index = 0;
while (index < [self.textToAnalyze length]) {
NSRange range;
id value = [self.textToAnalyze attribute:attributeName atIndex:index effectiveRange: &range];
if (value) {
[characters appendAttributedString:[self.textToAnalyze attributedSubstringFromRange:range]];
index = range.location + range.length;
}
else{
index++;
}
}
return characters;
}
警告訊息:
在index = range.location + range.length;這一行
implicit conversion loses integer precision 'unsigned long' to 'int'
我的Code都照打
怎麼還是會有warning....
不解QQ
作者:
Esvent
(Esvent)
2015-11-11 23:12:00
因為編譯的環境不同 arm64的NSInteger是long 之前是int啊說錯 之前也是long 不過arm64的long是8byte 其他4byte詳細可以參考Apple的document
https://goo.gl/t4Oiwe
32位元 long(4byte) <=> int(4byte) 長度相同 可直接轉換64位元 long(8byte) <=> int(4byte) 長度不同 會掉資訊
繼續閱讀
[閒聊] 寫了一個簡單的網路電視 App
shinrenpan
[問題] 有人也上架圖片上傳失敗嗎
converse
[問題] IOS9.1推播問題
dp814082
[問題] wrong window size
dp814082
[問題] add custom activity type
essay1029
[問題] Xcode7/Swift建立Objective-C bridge
strife00
[問題] 有關把圖片存到相簿的問題
iamsewei
[請益] 請問在發送電文與等待時做的處理?
tga123
[問題] 建置版本處理中 已經過了三天
lineseven
[問題] self用法
angelina877
Links
booklink
Contact Us: admin [ a t ] ucptt.com