class

iOS 底层原理 - isa原理

折月煮酒 提交于 2020-02-10 02:29:56
isa初始化 isa的结构 union isa_t { isa_t() { } isa_t(uintptr_t value) : bits(value) { } Class cls; uintptr_t bits; #if defined(ISA_BITFIELD) struct { ISA_BITFIELD; // defined in isa.h }; #endif }; 从而可以看出isa是一个联合体,一种数据类型,所占用8个字节。它的特性:内存共用,或者说带有互斥特性,意思就是赋值了cls,就不对其他成员赋值了。其中ISA_BITFIELD是一个宏定义,是一个位域,它定义的结构如下 #if SUPPORT_PACKED_ISA // extra_rc must be the MSB-most field (so it matches carry/overflow flags) // nonpointer must be the LSB (fixme or get rid of it) // shiftcls must occupy the same bits that a real class pointer would // bits + RC_ONE is equivalent to extra_rc + 1 // RC_HALF is the high bit of

【ES6】Class

牧云@^-^@ 提交于 2020-02-10 00:59:22
以前类我们通过构造函数 function Point(x, y) { this.x = x; this.y = y; } Point.prototype.toString = function () { return '(' + this.x + ', ' + this.y + ')'; }; var p = new Point(1, 2); ES6可以通过class,完全可以看做构造函数的另一种写法 class Point { constructor(x, y) { this.x = x; this.y = y; } toString() { return '(' + this.x + ', ' + this.y + ')'; } } typeof Point // "function" Point === Point.prototype.constructor // truelet point = new Point(2,3) 构造函数的 prototype 属性,在 ES6 的“类”上面继续存在。事实上,类的所有方法都定义在类的 prototype 属性上面。 class Point { constructor() { // ... } toString() { // ... } toValue() { // ... } } // 等同于 Point.prototype =

设计模式七大原则之合成复用原则

谁说我不能喝 提交于 2020-02-09 03:34:47
设计模式七大原则之合成复用原则(Composite Reuse Principle) 1.合成复用原则介绍 原则是尽量使用合成或者聚合的方式,而不是使用继承 2.案例分析 场景: 有两个类A和B,B要使用A中的方法有哪几种方法 方法一 (使用继承,不符合合成复用): 类图 代码实现: package com . ldx . compositereuse ; public class CR1 { public static void main ( String [ ] args ) { B b = new B ( ) ; b . function1 ( ) ; } } class A { public void function1 ( ) { System . out . println ( "B使用继承去调用function1" ) ; } } class B extends A { } 运行结果: 方法二 (使用依赖,符合合成复用) 类图: 代码实现: package com . ldx . compositereuse ; public class CR2 { public static void main ( String [ ] args ) { B2 b = new B2 ( ) ; b . function ( new A2 ( ) ) ; } } class A2 {

Python入门到精通三天速成第二讲——类与继承

吃可爱长大的小学妹 提交于 2020-02-09 03:18:56
子类扩展了超类(父类)的定义。要指定超类,可在 class 语句中的类名后加上超类名,并将其用圆括号括起。 class Filter: def init(self): self.blocked = [] def filter(self, sequence): return [x for x in sequence if x not in self.blocked] class SPAMFilter(Filter): # SPAMFilter是Filter的子类 def init(self): # 重写超类Filter的方法init self.blocked = ['SPAM'] Filter 是一个过滤序列的通用类。实际上,它不会过滤掉任何东西。 >>> f = Filter() >>> f.init() >>> f.filter([1, 2, 3]) [1, 2, 3] Filter 类的用途在于可用作其他类(如将 'SPAM' 从序列中过滤掉的 SPAMFilter 类)的基类(超类)。 >>> s = SPAMFilter() >>> s.init() >>> s.filter(['SPAM', 'SPAM', 'SPAM', 'SPAM', 'eggs', 'bacon', 'SPAM']) ['eggs', 'bacon'] 请注意 SPAMFilter

js对象声明方式

牧云@^-^@ 提交于 2020-02-08 22:30:52
在JS中,创建对象(Create Object)并不完全是我们时常说的创建类对象,JS中的对象强调的是一种复合类型,JS中创建对象及对对象的访问是极其灵活的。 JS对象是一种复合类型,它允许你通过变量名存储和访问,换一种思路,对象是一个无序的属性集合,集合中的每一项都由名称和值组成(听起来是不是很像我们常听说的HASH表、字典、健/值对?),而其中的值类型可能是内置类型(如number,string),也可能是对象。 一、由一对大括号括起来 var emptyObj = {}; var myObj = { ' id ' : 1 , // 属性名用引号括起来,属性间由逗号隔开 ' name ' : ' myName ' }; // var m = new myObj(); //不支持   不知你注意到对象都是用 var 声明的没有,像上面的代码,就只是简单的声明一个对象,它只有一份拷贝,你不能像实例化类对象一样对它采用new操作,像上面代码的注释部分。这样就极大的限制了对象的重用,除非你建立的对象只需要一份拷贝,否则考虑用其他方法建立对象。   下面一起看看如何访问对象的属性和方法。 var myObj = { ' id ' : 1 , ' fun ' : function () { document.writeln( this .id + ' - ' + this .name);

Android app force closes - setOnClickListener [simple app] [beginner]

余生长醉 提交于 2020-02-08 09:59:53
问题 Program functions as normal on start up. As soon as button is clicked, app force closes and the log cat (at bottom) is shown. XML File - layout is fully functional <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal

Multi threading classes not working correctly

坚强是说给别人听的谎言 提交于 2020-02-08 07:37:06
问题 I'm trying to make a program that when the user holds down the left or right arrow key along with the space bar it shoots some red picture boxes that move upwards until the get removed, when I just create one it works fine but when I create two or more the first picture box stops moving and the second one starts moving and if there were three picture boxes then the first and second would stop and the third would start, once the third has finished then the second starts again and then the

vue.js (v-bind、on)绑定class style

假如想象 提交于 2020-02-08 05:40:57
vue指令 1.v-bind绑定属性 简写“:” 2.绑定多个class用数组 class [] {} style {} [] v-on:xxx (v-on <==> @) Document <button @click="handleClick">点击</button> <h4 :class="h4ClassArr[h4Index]">{{ name }}</h4> 来源: CSDN 作者: 城南没有城北 链接: https://blog.csdn.net/weixin_42380289/article/details/104216043

Setting variables in a different class in Cocoa

痞子三分冷 提交于 2020-02-08 04:17:52
问题 I'm trying to learn how to set variables for different classes using one main data class. Here's a diagram of of what I would like to do and the code from my project: ClassA #import <Foundation/Foundation.h> @interface ClassA : NSObject { NSString *stringA; NSString *stringB; } @property (nonatomic, copy) NSString *stringA; @property (nonatomic, copy) NSString *stringB; @property (weak) IBOutlet NSTextField *textA; @property (weak) IBOutlet NSTextField *textB; - (IBAction)displayStrings:(id

Setting variables in a different class in Cocoa

一笑奈何 提交于 2020-02-08 04:17:47
问题 I'm trying to learn how to set variables for different classes using one main data class. Here's a diagram of of what I would like to do and the code from my project: ClassA #import <Foundation/Foundation.h> @interface ClassA : NSObject { NSString *stringA; NSString *stringB; } @property (nonatomic, copy) NSString *stringA; @property (nonatomic, copy) NSString *stringB; @property (weak) IBOutlet NSTextField *textA; @property (weak) IBOutlet NSTextField *textB; - (IBAction)displayStrings:(id