Giter Site home page Giter Site logo

zen's Issues

Swift学习: 从Objective-C到Swift中有误

struct SomeStructure {
    static var storedTypeProperty = "Some value."
    static var computedTypeProperty: Int {
        return 1
    }
    class var overrideableComputedTypeProperty: Int {
        return 107
    }
}

这里的SomeStructure是Struct,struct是不能继承的。而且struct只能用static,不能用class。

一处手误

Crash in Cocoa

Cocoa中会导致Carsh的地方:

crash。。。

iOS夯实:ARC时代的内存管理中的[self someMethod];

__weak SomeObjectClass *weakSelf = self;

SomeBlockType someBlock = ^{
SomeObjectClass *strongSelf = weakSelf;
if (strongSelf == nil) {
// The original self doesn't exist anymore.
// Ignore, notify or otherwise handle this case.
}
[self someMethod];
};
确定是[self someMethod];?

关于像素重绘问题

我一直有研究图形性能方面的东西,关于像素重绘方面,我一直有一个解决不了的问题,为了避免一个像素被过度重绘,我们最好是每个视图都加上背景颜色,特别是文本类的,但在iOS8下,UILabel绘制中文的方式跟iOS8以前的并不一样,即使给UILabel对象添加背景色,也会出现像素重绘问题,我解决的方案是,设置UILabel对像关联的layer的masksToBounds为YES,这样确定是可以解决像素重绘问题,但有些文本会莫名的出现多余的横线,是绘制文本的时候出现的,不知道作者对这块是否有了解。

非常感谢!

之前对Swift只停留在基本了解,一直在犹豫要不要转Swifter,现在看来,Swift这条船我还是上吧!
很感谢作者的这些Tip!能少走很多弯路!

图形性能离屏渲染

在 offscreen render 的那个小节里面,分析圆角的时候,offerScreen 是笔误吗?

对于 throttle 的使用场景存在疑问

文章最后给出

 let timer = SwiftTimer.repeaticTimer(interval: .seconds(1)) {
        SwiftTimer.throttle(interval: .seconds(1.5), identifier: "not pass") {
            print("should not pass")
        }
}

如果 throttle 的时间大于外层的时间,那么这个 print("should not pass") 永远不会执行,因为在执行 print 之前就会被外层更短的时间 cancel 掉了。

|——|——|
 1s 1s
·——x--·
  ·——x--·
   1.5s

那么如何做到文中所说的过滤呢?

关于 swift 中的 atomic,苹果官方,给出了一个替代/模拟 atomic 的方案

nonatomic,atomic 所有的Swift properties 都是nonatomic。但是我们在线程安全上已经有许多机制,例如NSLock,GCD相关API等。个人推测原因是苹果想把这一个本来就用的很少的特性去掉,线程安全方面交给平时我们用的更多的机制去处理。

苹果官方,给出了一个替代/模拟 atomic 的方案,可以参考下:

https://github.com/apple/swift-evolution/blob/master/proposals/0030-property-behavior-decls.md#synchronized-property-access

这是一个关于DispatchWallTime的使用问题?如果你能帮助我,真的很感谢

    let sourceWallTimer = DispatchSource.makeTimerSource(queue: DispatchQueue.global())
    let wallTimeInterval = DispatchTimeInterval.seconds(1)
    
    let walltime = DispatchWallTime.now() + wallTimeInterval
    print("time-now : \(DispatchWallTime.now())")
    print("walltime : \(walltime)")
    sourceWallTimer.scheduleRepeating(wallDeadline: walltime, interval: wallTimeInterval)
    sourceWallTimer.setEventHandler {
        NSLog("定时器运行:--walltime")
    }
    
    if #available(iOS 10.0, *) {
        sourceWallTimer.activate()
    } else {
        // Fallback on earlier versions
        sourceWallTimer.resume()
    }      

我运行的结果是这样的,我发现walltime
time-now : DispatchWallTime(rawValue: 16968580581812839616)
walltime : DispatchWallTime(rawValue: 16968580580812844616)
1分钟左右之后的再次运行
time-now : DispatchWallTime(rawValue: 16968580437033322616)
walltime : DispatchWallTime(rawValue: 16968580436033328616)
==》从这个参数上来看walltime可能是从现在到未来的最大值之间的一个 时间长度值
这个值看起来让我觉得并没有设么规律
可能由于模拟器的时间和现实的时间并不一致,大体的时间是不正确的。
但是这个walltime的使用,使得定时器并不能运行,如果使用DispatchTime的初始化时间是没有问题的。

iOS夯实:ARC时代的内存管理

在 viewDidLoad 中创建 timer 并用作为 strong 属性,代码如下:
NSTimer *time = [NSTimer timerWithTimeInterval:3.0 target:self selector:@selector(timeEnd:) userInfo:@"userinfo" repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:time forMode:NSDefaultRunLoopMode];
self.mytimer = time;
运行在 iOS9.2 模拟器上时,dealloc 方法是会调用的,不像你上面所说的强引用问题。
你可以再看看

网络相关

文章写的都不错,对新手很有帮助。能不能分享一些关于网络的知识。比如,哪些通信机制已经被实现了,哪些需要自己写。我猜想与网站服务器,数据库服务器通信的机制应该已经实现了。 这些无需开发者自己再写。 视频传输或其他的,我不是很清楚是否已经实现了。谢谢🙏

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.