Skip to content

Instantly share code, notes, and snippets.

class ExampleShark {
var name:NSString!
var howSwim:NSString!
init(name:NSString!, howSwim:NSString!) {
self.name = name
self.howSwim = howSwim;
}
func swim() -> String {
import Foundation
class GrayShark {
var name:String
var howSwim:String
init(name:String, howSwim:String) {
self.name = name
self.howSwim = howSwim;
}
@akisute
akisute / GrayShark.swift
Last active May 13, 2016 17:05
I have learned a "Gray Magic" of the Swift.
import Foundation
class GrayShark {
var name:String
var howSwim:String
init(name:String, howSwim:String) {
self.name = name
self.howSwim = howSwim;
}
@akisute
akisute / NonObjCShark.swift
Last active August 29, 2015 14:02
Swim Swim Swim Lurk... to investigate how ! and ? works in normal swift class/objc attributed swift class
class NonObjCShark {
var name:NSString!
var howSwim:NSString!
init(name:NSString!, howSwim:NSString?) {
self.name = name
self.howSwim = howSwim;
}
func swim() -> String {
@akisute
akisute / Enumeration.java
Created June 6, 2014 09:51
Java enum iteration sample
public enum Suit {
Spades, Hearts, Diamonds, Clubs;
}
for (Suit suit : Suit.values()) {
System.out.println(suit.toString());
}
@akisute
akisute / EnumerationForEnum.swift
Created June 6, 2014 09:44
Enumeration for enum classes in Swift.
enum Rank:Int {
case Ace = 1
case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten
case Jack, Queen, King
// Here's an undocumented trick: How to enumerate enums using Generator!
// I wish I could use yield though ;(
class EnumGenerator:Generator {
var i = 1
func next() -> Rank? {
@akisute
akisute / example1.swift
Last active August 29, 2015 14:02
Several disappointing Swift code snippets...
class MyClass {
var someValue:Int
func someMethod() -> Int {
return 42
}
var callback:(Int) -> (Void) = {(value:Int) -> (Void) in
// Using self within a closure owned by self makes reference loop
self.someValue = self.someMethod() + value
}
@akisute
akisute / MyPlayground.swift
Last active August 29, 2015 14:02
Playing around with Swift
import Foundation
var l = [
"abesi",
"hidebu",
"tawaba",
]
var m = [
"abesi": 1,
Initialize engine version: 4.3.3f1 (c8ca9b6b9936)
GfxDevice: creating device client; threaded=1
OpenGL:
Version: OpenGL 2.1 [2.1 NVIDIA-8.24.9 310.40.25f01]
Renderer: NVIDIA GeForce GTX 680MX OpenGL Engine
Vendor: NVIDIA Corporation
VRAM: 2048 MB
Extensions: GL_ARB_color_buffer_float GL_ARB_depth_buffer_float GL_ARB_depth_clamp GL_ARB_depth_texture GL_ARB_draw_buffers GL_ARB_draw_elements_base_vertex GL_ARB_draw_instanced GL_ARB_fragment_program GL_ARB_fragment_program_shadow GL_ARB_fragment_shader GL_ARB_framebuffer_object GL_ARB_framebuffer_sRGB GL_ARB_half_float_pixel GL_ARB_half_float_vertex GL_ARB_imaging GL_ARB_instanced_arrays GL_ARB_multisample GL_ARB_multitexture GL_ARB_occlusion_query GL_ARB_pixel_buffer_object GL_ARB_point_parameters GL_ARB_point_sprite GL_ARB_provoking_vertex GL_ARB_seamless_cube_map GL_ARB_shader_objects GL_ARB_shader_texture_lod GL_ARB_shading_language_100 GL_ARB_shadow GL_ARB_sync GL_ARB_texture_border_clamp GL_ARB_texture_compression GL_ARB_texture_c
public int getCryptoTypeDumb() {
// With Plain Java
List<Network> networkList = new ArrayList(mNetworkSet);
Collections.sort(networkList, NetworkComparators.CRYPTOTYPE_WEAKEST_TO_STRONGEST);
return networkList.get(0).getCryptoType();
}
public int getCryptoType() {
// With Google Guava
return Ordering.from(NetworkComparators.CRYPTOTYPE_WEAKEST_TO_STRONGEST).min(mNetworkSet).getCryptoType();